-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] feat: Specification을 Querydsl로 대체한다 (#604) #609
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e78ec43
chore: Querydsl 설정 추가
BGuga d21f510
feat: Querydsl Bean 등록
BGuga b826945
refactor: queryDsl 을 통해 로직 수행
BGuga 8d0b45e
feat: Spec 삭제
BGuga b7b06b2
chore: 개행 추가
BGuga 7c8b1a7
test: RepositoryTest 정의
BGuga 562f015
refactor: enum switch 문 default 삭제
BGuga 264f8c7
chore: 불 필요한 설정 값 삭제
BGuga 7508a2b
test: RepositoryTest 적용
BGuga 38ea29c
chore: 메서드 네이밍 변경
BGuga 59752a5
Merge remote-tracking branch 'origin/dev' into feat/#604
seokjin8678 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### QUERYDSL ### | ||
/src/main/generated/ |
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
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/festago/config/QuerydslConfig.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,19 @@ | ||
package com.festago.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QuerydslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
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
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
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
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.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,10 @@ | ||
package com.festago.festival.repository; | ||
|
||
import com.festago.festival.domain.Festival; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public interface FestivalRepositoryCustom { | ||
|
||
List<Festival> findByFilter(FestivalFilter festivalFilter, LocalDate currentTime); | ||
} |
42 changes: 42 additions & 0 deletions
42
backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.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,42 @@ | ||
package com.festago.festival.repository; | ||
|
||
import static com.festago.festival.domain.QFestival.festival; | ||
|
||
import com.festago.festival.domain.Festival; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class FestivalRepositoryCustomImpl implements FestivalRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Festival> findByFilter(FestivalFilter festivalFilter, LocalDate currentTime) { | ||
return switch (festivalFilter) { | ||
case PLANNED -> plannedFestivals(currentTime); | ||
case PROGRESS -> progressFestivals(currentTime); | ||
case END -> endFestivals(currentTime); | ||
}; | ||
} | ||
|
||
private List<Festival> plannedFestivals(LocalDate currentTime) { | ||
return queryFactory.selectFrom(festival) | ||
.where(festival.startDate.gt(currentTime)) | ||
.orderBy(festival.startDate.asc()).fetch(); | ||
} | ||
|
||
private List<Festival> progressFestivals(LocalDate currentTime) { | ||
return queryFactory.selectFrom(festival) | ||
.where(festival.startDate.loe(currentTime).and(festival.endDate.goe(currentTime))) | ||
.orderBy(festival.startDate.asc()).fetch(); | ||
} | ||
|
||
private List<Festival> endFestivals(LocalDate currentTime) { | ||
return queryFactory.selectFrom(festival) | ||
.where(festival.endDate.lt(currentTime)) | ||
.orderBy(festival.endDate.desc()).fetch(); | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
backend/src/main/java/com/festago/festival/repository/FestivalSpecification.java
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
14 changes: 14 additions & 0 deletions
14
backend/src/test/java/com/festago/support/RepositoryTest.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,14 @@ | ||
package com.festago.support; | ||
|
||
import com.festago.config.QuerydslConfig; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@DataJpaTest | ||
@Import(QuerydslConfig.class) | ||
public @interface RepositoryTest { | ||
|
||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behavior
스프링 문서에는 접두사에 Custom을 사용하는데, 접미사로 Custom을 사용해주신 이유가 따로 있나요?