From f09a64d70cfcbfbfb7ec6af60e6cf016d7c52d29 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Wed, 3 Jul 2024 09:51:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B8=8C=EB=A6=AC=ED=95=91=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20v2=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 14 ++++----- .../article/BriefingCustomRepositoryImpl.java | 29 +++++++++++-------- .../src/main/resources/application.properties | 1 - .../src/main/resources/application.yml | 8 +++-- src/main/resources/application.yml | 8 ++--- 5 files changed, 34 insertions(+), 26 deletions(-) delete mode 100644 core/Briefing-Common/src/main/resources/application.properties diff --git a/Briefing-Api/src/main/resources/application.yml b/Briefing-Api/src/main/resources/application.yml index 4ee24a7..ac2c9d5 100644 --- a/Briefing-Api/src/main/resources/application.yml +++ b/Briefing-Api/src/main/resources/application.yml @@ -97,8 +97,8 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect - # show_sql: true - # format_sql: true + show_sql: true + format_sql: true use_sql_comments: true hbm2ddl: auto: update @@ -147,8 +147,8 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect - # show_sql: true - # format_sql: true + show_sql: true + format_sql: true use_sql_comments: true hbm2ddl: auto: update @@ -186,9 +186,9 @@ spring: hibernate: ddl-hbm2ddl: auto: create - # show_sql: true - # format_sql: true - # use_sql_comments: true + show_sql: true + format_sql: true + use_sql_comments: true default_batch_fetch_size: 1000 data: redis: diff --git a/core/Briefing-Common/src/main/java/com/example/briefingcommon/domain/repository/article/BriefingCustomRepositoryImpl.java b/core/Briefing-Common/src/main/java/com/example/briefingcommon/domain/repository/article/BriefingCustomRepositoryImpl.java index 934757e..a8de58f 100644 --- a/core/Briefing-Common/src/main/java/com/example/briefingcommon/domain/repository/article/BriefingCustomRepositoryImpl.java +++ b/core/Briefing-Common/src/main/java/com/example/briefingcommon/domain/repository/article/BriefingCustomRepositoryImpl.java @@ -11,9 +11,11 @@ import com.example.briefingcommon.entity.enums.BriefingType; import com.example.briefingcommon.entity.enums.TimeOfDay; import com.querydsl.core.Tuple; +import com.querydsl.core.types.Expression; +import com.querydsl.core.types.ExpressionUtils; import com.querydsl.core.types.dsl.DateTemplate; import com.querydsl.core.types.dsl.DateTimePath; -import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.stereotype.Repository; @@ -64,20 +66,19 @@ public List findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) { QBriefing briefing = QBriefing.briefing; QScrap scrap = QScrap.scrap; - DateTimePath dateTime = briefing.createdAt; - DateTemplate date = - Expressions.dateTemplate( - LocalDate.class, "DATE_FORMAT({0}, {1})", dateTime, "%Y-%m-%d %H"); + Expression scrapCount = ExpressionUtils.as( + JPAExpressions.select(scrap.id.count()) + .from(scrap) + .where(scrap.briefing.eq(briefing)), + "scrapCount"); List results = queryFactory - .select(briefing, scrap.count()) + .select(briefing, + scrapCount) .from(briefing) - .leftJoin(scrap) - .on(scrap.briefing.eq(briefing)) .where(briefing.type.eq(type)) - .groupBy(briefing) - .orderBy(date.desc(), briefing.ranks.asc()) + .orderBy(briefing.createdAt.desc()) .limit(20) .fetch(); @@ -86,7 +87,8 @@ public List findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) { .map( tuple -> { Briefing b = tuple.get(briefing); - b.setScrapCount(Math.toIntExact(tuple.get(scrap.count()))); + Long scrapCountValue = tuple.get(scrapCount); + b.setScrapCount(Math.toIntExact(scrapCountValue)); return b; }) .collect(Collectors.toCollection(ArrayList::new)); @@ -94,7 +96,10 @@ public List findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) { Map briefingMap = new HashMap<>(); briefingList.forEach(candidate -> briefingMap.putIfAbsent(candidate.getRanks(), candidate)); - return briefingMap.values().stream().toList(); + return briefingMap.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); } @Override diff --git a/core/Briefing-Common/src/main/resources/application.properties b/core/Briefing-Common/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/core/Briefing-Common/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/core/Briefing-Common/src/main/resources/application.yml b/core/Briefing-Common/src/main/resources/application.yml index 5fbd264..26ec364 100644 --- a/core/Briefing-Common/src/main/resources/application.yml +++ b/core/Briefing-Common/src/main/resources/application.yml @@ -5,5 +5,9 @@ spring: baseline-version: 0 jpa: - hibernate: - ddl-auto: update \ No newline at end of file + properties: + hibernate: + ddl-auto: update + show_sql: true + format_sql: true + use_sql_comments: true \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 33cfba5..64b9273 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -87,8 +87,8 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect - # show_sql: true - # format_sql: true + show_sql: true + format_sql: true use_sql_comments: true hbm2ddl: auto: update @@ -137,8 +137,8 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect - # show_sql: true - # format_sql: true + show_sql: true + format_sql: true use_sql_comments: true hbm2ddl: auto: update