From e78ec43ae59f7f27ad8ce8303b81d3e9c2e50602 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 10:58:25 +0900 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20Querydsl=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.gitignore | 3 +++ backend/build.gradle | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/backend/.gitignore b/backend/.gitignore index b506e3002..728a2c212 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -37,3 +37,6 @@ out/ ### VS Code ### .vscode/ + +### QUERYDSL ### +/src/main/generated/ diff --git a/backend/build.gradle b/backend/build.gradle index b8d91cef4..6967ef488 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -7,6 +7,12 @@ plugins { group = 'com' version = '0.0.1-SNAPSHOT' +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + java { sourceCompatibility = '17' } @@ -47,6 +53,12 @@ dependencies { testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.13.0' testImplementation 'org.junit.platform:junit-platform-suite:1.8.2' + // Querydsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + // Flyway implementation 'org.flywaydb:flyway-core' implementation 'org.flywaydb:flyway-mysql' @@ -64,3 +76,21 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +// Querydsl 설정부 +def generated = 'src/main/generated' + +// querydsl QClass 파일 생성 위치를 지정 +tasks.withType(JavaCompile) { + options.getGeneratedSourceOutputDirectory().set(file(generated)) +} + +// java source set 에 querydsl QClass 위치 추가 +sourceSets { + main.java.srcDirs += [generated] +} + +// gradle clean 시에 QClass 디렉토리 삭제 +clean { + delete file(generated) +} From d21f510826f42b3e7fea96a0fc66f52e03b8b7ce Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 11:00:35 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20Querydsl=20Bean=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/config/QuerydslConfig.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 backend/src/main/java/com/festago/config/QuerydslConfig.java diff --git a/backend/src/main/java/com/festago/config/QuerydslConfig.java b/backend/src/main/java/com/festago/config/QuerydslConfig.java new file mode 100644 index 000000000..5f2fd66c5 --- /dev/null +++ b/backend/src/main/java/com/festago/config/QuerydslConfig.java @@ -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); + } +} From b8269455f6e2b1763ab8d93d265d39bc648da3ed Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 11:00:53 +0900 Subject: [PATCH 03/10] =?UTF-8?q?refactor:=20queryDsl=20=EC=9D=84=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EB=A1=9C=EC=A7=81=20=EC=88=98=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festago/common/exception/ErrorCode.java | 3 +- .../festival/application/FestivalService.java | 2 +- .../repository/FestivalRepository.java | 3 +- .../repository/FestivalRepositoryCustom.java | 10 ++++ .../FestivalRepositoryCustomImpl.java | 51 +++++++++++++++++++ .../repository/FestivalRepositoryTest.java | 19 ++++--- 6 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java create mode 100644 backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java diff --git a/backend/src/main/java/com/festago/common/exception/ErrorCode.java b/backend/src/main/java/com/festago/common/exception/ErrorCode.java index 890c4a099..c11fed050 100644 --- a/backend/src/main/java/com/festago/common/exception/ErrorCode.java +++ b/backend/src/main/java/com/festago/common/exception/ErrorCode.java @@ -67,7 +67,8 @@ public enum ErrorCode { INVALID_ROLE_NAME("해당하는 Role이 없습니다."), FOR_TEST_ERROR("테스트용 에러입니다."), FAIL_SEND_FCM_MESSAGE("FCM Message 전송에 실패했습니다."), - FCM_NOT_FOUND("유효하지 않은 MemberFCM 이 감지 되었습니다."); + FCM_NOT_FOUND("유효하지 않은 MemberFCM 이 감지 되었습니다."), + NOT_DEFINED_FESTIVAL_FESTIVAL("정의되지 않은 축제 필터입니다."); private final String message; diff --git a/backend/src/main/java/com/festago/festival/application/FestivalService.java b/backend/src/main/java/com/festago/festival/application/FestivalService.java index 5b8185718..4ad0fb19a 100644 --- a/backend/src/main/java/com/festago/festival/application/FestivalService.java +++ b/backend/src/main/java/com/festago/festival/application/FestivalService.java @@ -51,7 +51,7 @@ private void validate(Festival festival) { @Transactional(readOnly = true) public FestivalsResponse findFestivals(FestivalFilter festivalFilter) { - List festivals = festivalRepository.findAll(festivalFilter.getSpecification(LocalDate.now(clock))); + List festivals = festivalRepository.findFestivalBy(festivalFilter, LocalDate.now(clock)); return FestivalsResponse.from(festivals); } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java index 032b89a68..a71c6a272 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java @@ -2,8 +2,7 @@ import com.festago.festival.domain.Festival; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface FestivalRepository extends JpaRepository, JpaSpecificationExecutor { +public interface FestivalRepository extends JpaRepository, FestivalRepositoryCustom { } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java new file mode 100644 index 000000000..2e83226ff --- /dev/null +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java @@ -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 findFestivalBy(FestivalFilter festivalFilter, LocalDate currentTime); +} diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java new file mode 100644 index 000000000..85d488cf8 --- /dev/null +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java @@ -0,0 +1,51 @@ +package com.festago.festival.repository; + +import static com.festago.festival.domain.QFestival.festival; + +import com.festago.common.exception.ErrorCode; +import com.festago.common.exception.InternalServerException; +import com.festago.festival.domain.Festival; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.time.LocalDate; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class FestivalRepositoryCustomImpl implements FestivalRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public List findFestivalBy(FestivalFilter festivalFilter, LocalDate currentTime) { + return switch (festivalFilter) { + case PLANNED -> plannedFestivals(currentTime); + case PROGRESS -> progressFestivals(currentTime); + case END -> endFestivals(currentTime); + default -> throw new InternalServerException(ErrorCode.NOT_DEFINED_FESTIVAL_FESTIVAL); + }; + } + + private List plannedFestivals(LocalDate currentTime) { + return queryFactory.selectFrom(festival) + .where(festival.startDate.gt(currentTime)) + .orderBy(festival.startDate.asc()) + .fetch(); + } + + private List progressFestivals(LocalDate currentTime) { + return queryFactory.selectFrom(festival) + .where(festival.startDate.loe(currentTime) + .and(festival.endDate.goe(currentTime))) + .orderBy(festival.startDate.asc()) + .fetch(); + } + + private List endFestivals(LocalDate currentTime) { + return queryFactory.selectFrom(festival) + .where(festival.endDate.lt(currentTime)) + .orderBy(festival.endDate.desc()) + .fetch(); + } +} diff --git a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java index 81e13a050..40b43fa78 100644 --- a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java +++ b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java @@ -14,11 +14,14 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.transaction.annotation.Transactional; @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -@DataJpaTest +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@Transactional class FestivalRepositoryTest { private static final String CURRENT_FESTIVAL = "현재 축제"; @@ -56,7 +59,7 @@ class 진행_에정_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertSoftly(softAssertions -> { @@ -77,7 +80,7 @@ class 진행_에정_축제_반환 { new Festival("festival1", now.plusDays(1), now.plusDays(10), school)); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertThat(actual).isEqualTo(List.of(festival1, festival2, festival3)); @@ -94,7 +97,7 @@ class 진행_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertSoftly(softAssertions -> { @@ -115,7 +118,7 @@ class 진행_축제_반환 { new Festival("festival1", now.minusDays(3), now.plusDays(10), school)); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertThat(actual).isEqualTo(List.of(festival1, festival2, festival3)); @@ -132,7 +135,7 @@ class 종료_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertSoftly(softAssertions -> { @@ -153,7 +156,7 @@ class 종료_축제_반환 { new Festival("festival1", now.minusDays(10), now.minusDays(3), school)); // when - List actual = festivalRepository.findAll(filter.getSpecification(now)); + List actual = festivalRepository.findFestivalBy(filter, now); // then assertThat(actual).isEqualTo(List.of(festival3, festival2, festival1)); From 8d0b45e0a5c368e2bd8acc7363075c1fb5479ebd Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 11:02:45 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20Spec=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/repository/FestivalFilter.java | 20 ++-------- .../FestivalRepositoryCustomImpl.java | 20 +++------- .../repository/FestivalSpecification.java | 38 ------------------- 3 files changed, 9 insertions(+), 69 deletions(-) delete mode 100644 backend/src/main/java/com/festago/festival/repository/FestivalSpecification.java diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalFilter.java b/backend/src/main/java/com/festago/festival/repository/FestivalFilter.java index 81f60d250..7a328b631 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalFilter.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalFilter.java @@ -2,21 +2,11 @@ import com.festago.common.exception.BadRequestException; import com.festago.common.exception.ErrorCode; -import com.festago.festival.domain.Festival; -import java.time.LocalDate; -import java.util.function.Function; -import org.springframework.data.jpa.domain.Specification; public enum FestivalFilter { - PROGRESS(FestivalSpecification::progress), - PLANNED(FestivalSpecification::planned), - END(FestivalSpecification::end); - - private final Function> filter; - - FestivalFilter(Function> filter) { - this.filter = filter; - } + PROGRESS, + PLANNED, + END; public static FestivalFilter from(String filterName) { return switch (filterName.toUpperCase()) { @@ -26,8 +16,4 @@ public static FestivalFilter from(String filterName) { default -> throw new BadRequestException(ErrorCode.INVALID_FESTIVAL_FILTER); }; } - - public Specification getSpecification(LocalDate currentTime) { - return filter.apply(currentTime); - } } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java index 85d488cf8..3fef0b8dc 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java @@ -9,9 +9,7 @@ import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; -@Repository @RequiredArgsConstructor public class FestivalRepositoryCustomImpl implements FestivalRepositoryCustom { @@ -28,24 +26,18 @@ public List findFestivalBy(FestivalFilter festivalFilter, LocalDate cu } private List plannedFestivals(LocalDate currentTime) { - return queryFactory.selectFrom(festival) - .where(festival.startDate.gt(currentTime)) - .orderBy(festival.startDate.asc()) - .fetch(); + return queryFactory.selectFrom(festival).where(festival.startDate.gt(currentTime)) + .orderBy(festival.startDate.asc()).fetch(); } private List progressFestivals(LocalDate currentTime) { return queryFactory.selectFrom(festival) - .where(festival.startDate.loe(currentTime) - .and(festival.endDate.goe(currentTime))) - .orderBy(festival.startDate.asc()) - .fetch(); + .where(festival.startDate.loe(currentTime).and(festival.endDate.goe(currentTime))) + .orderBy(festival.startDate.asc()).fetch(); } private List endFestivals(LocalDate currentTime) { - return queryFactory.selectFrom(festival) - .where(festival.endDate.lt(currentTime)) - .orderBy(festival.endDate.desc()) - .fetch(); + return queryFactory.selectFrom(festival).where(festival.endDate.lt(currentTime)) + .orderBy(festival.endDate.desc()).fetch(); } } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalSpecification.java b/backend/src/main/java/com/festago/festival/repository/FestivalSpecification.java deleted file mode 100644 index 50e7efb5c..000000000 --- a/backend/src/main/java/com/festago/festival/repository/FestivalSpecification.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.festago.festival.repository; - -import com.festago.festival.domain.Festival; -import java.time.LocalDate; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.data.jpa.domain.Specification; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class FestivalSpecification { - - private static final String START_DATE = "startDate"; - private static final String END_DATE = "endDate"; - - public static Specification progress(LocalDate currentTime) { - return (root, query, criteriaBuilder) -> { - query.orderBy(criteriaBuilder.asc(root.get(START_DATE))); - return criteriaBuilder.and( - criteriaBuilder.lessThanOrEqualTo(root.get(START_DATE), currentTime), - criteriaBuilder.greaterThanOrEqualTo(root.get(END_DATE), currentTime) - ); - }; - } - - public static Specification planned(LocalDate currentTime) { - return (root, query, criteriaBuilder) -> { - query.orderBy(criteriaBuilder.asc(root.get(START_DATE))); - return criteriaBuilder.greaterThan(root.get(START_DATE), currentTime); - }; - } - - public static Specification end(LocalDate currentTime) { - return (root, query, criteriaBuilder) -> { - query.orderBy(criteriaBuilder.desc(root.get(END_DATE))); - return criteriaBuilder.lessThan(root.get(END_DATE), currentTime); - }; - } -} From b7b06b2b978224f1e810ceadb9396bd5d622cbc3 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 12:56:14 +0900 Subject: [PATCH 05/10] =?UTF-8?q?chore:=20=EA=B0=9C=ED=96=89=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/repository/FestivalRepositoryCustomImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java index 3fef0b8dc..601509bfc 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java @@ -26,7 +26,8 @@ public List findFestivalBy(FestivalFilter festivalFilter, LocalDate cu } private List plannedFestivals(LocalDate currentTime) { - return queryFactory.selectFrom(festival).where(festival.startDate.gt(currentTime)) + return queryFactory.selectFrom(festival) + .where(festival.startDate.gt(currentTime)) .orderBy(festival.startDate.asc()).fetch(); } @@ -37,7 +38,8 @@ private List progressFestivals(LocalDate currentTime) { } private List endFestivals(LocalDate currentTime) { - return queryFactory.selectFrom(festival).where(festival.endDate.lt(currentTime)) + return queryFactory.selectFrom(festival) + .where(festival.endDate.lt(currentTime)) .orderBy(festival.endDate.desc()).fetch(); } } From 7c8b1a7b524ea265ebe5aa1d94451900b8119e6c Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 13:14:50 +0900 Subject: [PATCH 06/10] =?UTF-8?q?test:=20RepositoryTest=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/domain/MemberRepositoryTest.java | 4 ++-- .../festago/domain/MemberTicketRepositoryTest.java | 4 ++-- .../com/festago/domain/StageRepositoryTest.java | 5 +++-- .../com/festago/domain/TicketRepositoryTest.java | 4 ++-- .../fcm/repository/MemberFCMRepositoryTest.java | 4 ++-- .../student/repository/StudentRepositoryTest.java | 4 ++-- .../java/com/festago/support/RepositoryTest.java | 14 ++++++++++++++ 7 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 backend/src/test/java/com/festago/support/RepositoryTest.java diff --git a/backend/src/test/java/com/festago/domain/MemberRepositoryTest.java b/backend/src/test/java/com/festago/domain/MemberRepositoryTest.java index 6e6e2e927..0eba9d78d 100644 --- a/backend/src/test/java/com/festago/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/com/festago/domain/MemberRepositoryTest.java @@ -6,16 +6,16 @@ import com.festago.member.domain.Member; import com.festago.member.repository.MemberRepository; import com.festago.support.MemberFixture; +import com.festago.support.RepositoryTest; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -@DataJpaTest +@RepositoryTest class MemberRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/festago/domain/MemberTicketRepositoryTest.java b/backend/src/test/java/com/festago/domain/MemberTicketRepositoryTest.java index bafb2b838..ef68965c1 100644 --- a/backend/src/test/java/com/festago/domain/MemberTicketRepositoryTest.java +++ b/backend/src/test/java/com/festago/domain/MemberTicketRepositoryTest.java @@ -15,6 +15,7 @@ import com.festago.support.FestivalFixture; import com.festago.support.MemberFixture; import com.festago.support.MemberTicketFixture; +import com.festago.support.RepositoryTest; import com.festago.support.SchoolFixture; import com.festago.support.StageFixture; import com.festago.ticket.repository.TicketRepository; @@ -28,16 +29,15 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @Import(JpaAuditingConfig.class) -@DataJpaTest @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") +@RepositoryTest class MemberTicketRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/festago/domain/StageRepositoryTest.java b/backend/src/test/java/com/festago/domain/StageRepositoryTest.java index c88bb4cf9..7c45a8211 100644 --- a/backend/src/test/java/com/festago/domain/StageRepositoryTest.java +++ b/backend/src/test/java/com/festago/domain/StageRepositoryTest.java @@ -10,6 +10,7 @@ import com.festago.stage.domain.Stage; import com.festago.stage.repository.StageRepository; import com.festago.support.FestivalFixture; +import com.festago.support.RepositoryTest; import com.festago.support.SchoolFixture; import com.festago.support.StageFixture; import com.festago.support.TicketFixture; @@ -22,11 +23,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -@DataJpaTest @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") +@RepositoryTest class StageRepositoryTest { @Autowired @@ -111,3 +111,4 @@ class StageRepositoryTest { }); } } + diff --git a/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java b/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java index 9c9361b71..c16325a4b 100644 --- a/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java +++ b/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java @@ -9,6 +9,7 @@ import com.festago.stage.domain.Stage; import com.festago.stage.repository.StageRepository; import com.festago.support.FestivalFixture; +import com.festago.support.RepositoryTest; import com.festago.support.SchoolFixture; import com.festago.support.StageFixture; import com.festago.support.TicketFixture; @@ -20,11 +21,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -@DataJpaTest +@RepositoryTest class TicketRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/festago/fcm/repository/MemberFCMRepositoryTest.java b/backend/src/test/java/com/festago/fcm/repository/MemberFCMRepositoryTest.java index 3ea135724..f4b3fa624 100644 --- a/backend/src/test/java/com/festago/fcm/repository/MemberFCMRepositoryTest.java +++ b/backend/src/test/java/com/festago/fcm/repository/MemberFCMRepositoryTest.java @@ -6,12 +6,12 @@ import com.festago.fcm.domain.MemberFCM; import com.festago.member.domain.Member; import com.festago.member.repository.MemberRepository; +import com.festago.support.RepositoryTest; import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -@DataJpaTest +@RepositoryTest class MemberFCMRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/festago/student/repository/StudentRepositoryTest.java b/backend/src/test/java/com/festago/student/repository/StudentRepositoryTest.java index 6076dab94..976ece1ae 100644 --- a/backend/src/test/java/com/festago/student/repository/StudentRepositoryTest.java +++ b/backend/src/test/java/com/festago/student/repository/StudentRepositoryTest.java @@ -8,6 +8,7 @@ import com.festago.school.repository.SchoolRepository; import com.festago.student.domain.Student; import com.festago.support.MemberFixture; +import com.festago.support.RepositoryTest; import com.festago.support.SchoolFixture; import com.festago.support.StudentFixture; import java.util.Optional; @@ -15,11 +16,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -@DataJpaTest +@RepositoryTest class StudentRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/festago/support/RepositoryTest.java b/backend/src/test/java/com/festago/support/RepositoryTest.java new file mode 100644 index 000000000..e4b2414d5 --- /dev/null +++ b/backend/src/test/java/com/festago/support/RepositoryTest.java @@ -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 { + +} From 562f015f90f56ba5dc4a9844fd7a5e41fdef0511 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 17:22:30 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20enum=20switch=20=EB=AC=B8=20d?= =?UTF-8?q?efault=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/festago/common/exception/ErrorCode.java | 3 +-- .../festival/repository/FestivalRepositoryCustomImpl.java | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/src/main/java/com/festago/common/exception/ErrorCode.java b/backend/src/main/java/com/festago/common/exception/ErrorCode.java index c11fed050..890c4a099 100644 --- a/backend/src/main/java/com/festago/common/exception/ErrorCode.java +++ b/backend/src/main/java/com/festago/common/exception/ErrorCode.java @@ -67,8 +67,7 @@ public enum ErrorCode { INVALID_ROLE_NAME("해당하는 Role이 없습니다."), FOR_TEST_ERROR("테스트용 에러입니다."), FAIL_SEND_FCM_MESSAGE("FCM Message 전송에 실패했습니다."), - FCM_NOT_FOUND("유효하지 않은 MemberFCM 이 감지 되었습니다."), - NOT_DEFINED_FESTIVAL_FESTIVAL("정의되지 않은 축제 필터입니다."); + FCM_NOT_FOUND("유효하지 않은 MemberFCM 이 감지 되었습니다."); private final String message; diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java index 601509bfc..61b61a867 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java @@ -2,8 +2,6 @@ import static com.festago.festival.domain.QFestival.festival; -import com.festago.common.exception.ErrorCode; -import com.festago.common.exception.InternalServerException; import com.festago.festival.domain.Festival; import com.querydsl.jpa.impl.JPAQueryFactory; import java.time.LocalDate; @@ -21,7 +19,6 @@ public List findFestivalBy(FestivalFilter festivalFilter, LocalDate cu case PLANNED -> plannedFestivals(currentTime); case PROGRESS -> progressFestivals(currentTime); case END -> endFestivals(currentTime); - default -> throw new InternalServerException(ErrorCode.NOT_DEFINED_FESTIVAL_FESTIVAL); }; } From 264f8c7be1772526705f8f9a5eea9243cfa10d9e Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 14 Nov 2023 17:22:42 +0900 Subject: [PATCH 08/10] =?UTF-8?q?chore:=20=EB=B6=88=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=84=A4=EC=A0=95=20=EA=B0=92=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 6967ef488..a3d6059a5 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -7,12 +7,6 @@ plugins { group = 'com' version = '0.0.1-SNAPSHOT' -configurations { - compileOnly { - extendsFrom annotationProcessor - } -} - java { sourceCompatibility = '17' } From 7508a2b70bb5356ff1b00683e23df590314725c0 Mon Sep 17 00:00:00 2001 From: BGuga Date: Thu, 16 Nov 2023 14:54:17 +0900 Subject: [PATCH 09/10] =?UTF-8?q?test:=20RepositoryTest=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/repository/FestivalRepositoryTest.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java index 40b43fa78..07579187e 100644 --- a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java +++ b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java @@ -6,6 +6,7 @@ import com.festago.festival.domain.Festival; import com.festago.school.domain.School; import com.festago.school.repository.SchoolRepository; +import com.festago.support.RepositoryTest; import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -14,14 +15,10 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.transaction.annotation.Transactional; @DisplayNameGeneration(ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -@SpringBootTest(webEnvironment = WebEnvironment.NONE) -@Transactional +@RepositoryTest class FestivalRepositoryTest { private static final String CURRENT_FESTIVAL = "현재 축제"; From 38ea29c1af5542a0cc349dca4e9e30b1c5b96144 Mon Sep 17 00:00:00 2001 From: BGuga Date: Thu, 16 Nov 2023 14:56:10 +0900 Subject: [PATCH 10/10] =?UTF-8?q?chore:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/application/FestivalService.java | 2 +- .../repository/FestivalRepositoryCustom.java | 2 +- .../repository/FestivalRepositoryCustomImpl.java | 2 +- .../festival/repository/FestivalRepositoryTest.java | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/festago/festival/application/FestivalService.java b/backend/src/main/java/com/festago/festival/application/FestivalService.java index 4ad0fb19a..a7a298e0d 100644 --- a/backend/src/main/java/com/festago/festival/application/FestivalService.java +++ b/backend/src/main/java/com/festago/festival/application/FestivalService.java @@ -51,7 +51,7 @@ private void validate(Festival festival) { @Transactional(readOnly = true) public FestivalsResponse findFestivals(FestivalFilter festivalFilter) { - List festivals = festivalRepository.findFestivalBy(festivalFilter, LocalDate.now(clock)); + List festivals = festivalRepository.findByFilter(festivalFilter, LocalDate.now(clock)); return FestivalsResponse.from(festivals); } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java index 2e83226ff..531f1f64c 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustom.java @@ -6,5 +6,5 @@ public interface FestivalRepositoryCustom { - List findFestivalBy(FestivalFilter festivalFilter, LocalDate currentTime); + List findByFilter(FestivalFilter festivalFilter, LocalDate currentTime); } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java index 61b61a867..db79bfcb6 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepositoryCustomImpl.java @@ -14,7 +14,7 @@ public class FestivalRepositoryCustomImpl implements FestivalRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public List findFestivalBy(FestivalFilter festivalFilter, LocalDate currentTime) { + public List findByFilter(FestivalFilter festivalFilter, LocalDate currentTime) { return switch (festivalFilter) { case PLANNED -> plannedFestivals(currentTime); case PROGRESS -> progressFestivals(currentTime); diff --git a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java index 07579187e..f36b269be 100644 --- a/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java +++ b/backend/src/test/java/com/festago/festival/repository/FestivalRepositoryTest.java @@ -56,7 +56,7 @@ class 진행_에정_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertSoftly(softAssertions -> { @@ -77,7 +77,7 @@ class 진행_에정_축제_반환 { new Festival("festival1", now.plusDays(1), now.plusDays(10), school)); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertThat(actual).isEqualTo(List.of(festival1, festival2, festival3)); @@ -94,7 +94,7 @@ class 진행_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertSoftly(softAssertions -> { @@ -115,7 +115,7 @@ class 진행_축제_반환 { new Festival("festival1", now.minusDays(3), now.plusDays(10), school)); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertThat(actual).isEqualTo(List.of(festival1, festival2, festival3)); @@ -132,7 +132,7 @@ class 종료_축제_반환 { prepareNotOrderedFestivals(); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertSoftly(softAssertions -> { @@ -153,7 +153,7 @@ class 종료_축제_반환 { new Festival("festival1", now.minusDays(10), now.minusDays(3), school)); // when - List actual = festivalRepository.findFestivalBy(filter, now); + List actual = festivalRepository.findByFilter(filter, now); // then assertThat(actual).isEqualTo(List.of(festival3, festival2, festival1));