-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : category infra layer 조회 쿼리 QueryDSL 개발, 기존 Repository 이름 변경 (#53)
- Loading branch information
1 parent
dccc25c
commit 93594ed
Showing
10 changed files
with
352 additions
and
29 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...other/src/main/java/com/neo/needeachother/category/domain/dto/CategoryDetailViewData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.neo.needeachother.category.domain.dto; | ||
|
||
import com.neo.needeachother.category.domain.ContentType; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@ToString(callSuper = true) | ||
public class CategoryDetailViewData { | ||
private final String categoryId; | ||
private final String categoryTitle; | ||
private final String categoryType; | ||
private final boolean isHostWriteOnly; | ||
private final boolean isCommentWriteAble; | ||
private final boolean isUsingRateFilter; | ||
private final int voteFilterRate; | ||
private final long postInCategoryCount; | ||
|
||
public CategoryDetailViewData(String categoryId, String categoryTitle, String categoryType, | ||
boolean isHostWriteOnly, boolean isCommentWriteAble, | ||
boolean isUsingRateFilter, | ||
int voteFilterRate, long postInCategoryCount) { | ||
this.categoryId = categoryId; | ||
this.categoryTitle = categoryTitle; | ||
this.categoryType = ContentType.convertToContentType(categoryType).name(); | ||
this.isHostWriteOnly = isHostWriteOnly; | ||
this.isCommentWriteAble = isCommentWriteAble; | ||
this.isUsingRateFilter = isUsingRateFilter; | ||
this.voteFilterRate = voteFilterRate; | ||
this.postInCategoryCount = postInCategoryCount; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...hother/src/main/java/com/neo/needeachother/category/domain/dto/CategoryDetailViewDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.neo.needeachother.category.domain.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@ToString | ||
@AllArgsConstructor | ||
public class CategoryDetailViewDto { | ||
private String starPageId; | ||
private List<CategoryDetailViewData> viewData; | ||
} |
24 changes: 24 additions & 0 deletions
24
needeachother/src/main/java/com/neo/needeachother/category/domain/dto/CategoryViewData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.neo.needeachother.category.domain.dto; | ||
|
||
import com.neo.needeachother.category.domain.ContentType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Setter | ||
@ToString(callSuper = true) | ||
public class CategoryViewData { | ||
private String categoryId; | ||
private String categoryTitle; | ||
private String categoryType; | ||
private long postCountInCategory; | ||
|
||
public CategoryViewData(String categoryId, String categoryTitle, String categoryType, long postCountInCategory){ | ||
this.categoryId = categoryId; | ||
this.categoryTitle = categoryTitle; | ||
this.categoryType = ContentType.convertToContentType(categoryType).name(); | ||
this.postCountInCategory = postCountInCategory; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
needeachother/src/main/java/com/neo/needeachother/category/domain/dto/CategoryViewDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.neo.needeachother.category.domain.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
public class CategoryViewDto { | ||
private String starPageId; | ||
private List<CategoryViewData> viewData; | ||
} |
9 changes: 0 additions & 9 deletions
9
.../main/java/com/neo/needeachother/category/domain/repository/CategoryCustomRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../main/java/com/neo/needeachother/category/domain/repository/CategoryRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.neo.needeachother.category.domain.repository; | ||
|
||
import com.neo.needeachother.category.domain.CategoryId; | ||
import com.neo.needeachother.category.domain.ContentType; | ||
import com.neo.needeachother.category.domain.dto.CategoryDetailViewDto; | ||
import com.neo.needeachother.category.domain.dto.CategoryViewDto; | ||
import com.neo.needeachother.starpage.domain.StarPageId; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CategoryRepositoryCustom { | ||
Optional<CategoryViewDto> searchCategoryViewByStarPageId(StarPageId starPageId); | ||
Optional<CategoryDetailViewDto> searchCategoryDetailViewByStarPageId(StarPageId starPageId); | ||
} |
16 changes: 0 additions & 16 deletions
16
...ther/src/main/java/com/neo/needeachother/category/infra/CategoryCustomRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
needeachother/src/main/java/com/neo/needeachother/category/infra/CategoryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.neo.needeachother.category.infra; | ||
|
||
import com.neo.needeachother.category.domain.CategoryStatus; | ||
import com.neo.needeachother.category.domain.dto.CategoryDetailViewData; | ||
import com.neo.needeachother.category.domain.dto.CategoryDetailViewDto; | ||
import com.neo.needeachother.category.domain.dto.CategoryViewData; | ||
import com.neo.needeachother.category.domain.dto.CategoryViewDto; | ||
import com.neo.needeachother.category.domain.repository.CategoryRepositoryCustom; | ||
import com.neo.needeachother.common.exception.NEOUnexpectedException; | ||
import com.neo.needeachother.starpage.domain.StarPageId; | ||
import com.querydsl.core.group.GroupBy; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.neo.needeachother.category.domain.QCategory.category; | ||
import static com.neo.needeachother.post.domain.QStarPagePost.starPagePost; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CategoryRepositoryImpl implements CategoryRepositoryCustom { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Optional<CategoryViewDto> searchCategoryViewByStarPageId(StarPageId starPageId) { | ||
List<CategoryViewDto> queryResult = jpaQueryFactory | ||
.select( | ||
Expressions.asString(starPageId.getValue()).as("starPageId"), | ||
category.categoryId.value, | ||
category.categoryInformation.categoryTitle, | ||
category.contentType.stringValue(), | ||
starPagePost.count() | ||
) | ||
.from(category) | ||
.innerJoin(starPagePost).on(starPagePost.categoryId.eq(category.categoryId)) | ||
.groupBy(category.categoryId) | ||
.where( | ||
categoryEqStarPageId(starPageId), | ||
neCategoryStatusDeleted() | ||
) | ||
.transform(GroupBy.groupBy(category.starPageId) | ||
.list(Projections.constructor(CategoryViewDto.class, | ||
Expressions.asString(starPageId.getValue()).as("starPageId"), | ||
GroupBy.list( | ||
Projections.constructor(CategoryViewData.class, | ||
category.categoryId.value, | ||
category.categoryInformation.categoryTitle, | ||
category.contentType.stringValue(), | ||
starPagePost.count()) | ||
) | ||
))); | ||
|
||
if (queryResult.size() > 1) { | ||
throw new NEOUnexpectedException("정상적이지 않은 결과, searchCategoryViewByStarPageId"); | ||
} | ||
|
||
return Optional.ofNullable(queryResult.isEmpty() ? null : queryResult.get(0)); | ||
} | ||
|
||
@Override | ||
public Optional<CategoryDetailViewDto> searchCategoryDetailViewByStarPageId(StarPageId starPageId) { | ||
List<CategoryDetailViewDto> queryResult = jpaQueryFactory | ||
.select(category, starPagePost.count()) | ||
.from(category) | ||
.innerJoin(starPagePost).on(starPagePost.categoryId.eq(category.categoryId)) | ||
.groupBy(category.categoryId) | ||
.where( | ||
categoryEqStarPageId(starPageId), | ||
neCategoryStatusDeleted() | ||
).transform(GroupBy.groupBy(category.starPageId) | ||
.list( | ||
Projections.constructor(CategoryDetailViewDto.class, | ||
Expressions.asString(starPageId.getValue()).as("starPageId"), | ||
GroupBy.list(Projections.constructor(CategoryDetailViewData.class, | ||
category.categoryId.value, | ||
category.categoryInformation.categoryTitle, | ||
category.contentType.stringValue(), | ||
category.restriction.onlyHostWriteContent, | ||
category.restriction.isWriteAbleComment, | ||
category.restriction.useCommentRatingFilter, | ||
category.restriction.filteringRate, | ||
starPagePost.count() | ||
)) | ||
) | ||
)); | ||
|
||
if (queryResult.size() > 1) { | ||
throw new NEOUnexpectedException("정상적이지 않은 결과, searchCategoryDetailViewByStarPageId"); | ||
} | ||
|
||
return Optional.ofNullable(queryResult.isEmpty() ? null : queryResult.get(0)); | ||
} | ||
|
||
private BooleanExpression categoryEqStarPageId(StarPageId starPageId) { | ||
return category.starPageId.eq(starPageId); | ||
} | ||
|
||
private BooleanExpression neCategoryStatusDeleted() { | ||
return category.categoryStatus.ne(CategoryStatus.DELETED); | ||
} | ||
} |
Oops, something went wrong.