-
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 application layer 구현 (#32)
* feat: ValidationException 정의 * fix: User 엔티티 기본 생성자 public 으로 전환 * feat: WaitingBookingErrorCode 정의 * feat: WaitingBooking 생성로직 구현 * feat: 예매대기 등록 API 요청, 응답 DTO 구현 * feat: 예매대기 엔티티 생성 서비스로직 구현 * feat: 예매대기 등록 퍼사드로직 구현
- Loading branch information
1 parent
ea02a5f
commit 20fb2e4
Showing
13 changed files
with
390 additions
and
9 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
14 changes: 14 additions & 0 deletions
14
core/src/main/java/dev/hooon/common/exception/ValidationException.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,14 @@ | ||
package dev.hooon.common.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ValidationException extends RuntimeException { | ||
|
||
private final String code; | ||
|
||
public ValidationException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.code = errorCode.getCode(); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
core/src/main/java/dev/hooon/waitingbooking/application/WaitingBookingService.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,23 @@ | ||
package dev.hooon.waitingbooking.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
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; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WaitingBookingService { | ||
|
||
private final WaitingBookingRepository waitingBookingRepository; | ||
|
||
public WaitingBooking createWaitingBooking(User user, WaitingRegisterRequest request) { | ||
WaitingBooking waitingBooking = WaitingBooking.of(user, request.seatCount(), request.seatIds()); | ||
waitingBookingRepository.save(waitingBooking); | ||
|
||
return waitingBooking; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/main/java/dev/hooon/waitingbooking/application/facade/WaitingBookingFacade.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,26 @@ | ||
package dev.hooon.waitingbooking.application.facade; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import dev.hooon.user.application.UserService; | ||
import dev.hooon.user.domain.entity.User; | ||
import dev.hooon.waitingbooking.application.WaitingBookingService; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingBooking; | ||
import dev.hooon.waitingbooking.dto.request.WaitingRegisterRequest; | ||
import dev.hooon.waitingbooking.dto.response.WaitingRegisterResponse; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class WaitingBookingFacade { | ||
|
||
private final WaitingBookingService waitingBookingService; | ||
private final UserService userService; | ||
|
||
public WaitingRegisterResponse registerWaitingBooking(Long userId, WaitingRegisterRequest request) { | ||
User user = userService.getUserById(userId); | ||
WaitingBooking waitingBooking = waitingBookingService.createWaitingBooking(user, request); | ||
|
||
return new WaitingRegisterResponse(waitingBooking.getId()); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
core/src/main/java/dev/hooon/waitingbooking/dto/request/WaitingRegisterRequest.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,9 @@ | ||
package dev.hooon.waitingbooking.dto.request; | ||
|
||
import java.util.List; | ||
|
||
public record WaitingRegisterRequest( | ||
int seatCount, | ||
List<Long> seatIds | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/dev/hooon/waitingbooking/dto/response/WaitingRegisterResponse.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,6 @@ | ||
package dev.hooon.waitingbooking.dto.response; | ||
|
||
public record WaitingRegisterResponse( | ||
Long waitingBookingId | ||
) { | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/java/dev/hooon/waitingbooking/exception/WaitingBookingErrorCode.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,17 @@ | ||
package dev.hooon.waitingbooking.exception; | ||
|
||
import dev.hooon.common.exception.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum WaitingBookingErrorCode implements ErrorCode { | ||
|
||
INVALID_SEAT_COUNT("좌석 개수는 1~3 개 내로 선택해야합니다", "W_001"), | ||
EMPTY_SELECTED_SEAT("좌석은 반드시 1개 이상 선택해야합니다", "W_002"), | ||
INVALID_SELECTED_SEAT_COUNT("좌석은 선택한 좌석 개수에서 10배수 까지 선택 가능합니다", "W_003"); | ||
|
||
private final String message; | ||
private final String code; | ||
} |
58 changes: 58 additions & 0 deletions
58
core/src/test/java/dev/hooon/waitingbooking/application/WaitingBookingServiceTest.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,58 @@ | ||
package dev.hooon.waitingbooking.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import dev.hooon.user.domain.entity.User; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingBooking; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingBookingSeat; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingStatus; | ||
import dev.hooon.waitingbooking.domain.repository.WaitingBookingRepository; | ||
import dev.hooon.waitingbooking.dto.request.WaitingRegisterRequest; | ||
|
||
@DisplayName("[WaitingBookingService 테스트]") | ||
@ExtendWith(MockitoExtension.class) | ||
class WaitingBookingServiceTest { | ||
|
||
@InjectMocks | ||
private WaitingBookingService waitingBookingService; | ||
@Mock | ||
private WaitingBookingRepository waitingBookingRepository; | ||
|
||
@Test | ||
@DisplayName("[WaitingBooking 을 생성하고 응답한다]") | ||
void createWaitingBookingTest() { | ||
//given | ||
int seatCount = 2; | ||
List<Long> seatIds = List.of(1L, 2L, 3L); | ||
WaitingRegisterRequest request = new WaitingRegisterRequest(seatCount, seatIds); | ||
User user = new User(); | ||
|
||
//when | ||
WaitingBooking result = waitingBookingService.createWaitingBooking(user, request); | ||
|
||
//then | ||
assertAll( | ||
() -> assertThat(result.getSeatCount()).isEqualTo(seatCount), | ||
() -> assertThat(result.getStatus()).isEqualTo(WaitingStatus.WAITING), | ||
() -> assertThat(result.getUser()).isEqualTo(user), | ||
() -> { | ||
List<Long> actualSeatIds = result.getWaitingBookingSeats().stream() | ||
.map(WaitingBookingSeat::getSeatId) | ||
.toList(); | ||
assertThat(actualSeatIds) | ||
.hasSameSizeAs(seatIds) | ||
.containsAll(seatIds); | ||
} | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
core/src/test/java/dev/hooon/waitingbooking/application/facade/WaitingBookingFacadeTest.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,53 @@ | ||
package dev.hooon.waitingbooking.application.facade; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import dev.hooon.user.application.UserService; | ||
import dev.hooon.user.domain.entity.User; | ||
import dev.hooon.waitingbooking.application.WaitingBookingService; | ||
import dev.hooon.waitingbooking.domain.entity.WaitingBooking; | ||
import dev.hooon.waitingbooking.dto.request.WaitingRegisterRequest; | ||
import dev.hooon.waitingbooking.dto.response.WaitingRegisterResponse; | ||
|
||
@DisplayName("[WaitingBookingFacade 테스트]") | ||
@ExtendWith(MockitoExtension.class) | ||
class WaitingBookingFacadeTest { | ||
|
||
@InjectMocks | ||
private WaitingBookingFacade waitingBookingFacade; | ||
@Mock | ||
private WaitingBookingService waitingBookingService; | ||
@Mock | ||
private UserService userService; | ||
|
||
@Test | ||
void registerWaitingBookingTest() { | ||
//given | ||
User user = new User(); | ||
WaitingRegisterRequest request = new WaitingRegisterRequest(3, List.of(1L, 2L, 3L)); | ||
WaitingBooking waitingBooking = WaitingBooking.of(user, request.seatCount(), request.seatIds()); | ||
// 테스트하는 로직에 waitingBooking 의 ID 가 필요하기 때문에 리플렉션으로 주입 | ||
ReflectionTestUtils.setField(waitingBooking, "id", 1L); | ||
|
||
given(userService.getUserById(1L)).willReturn(user); | ||
given(waitingBookingService.createWaitingBooking(user, request)) | ||
.willReturn(waitingBooking); | ||
|
||
//when | ||
WaitingRegisterResponse result = waitingBookingFacade.registerWaitingBooking(1L, request); | ||
|
||
//then | ||
assertThat(result.waitingBookingId()).isEqualTo(1L); | ||
} | ||
} |
Oops, something went wrong.