-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 공연 : 공연 목록 및 상세 조회 기능 구현 #28
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
Open
boogiewooki02
wants to merge
3
commits into
main
Choose a base branch
from
feat/performance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
festival-app/backend/src/main/java/com/festivalapp/api/PerformanceController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.festivalapp.api; | ||
|
|
||
| import com.festivalapp.dto.PerformanceResponse; | ||
| import com.festivalapp.service.PerformanceService; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/performances") | ||
| @RequiredArgsConstructor | ||
| public class PerformanceController { | ||
|
|
||
| private final PerformanceService performanceService; | ||
|
|
||
| @GetMapping | ||
| ResponseEntity<List<PerformanceResponse>> getPerformances() { | ||
| return ResponseEntity.ok(performanceService.getPerformances()); | ||
| } | ||
|
|
||
| @GetMapping("/{performanceId}") | ||
| ResponseEntity<PerformanceResponse> getPerformance(@PathVariable Long performanceId) { | ||
| return ResponseEntity.ok(performanceService.getPerformance(performanceId)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
festival-app/backend/src/main/java/com/festivalapp/domain/performance/Performance.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.festivalapp.domain.performance; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record Performance( | ||
| Long id, | ||
| String title, | ||
| String artist, | ||
| LocalDateTime startsAt, | ||
| LocalDateTime endsAt, | ||
| String location, | ||
| String description, | ||
| int totalSeats, | ||
| int reservedSeats) { | ||
|
|
||
| public int remainingSeats() { | ||
| return Math.max(totalSeats - reservedSeats, 0); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
festival-app/backend/src/main/java/com/festivalapp/dto/PerformanceResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.festivalapp.dto; | ||
|
|
||
| import com.festivalapp.domain.performance.Performance; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| public record PerformanceResponse( | ||
| Long id, | ||
| String title, | ||
| String artist, | ||
| LocalDateTime startsAt, | ||
| LocalDateTime endsAt, | ||
| String location, | ||
| String description, | ||
| int totalSeats, | ||
| int reservedSeats, | ||
| int remainingSeats) { | ||
|
|
||
| public static PerformanceResponse from(Performance performance) { | ||
| return new PerformanceResponse( | ||
| performance.id(), | ||
| performance.title(), | ||
| performance.artist(), | ||
| performance.startsAt(), | ||
| performance.endsAt(), | ||
| performance.location(), | ||
| performance.description(), | ||
| performance.totalSeats(), | ||
| performance.reservedSeats(), | ||
| performance.remainingSeats()); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...p/backend/src/main/java/com/festivalapp/repository/performance/PerformanceRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.festivalapp.repository.performance; | ||
|
|
||
| import com.festivalapp.domain.performance.Performance; | ||
| import com.festivalapp.repository.performance.datasource.PerformanceDataSource; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class PerformanceRepository { | ||
|
|
||
| private final PerformanceDataSource performanceDataSource; | ||
|
|
||
| public List<Performance> findAll() { | ||
| return performanceDataSource.findAll().stream() | ||
| .sorted(Comparator.comparing(Performance::startsAt)) | ||
| .toList(); | ||
| } | ||
|
|
||
| public Optional<Performance> findById(Long performanceId) { | ||
| return performanceDataSource.findAll().stream() | ||
| .filter(performance -> performance.id().equals(performanceId)) | ||
| .findFirst(); | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
...java/com/festivalapp/repository/performance/datasource/InMemoryPerformanceDataSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package com.festivalapp.repository.performance.datasource; | ||
|
|
||
| import com.festivalapp.domain.performance.Performance; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class InMemoryPerformanceDataSource implements PerformanceDataSource { | ||
|
|
||
| private final List<Performance> performances = | ||
| List.of( | ||
| performance( | ||
| 1L, | ||
| "와우 스테이지 헤드라이너", | ||
| "헤드라이너 아티스트", | ||
| 2026, | ||
| 5, | ||
| 13, | ||
| 19, | ||
| 0, | ||
| 21, | ||
| 0, | ||
| "대운동장 메인 스테이지", | ||
| "축제 첫날 밤을 여는 메인 스테이지 공연입니다.", | ||
| 500, | ||
| 372), | ||
| performance( | ||
| 2L, | ||
| "동아리 밴드 쇼케이스", | ||
| "학생 밴드 연합", | ||
| 2026, | ||
| 5, | ||
| 14, | ||
| 18, | ||
| 0, | ||
| 19, | ||
| 30, | ||
| "학생회관 야외무대", | ||
| "교내 밴드 동아리들이 준비한 라이브 쇼케이스입니다.", | ||
| 220, | ||
| 156), | ||
| performance( | ||
| 3L, | ||
| "WOW DJ Festival", | ||
| "WOW DJ Crew", | ||
| 2026, | ||
| 5, | ||
| 15, | ||
| 20, | ||
| 0, | ||
| 23, | ||
| 30, | ||
| "운동장 DJ 스테이지", | ||
| "축제 마지막 밤을 채우는 DJ 페스티벌 공연입니다.", | ||
| 800, | ||
| 615)); | ||
|
|
||
| @Override | ||
| public List<Performance> findAll() { | ||
| return performances; | ||
| } | ||
|
|
||
| private static Performance performance( | ||
| Long id, | ||
| String title, | ||
| String artist, | ||
| int year, | ||
| int month, | ||
| int day, | ||
| int startHour, | ||
| int startMinute, | ||
| int endHour, | ||
| int endMinute, | ||
| String location, | ||
| String description, | ||
| int totalSeats, | ||
| int reservedSeats) { | ||
| return new Performance( | ||
| id, | ||
| title, | ||
| artist, | ||
| LocalDateTime.of(year, month, day, startHour, startMinute), | ||
| LocalDateTime.of(year, month, day, endHour, endMinute), | ||
| location, | ||
| description, | ||
| totalSeats, | ||
| reservedSeats); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...rc/main/java/com/festivalapp/repository/performance/datasource/PerformanceDataSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.festivalapp.repository.performance.datasource; | ||
|
|
||
| import com.festivalapp.domain.performance.Performance; | ||
| import java.util.List; | ||
|
|
||
| public interface PerformanceDataSource { | ||
|
|
||
| List<Performance> findAll(); | ||
| } |
28 changes: 28 additions & 0 deletions
28
festival-app/backend/src/main/java/com/festivalapp/service/PerformanceService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.festivalapp.service; | ||
|
|
||
| import com.festivalapp.dto.PerformanceResponse; | ||
| import com.festivalapp.repository.performance.PerformanceRepository; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.server.ResponseStatusException; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PerformanceService { | ||
|
|
||
| private final PerformanceRepository performanceRepository; | ||
|
|
||
| public List<PerformanceResponse> getPerformances() { | ||
| return performanceRepository.findAll().stream() | ||
| .map(PerformanceResponse::from) | ||
| .toList(); | ||
| } | ||
|
|
||
| public PerformanceResponse getPerformance(Long performanceId) { | ||
| return performanceRepository.findById(performanceId) | ||
| .map(PerformanceResponse::from) | ||
| .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "공연을 찾을 수 없습니다.")); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
festival-app/backend/src/test/java/com/festivalapp/api/PerformanceControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.festivalapp.api; | ||
|
|
||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import com.festivalapp.dto.PerformanceResponse; | ||
| import com.festivalapp.service.PerformanceService; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
|
||
| class PerformanceControllerTest { | ||
|
|
||
| private final PerformanceService performanceService = mock(PerformanceService.class); | ||
| private MockMvc mockMvc; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| mockMvc = MockMvcBuilders.standaloneSetup(new PerformanceController(performanceService)).build(); | ||
| } | ||
|
|
||
| @Test | ||
| void getPerformancesReturnsPerformanceSummaries() throws Exception { | ||
| given(performanceService.getPerformances()).willReturn(List.of(performanceResponse())); | ||
|
|
||
| mockMvc.perform(get("/api/performances")) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$[0].title").value("와우 스테이지 헤드라이너")) | ||
| .andExpect(jsonPath("$[0].remainingSeats").value(128)); | ||
| } | ||
|
|
||
| @Test | ||
| void getPerformanceReturnsPerformanceDetail() throws Exception { | ||
| given(performanceService.getPerformance(1L)).willReturn(performanceResponse()); | ||
|
|
||
| mockMvc.perform(get("/api/performances/1")) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.title").value("와우 스테이지 헤드라이너")) | ||
| .andExpect(jsonPath("$.description").value("축제 첫날 밤을 여는 메인 스테이지 공연입니다.")) | ||
| .andExpect(jsonPath("$.remainingSeats").value(128)); | ||
| } | ||
|
|
||
| private PerformanceResponse performanceResponse() { | ||
| return new PerformanceResponse( | ||
| 1L, | ||
| "와우 스테이지 헤드라이너", | ||
| "헤드라이너 아티스트", | ||
| LocalDateTime.of(2026, 5, 13, 19, 0), | ||
| LocalDateTime.of(2026, 5, 13, 21, 0), | ||
| "대운동장 메인 스테이지", | ||
| "축제 첫날 밤을 여는 메인 스테이지 공연입니다.", | ||
| 500, | ||
| 372, | ||
| 128); | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
...ckend/src/test/java/com/festivalapp/repository/performance/PerformanceRepositoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.festivalapp.repository.performance; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.festivalapp.domain.performance.Performance; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class PerformanceRepositoryTest { | ||
|
|
||
| @Test | ||
| void findAllReturnsPerformancesSortedByStartTime() { | ||
| Performance latePerformance = | ||
| performance(2L, "늦은 공연", LocalDateTime.of(2026, 5, 14, 20, 0)); | ||
| Performance earlyPerformance = | ||
| performance(1L, "이른 공연", LocalDateTime.of(2026, 5, 14, 18, 0)); | ||
| PerformanceRepository performanceRepository = | ||
| new PerformanceRepository(() -> List.of(latePerformance, earlyPerformance)); | ||
|
|
||
| List<Performance> performances = performanceRepository.findAll(); | ||
|
|
||
| assertThat(performances).containsExactly(earlyPerformance, latePerformance); | ||
| } | ||
|
|
||
| @Test | ||
| void findByIdReturnsMatchingPerformance() { | ||
| Performance performance = | ||
| performance(1L, "와우 스테이지 헤드라이너", LocalDateTime.of(2026, 5, 13, 19, 0)); | ||
| PerformanceRepository performanceRepository = new PerformanceRepository(() -> List.of(performance)); | ||
|
|
||
| assertThat(performanceRepository.findById(1L)).contains(performance); | ||
| assertThat(performanceRepository.findById(999L)).isEmpty(); | ||
| } | ||
|
|
||
| private Performance performance(Long id, String title, LocalDateTime startsAt) { | ||
| return new Performance( | ||
| id, | ||
| title, | ||
| "아티스트", | ||
| startsAt, | ||
| startsAt.plusHours(2), | ||
| "메인무대", | ||
| "공연 설명입니다.", | ||
| 100, | ||
| 40); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중요한 부분은 아니나, 추후 테스트코드를 작성할 때는 @BeforeAll을 이용하여 리소스 낭비를 줄이는 방식으로 해도 좋을 거 같습니다!