Skip to content
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

feat: 모든 페스티벌 id 조회 api 구현 #182

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading