Skip to content

Commit

Permalink
✨ Feature: 기본 카테고리를 우선 정렬하도록 수정 (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong authored Jun 3, 2024
1 parent 5e3e1d2 commit 32c3547
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions moodoodle-domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dependencies {
implementation project(':moodoodle-common')

// spring boot
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import static zzangdol.scrap.domain.QScrap.scrap;
import static zzangdol.scrap.domain.QScrapCategory.scrapCategory;

import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import zzangdol.constant.Constants;
import zzangdol.scrap.domain.Category;
import zzangdol.user.domain.User;

Expand All @@ -25,7 +27,12 @@ public List<Category> findCategoriesByUserOrderByLatestScrapCategory(User user)
.leftJoin(scrapCategory.scrap, scrap)
.where(category.user.eq(user))
.groupBy(category.id)
.orderBy(scrapCategory.createdAt.max().desc().nullsLast())
.orderBy(
new CaseBuilder()
.when(category.name.eq(Constants.DEFAULT_CATEGORY_NAME)).then(0)
.otherwise(1).asc(),
scrapCategory.createdAt.max().desc().nullsLast()
)
.fetch();
}

Expand Down

0 comments on commit 32c3547

Please sign in to comment.