-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: 조회 기간에 따른 예매 티켓 조회 API 추가 (#62)
* [chore]: 페이징을 위한 의존성 추가 * [feat]: 예매 조회 controller 추가 * [test]: 예매 조회 인수테스트 추가 * [feat]: 예매 조회 application 추가 * [feat]: 예매 조회 repository, adaptor 추가 * [test]: 예매 조회 jpaRepository 쿼리 테스트 추가 * [refactor]: 예약 도메인 리팩토링 및 도메인 내장함수 추가 * [feat]: 예매 조회 응답 Response 추가 * [refactor]: 예매, 티켓 도메인 리팩토링 및 내장함수 추가 * [feat]: Response 매퍼 추가 * [refactor]: 리팩토링 적용 * [refactor]: 테스트 리팩토링 * [refactor]: 리팩토링
- Loading branch information
1 parent
0213b45
commit 173e415
Showing
14 changed files
with
387 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
39 changes: 39 additions & 0 deletions
39
api/src/main/java/dev/hooon/booking/BookingApiController.java
This file contains 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,39 @@ | ||
package dev.hooon.booking; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import dev.hooon.auth.jwt.JwtAuthorization; | ||
import dev.hooon.booking.application.BookingService; | ||
import dev.hooon.booking.dto.response.BookingListResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class BookingApiController { | ||
|
||
private final BookingService bookingService; | ||
|
||
@GetMapping("/api/users/booking") | ||
@Operation(summary = "예매 조회 API", description = "예매를 조회한다") | ||
@ApiResponse(responseCode = "200", useReturnTypeSchema = true) | ||
public ResponseEntity<BookingListResponse> getBookings( | ||
@Parameter(hidden = true) @JwtAuthorization Long userId, | ||
@RequestParam(name = "duration") int duration, | ||
@PageableDefault(size = 10) Pageable pageable | ||
) { | ||
BookingListResponse bookingListResponse = bookingService.getBookings( | ||
userId, | ||
duration, | ||
pageable | ||
); | ||
return ResponseEntity.ok(bookingListResponse); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
api/src/test/java/dev/hooon/booking/BookingApiControllerTest.java
This file contains 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,98 @@ | ||
package dev.hooon.booking; | ||
|
||
import static org.springframework.http.HttpHeaders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import dev.hooon.common.support.ApiTestSupport; | ||
import dev.hooon.user.domain.entity.User; | ||
|
||
@DisplayName("[BookingApiController API 테스트]") | ||
@Sql("/sql/user_bookings_find.sql") | ||
class BookingApiControllerTest extends ApiTestSupport { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@DisplayName("사용자는 조회 기간에 따른 예매 정보를 조회할 수 있다 - 1") | ||
@Test | ||
void getBookings_test_1() throws Exception { | ||
|
||
// given | ||
User user = new User(); | ||
ReflectionTestUtils.setField(user, "id", 1L); | ||
|
||
// when | ||
ResultActions resultActions = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.get("/api/users/booking?duration=3600&page=0&size=2") | ||
.header(AUTHORIZATION, accessToken) | ||
); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isOk(), | ||
|
||
jsonPath("$.bookingList.length()").value(2), | ||
|
||
jsonPath("$.bookingList[0].bookingId").isNumber(), | ||
jsonPath("$.bookingList[0].bookingDate").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showName").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showDate").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showRound").isNumber(), | ||
jsonPath("$.bookingList[0].showInfo.showRoundStartTime").isString(), | ||
jsonPath("$.bookingList[0].ticketNumber").isNumber(), | ||
jsonPath("$.bookingList[0].currentState").isString(), | ||
|
||
jsonPath("$.bookingList[1].bookingId").isNumber(), | ||
jsonPath("$.bookingList[1].bookingDate").isString(), | ||
jsonPath("$.bookingList[1].showInfo.showName").isString(), | ||
jsonPath("$.bookingList[1].showInfo.showDate").isString(), | ||
jsonPath("$.bookingList[1].showInfo.showRound").isNumber(), | ||
jsonPath("$.bookingList[1].showInfo.showRoundStartTime").isString(), | ||
jsonPath("$.bookingList[1].ticketNumber").isNumber(), | ||
jsonPath("$.bookingList[1].currentState").isString() | ||
); | ||
} | ||
|
||
@DisplayName("사용자는 조회 기간에 따른 예매 정보를 조회할 수 있다 - 2") | ||
@Test | ||
void getBookings_test_2() throws Exception { | ||
|
||
// given | ||
User user = new User(); | ||
ReflectionTestUtils.setField(user, "id", 1L); | ||
|
||
// when | ||
ResultActions resultActions = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.get("/api/users/booking?duration=30&page=0&size=2") | ||
.header(AUTHORIZATION, accessToken) | ||
); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isOk(), | ||
|
||
jsonPath("$.bookingList.length()").value(1), | ||
|
||
jsonPath("$.bookingList[0].bookingId").isNumber(), | ||
jsonPath("$.bookingList[0].bookingDate").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showName").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showDate").isString(), | ||
jsonPath("$.bookingList[0].showInfo.showRound").isNumber(), | ||
jsonPath("$.bookingList[0].showInfo.showRoundStartTime").isString(), | ||
jsonPath("$.bookingList[0].ticketNumber").isNumber(), | ||
jsonPath("$.bookingList[0].currentState").isString() | ||
|
||
); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
8 changes: 8 additions & 0 deletions
8
core/src/main/java/dev/hooon/booking/dto/response/BookingListResponse.java
This file contains 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,8 @@ | ||
package dev.hooon.booking.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record BookingListResponse( | ||
List<BookingResponse> bookingList | ||
) { | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/java/dev/hooon/booking/dto/response/BookingResponse.java
This file contains 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,15 @@ | ||
package dev.hooon.booking.dto.response; | ||
|
||
import java.time.LocalDate; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
public record BookingResponse( | ||
long bookingId, | ||
@JsonFormat(pattern = "yyyy-MM-dd") | ||
LocalDate bookingDate, | ||
ShowInfoResponse showInfo, | ||
int ticketNumber, | ||
String currentState | ||
) { | ||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/java/dev/hooon/booking/dto/response/ShowInfoResponse.java
This file contains 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,16 @@ | ||
package dev.hooon.booking.dto.response; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
public record ShowInfoResponse( | ||
String showName, | ||
@JsonFormat(pattern = "yyyy-MM-dd") | ||
LocalDate showDate, | ||
int showRound, | ||
@JsonFormat(pattern = "HH:mm:ss") | ||
LocalTime showRoundStartTime | ||
) { | ||
} |
Oops, something went wrong.