-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Category 저장 시 순서 저장 로직 추가 (#41)
* Feat: Category 저장 시 순서 저장 로직 추가 * Feat: CategoryCustomRepository 추가 * Feat: parentCategory 저장 로직 추가 * Refactor: 불필요한 주석 제거 * Feat: position 저장 로직 추가 * Refactor: Optional 사용 * Fix: 쿼리 수정
- Loading branch information
1 parent
94a3ce3
commit 2b3c7b6
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...n/java/kdkd/youre/backend/domain/category/domain/repository/CategoryCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kdkd.youre.backend.domain.category.domain.repository; | ||
|
||
import kdkd.youre.backend.domain.category.domain.Category; | ||
import kdkd.youre.backend.domain.member.domain.Member; | ||
|
||
public interface CategoryCustomRepository { | ||
Long findMaxPositionByMember(Member member); | ||
Long findMaxPositionForMemberAndParent(Member member, Category parent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ain/java/kdkd/youre/backend/domain/category/domain/repository/CategoryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kdkd.youre.backend.domain.category.domain.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import kdkd.youre.backend.domain.category.domain.Category; | ||
import kdkd.youre.backend.domain.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import static kdkd.youre.backend.domain.category.domain.QCategory.category; | ||
|
||
@RequiredArgsConstructor | ||
public class CategoryRepositoryImpl implements CategoryCustomRepository{ | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Long findMaxPositionByMember(Member member) { | ||
return queryFactory | ||
.select(category.position.max()) | ||
.from(category) | ||
.where( | ||
category.member.eq(member).and(category.parent.isNull()) | ||
) | ||
.fetchOne(); | ||
} | ||
|
||
@Override | ||
public Long findMaxPositionForMemberAndParent(Member member, Category parent) { | ||
return queryFactory | ||
.select(category.position.max()) | ||
.from(category) | ||
.where( | ||
category.member.eq(member).and(category.parent.eq(parent)) | ||
) | ||
.fetchOne(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters