From 466fa464c178b187cb94e6868a0f8e5dd6d26f29 Mon Sep 17 00:00:00 2001 From: Daeun <74234333+punchdrunkard@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:41:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AA=A8=EB=93=A0=20=ED=8E=98=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EB=B2=8C=20id=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FestivalController.java | 11 +++++++++++ .../repository/FestivalRepository.java | 6 ++++++ .../festival/service/FestivalService.java | 5 +++++ src/main/resources/application-local.yml | 4 ++-- .../festival/service/FestivalServiceTest.java | 19 +++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/odiga/fiesta/festival/controller/FestivalController.java b/src/main/java/com/odiga/fiesta/festival/controller/FestivalController.java index fd66dbed..1e9f72d3 100644 --- a/src/main/java/com/odiga/fiesta/festival/controller/FestivalController.java +++ b/src/main/java/com/odiga/fiesta/festival/controller/FestivalController.java @@ -71,6 +71,17 @@ public class FestivalController { private final FestivalService festivalService; private final FestivalBookmarkService festivalBookmarkService; + @Operation( + summary = "모든 페스티벌의 id 조회", + description = "DB에 존재하는 모든 페스티벌의 id를 조회합니다." + ) + @GetMapping("/id") + public ResponseEntity>> getAllFestivalIds() { + String message = "페스티벌 id 조회 성공"; + final List response = festivalService.getAllFestivalIds(); + return ResponseEntity.ok(BasicResponse.ok(message, response)); + } + @Operation( summary = "페스티벌 생성", description = "페스티벌을 생성합니다." diff --git a/src/main/java/com/odiga/fiesta/festival/repository/FestivalRepository.java b/src/main/java/com/odiga/fiesta/festival/repository/FestivalRepository.java index 6c631d70..b8365e44 100644 --- a/src/main/java/com/odiga/fiesta/festival/repository/FestivalRepository.java +++ b/src/main/java/com/odiga/fiesta/festival/repository/FestivalRepository.java @@ -1,10 +1,16 @@ package com.odiga.fiesta.festival.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.odiga.fiesta.festival.domain.Festival; public interface FestivalRepository extends JpaRepository , FestivalCustomRepository { boolean existsByUserId(long userId); + + @Query("SELECT f.id FROM Festival f") + List findAllFestivalIds(); } diff --git a/src/main/java/com/odiga/fiesta/festival/service/FestivalService.java b/src/main/java/com/odiga/fiesta/festival/service/FestivalService.java index 04be7742..81fd4d07 100644 --- a/src/main/java/com/odiga/fiesta/festival/service/FestivalService.java +++ b/src/main/java/com/odiga/fiesta/festival/service/FestivalService.java @@ -359,6 +359,10 @@ public FestivalModificationResponse createFestivalRequest(User user, Long festiv .build(); } + public List getAllFestivalIds() { + return festivalRepository.findAllFestivalIds(); + } + // 필터링을 위해, request list 내부의 중복 제거 private FestivalFilterCondition getFestivalFilterCondition(FestivalFilterRequest festivalFilterRequest) { Optional.ofNullable(festivalFilterRequest.getMonths()) @@ -506,4 +510,5 @@ private void validateFileExtension(List files) { } } + } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 6fb10815..87247932 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,7 +1,7 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - username: admin + username: root password: fiesta123 url: jdbc:mysql://localhost:3306/fiesta jpa: @@ -19,4 +19,4 @@ spring: data: redis: host: localhost - port: 6379 \ No newline at end of file + port: 6379 diff --git a/src/test/java/com/odiga/fiesta/festival/service/FestivalServiceTest.java b/src/test/java/com/odiga/fiesta/festival/service/FestivalServiceTest.java index e417bdfb..564e93fc 100644 --- a/src/test/java/com/odiga/fiesta/festival/service/FestivalServiceTest.java +++ b/src/test/java/com/odiga/fiesta/festival/service/FestivalServiceTest.java @@ -939,6 +939,25 @@ void findBookmarkedFestivals_Success() { assertThat(bookmarkedFestivals.getTotalElements()).isEqualTo(bookmarkedFestivalCount); } + @DisplayName("페스티벌 id조회 - DB에 저장된 모든 페스티벌의 id를 조회한다.") + @Test + void getAllFestivalIds() { + // given + Festival festival1 = createFestival(); + Festival festival2 = createFestival(); + Festival festival3 = createFestival(); + Festival festival4 = createFestival(); + Festival festival5 = createFestival(); + + festivalRepository.saveAll(List.of(festival1, festival2, festival3, festival4, festival5)); + + // when + List festivalIds = festivalService.getAllFestivalIds(); + + // then + assertThat(festivalIds).hasSize(5); + } + private static FestivalImage createFestivalImage(Festival festival) { return FestivalImage.builder().festivalId(festival.getId()).imageUrl("imageUrl1").build(); }