Skip to content

Commit

Permalink
Merge pull request #189 from TripInfoWeb/refactor/gathering_information
Browse files Browse the repository at this point in the history
Refactor/gathering information
  • Loading branch information
hyeonjaez authored Sep 21, 2024
2 parents 1c71e26 + 1976f97 commit 9177c17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<GatheringBriefResponse> getGatheringRecommend(Long gatheringId, Long
isGatheringBookmark(userId),
likeCount,
gathering.gatheringCategory.name,
gathering.user.name,
gathering.user.nickname,
gathering.scheduleStartDate,
gathering.scheduleEndDate,
gathering.deadline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class InformationBriefResponse {
private String title;
private String zoneCategoryParentName;
private String zoneCategoryChildName;
private String categoryName;
private Integer viewCount;
private Boolean isBookMark;
private String thumbNailImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,15 @@ public Page<InformationBriefResponse> getInformationPageFilterAndOrder(Pageable
NumberExpression<Integer> countGreatInformation = countGreatInformationByInformationById();

long total = from(information)
.join(zoneCategoryChild).on(zoneCategoryChild.id.eq(information.zoneCategory.id))
.leftJoin(zoneCategoryParent).on(zoneCategoryParent.id.eq(zoneCategoryChild.parentZoneCategory.id))
.leftJoin(bookMarkInformation)
.on(bookMarkInformation.information.id.eq(information.id).and(bookMarkInformation.user.id.eq(userId)))
.leftJoin(image)
.on(image.information.id.eq(information.id).and(image.imageStatus.eq(ImageStatus.THUMBNAIL)))
.join(category).on(category.id.eq(information.category.id).and(categoryCondition))
.where(whereClause)
.select(information.count()).fetchCount();
.select(information.id).fetchCount();

List<InformationBriefResponse> list = from(information)
.join(zoneCategoryChild).on(zoneCategoryChild.id.eq(information.zoneCategory.id))
.leftJoin(zoneCategoryParent).on(zoneCategoryParent.id.eq(zoneCategoryChild.parentZoneCategory.id))
.leftJoin(bookMarkInformation)
.on(bookMarkInformation.information.id.eq(information.id).and(bookMarkInformation.user.id.eq(userId)))
.leftJoin(image)
.on(image.information.id.eq(information.id).and(image.imageStatus.eq(ImageStatus.THUMBNAIL)))
.join(category).on(category.id.eq(information.category.id).and(categoryCondition))
.leftJoin(greatInformation).on(greatInformation.information.id.eq(information.id))
.where(whereClause)
.groupBy(information.id, zoneCategoryChild.id, zoneCategoryParent.id, image.id)
.orderBy(orderSpecifier)
Expand All @@ -104,8 +94,9 @@ public Page<InformationBriefResponse> getInformationPageFilterAndOrder(Pageable
information.title,
zoneCategoryParent.name,
zoneCategoryChild.name,
information.category.name,
information.viewCount,
bookMarkInformation.user.id.isNotNull(),
isInformationBookmark(userId),
image.address,
countGreatInformation,
isUserGreatInformation(userId)
Expand All @@ -122,11 +113,8 @@ public List<InformationMainResponse> getInformationLikeCountFromCreatedIn3(Long
return from(information)
.leftJoin(zoneCategoryChild).on(zoneCategoryChild.id.eq(information.zoneCategory.id))
.leftJoin(zoneCategoryParent).on(zoneCategoryParent.id.eq(zoneCategoryChild.parentZoneCategory.id))
.leftJoin(bookMarkInformation)
.on(bookMarkInformation.information.id.eq(information.id).and(bookMarkInformation.user.id.eq(userId)))
.leftJoin(image)
.on(image.information.id.eq(information.id).and(image.imageStatus.eq(ImageStatus.THUMBNAIL)))
.leftJoin(greatInformation).on(greatInformation.information.id.eq(information.id))
.leftJoin(category).on(category.id.eq(information.category.id))
.where(information.createdDate.after(LocalDateTime.now().minusMonths(3)))
.groupBy(information.id, information.title, zoneCategoryParent.name, zoneCategoryChild.name,
Expand All @@ -140,7 +128,7 @@ public List<InformationMainResponse> getInformationLikeCountFromCreatedIn3(Long
zoneCategoryChild.name,
category.parentCategory.name,
information.viewCount,
bookMarkInformation.user.id.isNotNull(),
isInformationBookmark(userId),
image.address,
countGreatInformationByInformationById(),
isUserGreatInformation(userId)
Expand All @@ -154,11 +142,8 @@ public List<InformationBriefResponse> getInformationRecommend(Long informationId
return from(information)
.join(zoneCategoryChild).on(zoneCategoryChild.id.eq(information.zoneCategory.id))
.leftJoin(zoneCategoryParent).on(zoneCategoryParent.id.eq(zoneCategoryChild.parentZoneCategory.id))
.leftJoin(bookMarkInformation)
.on(bookMarkInformation.information.id.eq(information.id).and(bookMarkInformation.user.id.eq(userId)))
.leftJoin(image).on(image.information.id.eq(information.id)
.and(image.imageStatus.eq(ImageStatus.THUMBNAIL)))
.leftJoin(greatInformation).on(greatInformation.information.id.eq(information.id))
.where(information.category.id.eq(childCategoryId).and(information.id.ne(informationId)))
.groupBy(information.id, zoneCategoryChild.id, zoneCategoryParent.id, image.id)
.orderBy(information.createdDate.desc())
Expand All @@ -168,8 +153,9 @@ public List<InformationBriefResponse> getInformationRecommend(Long informationId
information.title,
zoneCategoryParent.name,
zoneCategoryChild.name,
information.category.name,
information.viewCount,
bookMarkInformation.user.id.isNotNull(),
isInformationBookmark(userId),
image.address,
countGreatInformationByInformationById(),
isUserGreatInformation(userId)
Expand Down Expand Up @@ -233,6 +219,7 @@ public Page<InformationBriefResponse> getInformationPageByTag(Pageable pageable,
information.title,
zoneCategoryParent.name,
zoneCategoryChild.name,
information.category.name,
information.viewCount,
bookMarkInformation.user.id.isNotNull(),
image.address,
Expand Down Expand Up @@ -278,7 +265,9 @@ private NumberExpression<Integer> countGreatInformationByInformationById() {
.from(greatInformationSub)
.where(greatInformationSub.information.id.eq(information.id));

return Expressions.numberTemplate(Long.class, "{0}", likeCountSubQuery).coalesce(0L).intValue();
return Expressions.numberTemplate(Long.class, "{0}", likeCountSubQuery)
.coalesce(0L)
.intValue();
}

private BooleanExpression isUserGreatInformation(Long userId) {
Expand All @@ -292,5 +281,16 @@ private BooleanExpression isUserGreatInformation(Long userId) {
.otherwise(false);
}

private BooleanExpression isInformationBookmark(Long userId) {
return new CaseBuilder()
.when(JPAExpressions.selectOne()
.from(bookMarkInformation)
.where(bookMarkInformation.information.id.eq(information.id)
.and(bookMarkInformation.user.id.eq(userId)))
.exists())
.then(true)
.otherwise(false);
}


}

0 comments on commit 9177c17

Please sign in to comment.