Skip to content

Commit

Permalink
feat: 모든 페스티벌 id 조회 api 구현 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
punchdrunkard authored Oct 25, 2024
1 parent a068539 commit 466fa46
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicResponse<List<Long>>> getAllFestivalIds() {
String message = "페스티벌 id 조회 성공";
final List<Long> response = festivalService.getAllFestivalIds();
return ResponseEntity.ok(BasicResponse.ok(message, response));
}

@Operation(
summary = "페스티벌 생성",
description = "페스티벌을 생성합니다."
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Festival, Long>
, FestivalCustomRepository {
boolean existsByUserId(long userId);

@Query("SELECT f.id FROM Festival f")
List<Long> findAllFestivalIds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public FestivalModificationResponse createFestivalRequest(User user, Long festiv
.build();
}

public List<Long> getAllFestivalIds() {
return festivalRepository.findAllFestivalIds();
}

// 필터링을 위해, request list 내부의 중복 제거
private FestivalFilterCondition getFestivalFilterCondition(FestivalFilterRequest festivalFilterRequest) {
Optional.ofNullable(festivalFilterRequest.getMonths())
Expand Down Expand Up @@ -506,4 +510,5 @@ private void validateFileExtension(List<MultipartFile> files) {
}
}


}
4 changes: 2 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -19,4 +19,4 @@ spring:
data:
redis:
host: localhost
port: 6379
port: 6379
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> festivalIds = festivalService.getAllFestivalIds();

// then
assertThat(festivalIds).hasSize(5);
}

private static FestivalImage createFestivalImage(Festival festival) {
return FestivalImage.builder().festivalId(festival.getId()).imageUrl("imageUrl1").build();
}
Expand Down

0 comments on commit 466fa46

Please sign in to comment.