diff --git a/pickly-service/src/main/java/org/pickly/service/domain/bookmark/repository/impl/BookmarkQueryRepositoryImpl.java b/pickly-service/src/main/java/org/pickly/service/domain/bookmark/repository/impl/BookmarkQueryRepositoryImpl.java index 49df70b2..732d7691 100644 --- a/pickly-service/src/main/java/org/pickly/service/domain/bookmark/repository/impl/BookmarkQueryRepositoryImpl.java +++ b/pickly-service/src/main/java/org/pickly/service/domain/bookmark/repository/impl/BookmarkQueryRepositoryImpl.java @@ -2,9 +2,12 @@ import com.querydsl.core.Tuple; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.core.types.dsl.NumberExpression; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.pickly.service.common.utils.page.PageRequest; import org.pickly.service.common.utils.timezone.TimezoneHandler; import org.pickly.service.domain.bookmark.entity.Bookmark; @@ -24,6 +27,7 @@ import static org.pickly.service.domain.category.entity.QCategory.category; import static org.pickly.service.domain.notification.entity.QNotification.notification; +@Slf4j @Repository @RequiredArgsConstructor public class BookmarkQueryRepositoryImpl implements BookmarkQueryRepository { @@ -100,6 +104,7 @@ public List findBookmarkByCategoryId(PageRequest pageRequest, Long cat return queryFactory .selectFrom(bookmark) .where( + ltCursorId(cursorId), eqCategoryId(categoryId), notDeleted() ) @@ -138,7 +143,7 @@ public Map findCategoryReadStatus(final Long membe .select( category, bookmark.id.count(), - bookmark.readByUser.count() + sumReadTrue() ) .from(category) .leftJoin(bookmark).on(category.id.eq(bookmark.category.id)) @@ -154,7 +159,7 @@ public Map findCategoryReadStatus(final Long membe for (Tuple result : results) { Category currentCategory = result.get(category); Long totalBookmarks = result.get(bookmark.id.count()); - Long readBookmarks = result.get(bookmark.readByUser.count()); + Long readBookmarks = result.get(sumReadTrue()); BookmarkReadStatus status = new BookmarkReadStatus(totalBookmarks, readBookmarks); categoryBookmarkCounts.put(currentCategory, status); @@ -162,6 +167,14 @@ public Map findCategoryReadStatus(final Long membe return categoryBookmarkCounts; } + private NumberExpression sumReadTrue() { + return new CaseBuilder() + .when(bookmark.readByUser.isTrue()) + .then(1L) + .otherwise(0L) + .sum(); + } + private BooleanExpression eqMemberId(final Long memberId) { if (memberId == null) { return null; diff --git a/pickly-service/src/main/resources/application-dev.yml b/pickly-service/src/main/resources/application-dev.yml index 900619c5..311c5bc2 100644 --- a/pickly-service/src/main/resources/application-dev.yml +++ b/pickly-service/src/main/resources/application-dev.yml @@ -19,9 +19,9 @@ spring: mode: never # postgreSQL local 설정 datasource: - url: jdbc:postgresql://localhost:5450/pickly - username: postgres - password: postgres + url: jdbc:postgresql://${DEV_DB_HOST}:${DEV_DB_PORT}/${DB_DBNAME} + username: ${DB_USERNAME} + password: ${DEV_DB_PASSWORD} # 로깅 관련 logging: