From 946ec757913b0b24c51d0047bf92082213d38aba Mon Sep 17 00:00:00 2001 From: BGuga Date: Wed, 15 May 2024 23:10:16 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EA=B3=B5=EC=97=B0=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=B6=95=EC=A0=9C=EA=B0=80=20=EC=9D=B8?= =?UTF-8?q?=EA=B8=B0=20=EC=B6=95=EC=A0=9C=EB=A1=9C=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PopularFestivalV1QueryDslRepository.java | 1 + ...FestivalV1QueryServiceIntegrationTest.java | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java b/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java index 7470d13c4..8777aaea5 100644 --- a/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java @@ -38,6 +38,7 @@ public List findPopularFestivals() { festivalQueryInfo.artistInfo) ) .from(festival) + .where(festivalQueryInfo.artistInfo.ne("[]")) .innerJoin(school).on(school.id.eq(festival.school.id)) .innerJoin(festivalQueryInfo).on(festivalQueryInfo.festivalId.eq(festival.id)) .orderBy(festival.id.desc()) diff --git a/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java b/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java index d85f1ccaf..fb8ca7597 100644 --- a/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java +++ b/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.festago.artist.repository.ArtistRepository; import com.festago.festival.application.PopularFestivalV1QueryService; import com.festago.festival.application.command.FestivalCreateService; import com.festago.festival.dto.FestivalV1Response; @@ -9,8 +10,13 @@ import com.festago.school.application.SchoolCommandService; import com.festago.school.domain.SchoolRegion; import com.festago.school.dto.SchoolCreateCommand; +import com.festago.stage.application.command.StageCreateService; +import com.festago.stage.dto.command.StageCreateCommand; import com.festago.support.ApplicationIntegrationTest; +import com.festago.support.fixture.ArtistFixture; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -30,7 +36,14 @@ class PopularFestivalV1QueryServiceIntegrationTest extends ApplicationIntegratio @Autowired SchoolCommandService schoolCommandService; + @Autowired + StageCreateService stageCreateService; + + @Autowired + ArtistRepository artistRepository; + LocalDate now = LocalDate.parse("2077-06-30"); + LocalDateTime nowDate = now.atTime(12, 00); Long 대학교_식별자; @@ -42,6 +55,8 @@ class PopularFestivalV1QueryServiceIntegrationTest extends ApplicationIntegratio Long 여섯번째로_저장된_축제_식별자; Long 일곱번째로_저장된_축제_식별자; Long 여덟번째로_저장된_축제_식별자; + Long 아홉번쨔로_저장된_무대없는_축제_식별자; + Long 열번쨰로_저장된_무대없는_축제_식별자; @BeforeEach void setUp() { @@ -53,6 +68,8 @@ void setUp() { "https://image.com/background.png" )); + List 아티스트_리스트 = List.of(artistRepository.save(ArtistFixture.builder().build()).getId()); + 첫번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("첫번째로 저장된 축제")); 두번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("두번째로 저장된 축제")); 세번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("세번째로 저장된 축제")); @@ -61,6 +78,19 @@ void setUp() { 여섯번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("여섯번째로 저장된 축제")); 일곱번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("일곱번째로 저장된 축제")); 여덟번째로_저장된_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("여덟번째로 저장된 축제")); + 아홉번쨔로_저장된_무대없는_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("아홉번쨔로 저장된 축제")); + 열번쨰로_저장된_무대없는_축제_식별자 = festivalCreateService.createFestival(getFestivalCreateCommand("열번쨰로 저장된 축제")); + + LocalDateTime 티켓_오픈_시간 = nowDate.minusDays(1L); + + stageCreateService.createStage(new StageCreateCommand(첫번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(두번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(세번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(네번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(다섯번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(여섯번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(일곱번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); + stageCreateService.createStage(new StageCreateCommand(여덟번째로_저장된_축제_식별자, nowDate, 티켓_오픈_시간, 아티스트_리스트)); } private FestivalCreateCommand getFestivalCreateCommand(String schoolName) { @@ -68,7 +98,7 @@ private FestivalCreateCommand getFestivalCreateCommand(String schoolName) { } @Test - void 인기_축제는_7개까지_반환되고_식별자의_내림차순으로_정렬되어_조회된다() { + void 인기_축제는_공연이_뜽록된_축제만_7개까지_반환되고_식별자의_내림차순으로_정렬되어_조회된다() { // given && when var expect = popularQueryService.findPopularFestivals().content(); From 6ca103e3b135bcbabd23c1b5c3e9fe36998b3d34 Mon Sep 17 00:00:00 2001 From: BGuga Date: Wed, 15 May 2024 23:12:34 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20ClientAbortException=20=EB=A5=BC=20?= =?UTF-8?q?BadRequest=20=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/common/handler/GlobalExceptionHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/main/java/com/festago/common/handler/GlobalExceptionHandler.java b/backend/src/main/java/com/festago/common/handler/GlobalExceptionHandler.java index 0d314d4d3..b26be3752 100644 --- a/backend/src/main/java/com/festago/common/handler/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/festago/common/handler/GlobalExceptionHandler.java @@ -15,6 +15,7 @@ import com.festago.common.exception.dto.ValidErrorResponse; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; +import org.apache.catalina.connector.ClientAbortException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; @@ -63,6 +64,11 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { private final AuthenticateContext authenticateContext; + @ExceptionHandler(ClientAbortException.class) + public ResponseEntity handle(ClientAbortException e) { + return ResponseEntity.badRequest().build(); + } + @ExceptionHandler(InvalidMediaTypeException.class) public ResponseEntity handle(InvalidMediaTypeException e) { return ResponseEntity.badRequest().build(); From 4a47d1e4ede0163ed494a1941d82db1d462e9eab Mon Sep 17 00:00:00 2001 From: BGuga Date: Thu, 16 May 2024 11:49:50 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EC=B6=95=EC=A0=9C=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=9C=20=EC=B6=95=EC=A0=9C?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B8=EA=B8=B0=20=EC=B6=95=EC=A0=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PopularFestivalV1QueryService.java | 5 +- .../PopularFestivalV1QueryDslRepository.java | 6 +- ...FestivalV1QueryServiceIntegrationTest.java | 61 +++++++++++++------ 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/com/festago/festival/application/PopularFestivalV1QueryService.java b/backend/src/main/java/com/festago/festival/application/PopularFestivalV1QueryService.java index ff850a433..7860c3523 100644 --- a/backend/src/main/java/com/festago/festival/application/PopularFestivalV1QueryService.java +++ b/backend/src/main/java/com/festago/festival/application/PopularFestivalV1QueryService.java @@ -3,6 +3,8 @@ import com.festago.festival.dto.FestivalV1Response; import com.festago.festival.dto.PopularFestivalsV1Response; import com.festago.festival.repository.PopularFestivalV1QueryDslRepository; +import java.time.Clock; +import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -14,9 +16,10 @@ public class PopularFestivalV1QueryService { private final PopularFestivalV1QueryDslRepository popularFestivalRepository; + private final Clock clock; public PopularFestivalsV1Response findPopularFestivals() { - List popularFestivals = popularFestivalRepository.findPopularFestivals(); + List popularFestivals = popularFestivalRepository.findPopularFestivals(LocalDate.now(clock)); return new PopularFestivalsV1Response( "요즘 뜨는 축제", popularFestivals diff --git a/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java b/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java index 8777aaea5..82e0f39f6 100644 --- a/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/PopularFestivalV1QueryDslRepository.java @@ -9,6 +9,7 @@ import com.festago.festival.dto.FestivalV1Response; import com.festago.festival.dto.QFestivalV1Response; import com.festago.festival.dto.QSchoolV1Response; +import java.time.LocalDate; import java.util.List; import org.springframework.stereotype.Repository; @@ -24,7 +25,7 @@ public PopularFestivalV1QueryDslRepository() { /** * 아직 명확한 추천 축제 기준이 없으므로 생성 시간(식별자) 내림차순으로 반환하도록 함 */ - public List findPopularFestivals() { + public List findPopularFestivals(LocalDate now) { return select(new QFestivalV1Response( festival.id, festival.name, @@ -38,7 +39,8 @@ public List findPopularFestivals() { festivalQueryInfo.artistInfo) ) .from(festival) - .where(festivalQueryInfo.artistInfo.ne("[]")) + .where(festivalQueryInfo.artistInfo.ne("[]") + .and(festival.festivalDuration.endDate.goe(now))) .innerJoin(school).on(school.id.eq(festival.school.id)) .innerJoin(festivalQueryInfo).on(festivalQueryInfo.festivalId.eq(festival.id)) .orderBy(festival.id.desc()) diff --git a/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java b/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java index 2cbeef46e..77f5526dc 100644 --- a/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java +++ b/backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java @@ -13,6 +13,7 @@ import com.festago.support.fixture.FestivalFixture; import com.festago.support.fixture.FestivalQueryInfoFixture; import com.festago.support.fixture.SchoolFixture; +import java.time.LocalDate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -47,26 +48,31 @@ class PopularFestivalV1QueryServiceIntegrationTest extends ApplicationIntegratio Festival 여덟번째로_저장된_축제; Festival 아홉번째로_저장된_공연없는_축제; Festival 열번째로_저장된_공연없는_축제; + Festival 열한번쨰로_저장된_기간이_지난_축제; @BeforeEach void setUp() { 대학교 = schoolRepository.save(SchoolFixture.builder().build()); - 첫번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 두번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 세번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 네번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 다섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 여섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 일곱번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 여덟번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(); - 아홉번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(); - 열번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(); + LocalDate startDate = LocalDate.now();; + LocalDate endDate = startDate.plusDays(3); + + 첫번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 두번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 세번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 네번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 다섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 여섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 일곱번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 여덟번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate); + 아홉번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(startDate, endDate); + 열번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(startDate, endDate); + 열한번쨰로_저장된_기간이_지난_축제 = createFestivalWithFilledFestivalInfo(startDate.minusDays(10L), endDate.minusDays(13L)); } - private Festival createFestivalWithFilledFestivalInfo() { - Festival festival = festivalRepository.save(FestivalFixture.builder().school(대학교).build()); - festivalInfoRepository.save(makeBaseFixture(festival) + private Festival createFestivalWithFilledFestivalInfo(LocalDate startDate, LocalDate endDate) { + Festival festival = festivalRepository.save(makeBaseFestivalFixture(startDate, endDate)); + festivalInfoRepository.save(makeBaseFestivalInfoFixture(festival) .artistInfo(""" { notEmpty @@ -76,14 +82,22 @@ private Festival createFestivalWithFilledFestivalInfo() { return festival; } - private FestivalQueryInfoFixture makeBaseFixture(Festival festival) { + private Festival makeBaseFestivalFixture(LocalDate startDate, LocalDate endDate) { + return FestivalFixture.builder() + .school(대학교) + .startDate(startDate) + .endDate(endDate) + .build(); + } + + private FestivalQueryInfoFixture makeBaseFestivalInfoFixture(Festival festival) { return FestivalQueryInfoFixture.builder() .festivalId(festival.getId()); } - private Festival createFestivalWithEmptyFestivalInfo() { - Festival festival = festivalRepository.save(FestivalFixture.builder().school(대학교).build()); - festivalInfoRepository.save(makeBaseFixture(festival) + private Festival createFestivalWithEmptyFestivalInfo(LocalDate startDate, LocalDate endDate) { + Festival festival = festivalRepository.save(makeBaseFestivalFixture(startDate, endDate)); + festivalInfoRepository.save(makeBaseFestivalInfoFixture(festival) .build()); return festival; } @@ -106,4 +120,17 @@ private Festival createFestivalWithEmptyFestivalInfo() { 두번째로_저장된_축제.getId() ); } + + @Test + void 축제_기간이_끝난_축제는_반환되지_않는다() { + // when + var expect = popularQueryService.findPopularFestivals().content(); + + // then + assertThat(expect) + .map(FestivalV1Response::id) + .doesNotContain( + 열한번쨰로_저장된_기간이_지난_축제.getId() + ); + } }