-
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 Controller 구현 (#40)
* feat: 예매대기 등록 요청 DTO에 검증 어노테이션 추가 * feat: 테스트를 위한 간단한 findAll 쿼리 구현 * feat: 예매대기 등록 API 구현
- Loading branch information
1 parent
3071f17
commit ae05181
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
api/src/main/java/dev/hooon/waitingbooking/WaitingBookingApiController.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,29 @@ | ||
package dev.hooon.waitingbooking; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import dev.hooon.waitingbooking.application.facade.WaitingBookingFacade; | ||
import dev.hooon.waitingbooking.dto.request.WaitingRegisterRequest; | ||
import dev.hooon.waitingbooking.dto.response.WaitingRegisterResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class WaitingBookingApiController { | ||
|
||
private final WaitingBookingFacade waitingBookingFacade; | ||
|
||
@PostMapping("/api/waiting_bookings") | ||
public ResponseEntity<WaitingRegisterResponse> registerWaitingBooking( | ||
@Valid @RequestBody WaitingRegisterRequest request, | ||
@RequestParam Long userId // TODO 추후에 인증정보 ArgumentResolver 가 구현되면 수정 예정 | ||
) { | ||
WaitingRegisterResponse waitingRegisterResponse = waitingBookingFacade.registerWaitingBooking(userId, request); | ||
return ResponseEntity.ok(waitingRegisterResponse); | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
api/src/test/java/dev/hooon/waitingbooking/WaitingBookingApiControllerTest.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,66 @@ | ||
package dev.hooon.waitingbooking; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
import static org.springframework.http.MediaType.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
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.application.UserService; | ||
import dev.hooon.user.domain.entity.User; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingBooking; | ||
import dev.hooon.waitingbooking.domain.repository.WaitingBookingRepository; | ||
import dev.hooon.waitingbooking.dto.request.WaitingRegisterRequest; | ||
|
||
@DisplayName("[WaitingBookingApiController API 테스트]") | ||
class WaitingBookingApiControllerTest extends ApiTestSupport { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@Autowired | ||
private WaitingBookingRepository waitingBookingRepository; | ||
// TODO User 저장에 대한 로직을 다른 작업에서 병행중이어서 일단 모킹으로 대체하구 추후에 수정 | ||
@MockBean | ||
private UserService userService; | ||
|
||
@Test | ||
@DisplayName("[예매대기 등록 API 를 호출하면 예매대기가 등록되고 예매대기 ID 를 응답한다]") | ||
void registerWaitingBookingTest() throws Exception { | ||
//given | ||
// TODO 추후에 User 생성 기능이 구현되면 수정 예정 | ||
User user = new User(); | ||
ReflectionTestUtils.setField(user, "id", 1L); | ||
given(userService.getUserById(1L)).willReturn(user); | ||
|
||
WaitingRegisterRequest waitingRegisterRequest = new WaitingRegisterRequest(2, List.of(1L, 2L, 3L, 4L)); | ||
|
||
//when | ||
ResultActions actions = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.post("/api/waiting_bookings") | ||
.queryParam("userId", "1") // TODO 추후에 인증정보 ArgumentResolver 가 구현되면 수정 예정 | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(waitingRegisterRequest)) | ||
); | ||
|
||
//then | ||
List<WaitingBooking> allWaitingBookings = waitingBookingRepository.findAll(); | ||
assertThat(allWaitingBookings).isNotEmpty(); | ||
|
||
actions.andExpectAll( | ||
status().isOk(), | ||
jsonPath("$.waitingBookingId").value(allWaitingBookings.get(0).getId()) | ||
); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
core/src/main/java/dev/hooon/waitingbooking/domain/repository/WaitingBookingRepository.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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package dev.hooon.waitingbooking.domain.repository; | ||
|
||
import java.util.List; | ||
|
||
import dev.hooon.waitingbooking.domain.entity.WaitingBooking; | ||
|
||
public interface WaitingBookingRepository { | ||
|
||
void save(WaitingBooking waitingBooking); | ||
|
||
List<WaitingBooking> findAll(); | ||
} |
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