Skip to content

Commit

Permalink
Merge pull request #146 from Team-Shaka/bug/135
Browse files Browse the repository at this point in the history
🐛 Fix: 브리핑 목록 조회 순위 버그 해결
  • Loading branch information
swa07016 authored Jan 7, 2024
2 parents cbfd0ee + 66ae90e commit 61d460f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -32,7 +31,6 @@ public List<Briefing> findBriefings(BriefingRequestParam.BriefingPreviewListPara
if (briefingList.isEmpty()) {
briefingList =
briefingRepository.findTop10ByTypeOrderByCreatedAtDesc(BriefingType.SOCIAL);
Collections.reverse(briefingList);
}
return briefingList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -34,7 +33,6 @@ public List<Briefing> findBriefings(BriefingRequestParam.BriefingPreviewListPara
}

briefingList = briefingRepository.findTop10ByTypeOrderByCreatedAtDesc(params.getType());
Collections.reverse(briefingList);
return briefingList;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package briefing.briefing.domain.repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -9,6 +10,9 @@
import org.springframework.stereotype.Repository;

import com.querydsl.core.Tuple;
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.impl.JPAQueryFactory;

import briefing.briefing.domain.Briefing;
Expand Down Expand Up @@ -61,6 +65,11 @@ public List<Briefing> findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) {
QBriefing briefing = QBriefing.briefing;
QScrap scrap = QScrap.scrap;

DateTimePath<LocalDateTime> dateTime = briefing.createdAt;
DateTemplate<LocalDate> date =
Expressions.dateTemplate(
LocalDate.class, "DATE_FORMAT({0}, {1})", dateTime, "%Y-%m-%d");

List<Tuple> results =
queryFactory
.select(briefing, scrap.count())
Expand All @@ -69,7 +78,7 @@ public List<Briefing> findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) {
.on(scrap.briefing.eq(briefing))
.where(briefing.type.eq(type))
.groupBy(briefing)
.orderBy(briefing.createdAt.desc())
.orderBy(date.desc(), briefing.ranks.asc())
.limit(10)
.fetch();

Expand Down

0 comments on commit 61d460f

Please sign in to comment.