-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Refactor] 프로젝트 구조 변경 및 서비스 코드 수정 #14
Merged
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5f749ca
structure: 디렉토리 구조 변경 (도메인별 → 계층별)
uijin31 857b4b0
refactor: UserRepository, PlaceRepository에 대한 제어권을 UserService, Place…
uijin31 056faaa
test: 서비스 분리에 따른 테스트 코드 변경 및 PlaceService, UserService 단위 테스트 작성
uijin31 9b35295
test: BookingServiceTest → BookingServiceUnitTest 클래스명 변경
uijin31 4d29db6
test: verify() 메서드를 통해 메서드 호출 검증 추가
uijin31 2fee9d9
structure: 컨트롤러와 애플리케이션 사이의 Response DTO 위치를 애플리케이션으로 변경
uijin31 b926940
refactor: 생성자 파라미터 순서 변경
uijin31 b0a14e8
feat: Booking 생성자 파라미터 검증 추가
uijin31 e3576c3
feat: 예약 후 상태 반환 메서드를 BookingSlot에서 BookingStatus로 변경
uijin31 20e8bfd
feat: 예약 인원 정보가 없는 경우 1인을 기본값으로 하도록 변경
uijin31 178c452
refactor: 필드를 직접 참조하지 않고, 메서드를 호출하도록 변경
uijin31 0086566
refactor: 오타 수정 (결재 → 결제)
uijin31 5f6b1e2
refactor: 메서드명 변경(getStatusAfterBook → getStatusAfterBooking)
uijin31 00658a0
test: BookingSlot 예약 기능 단위 테스트 작성
uijin31 04a781b
test: BookingStatus.getStatusAfterBooking 메서드 단위 테스트 작성
uijin31 dc3ba58
test: Booking 생성 단위 테스트 작성
uijin31 d6e8029
refactor: if 대신 requireNonNull() 메서드 적용
uijin31 c22a745
refactor: 리소스가 없는 경우 예외 처리 로직을 각 비즈니스에서 해결하도록 변경
uijin31 bdf04f1
refactor: 매직 넘버 제거 (default party size: 1)
uijin31 dd5906a
feat: book() → setBooked() 변경
uijin31 165a746
test: 서비스 코드 변경에 따른 테스트 코드 변경
uijin31 3064e73
style: 스네이크 케이스를 카멜 케이스로 변경
uijin31 df6f8ee
test: 도메인 코드 변경에 따른 테스트 코드 변경
uijin31 3b08999
test: 도메인 코드 변경에 따른 테스트 코드 변경
uijin31 a0642b5
chore: merge main
uijin31 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
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,15 +1,13 @@ | ||
package com.nowait.booking.application; | ||
package com.nowait.application; | ||
|
||
import com.nowait.booking.domain.model.Booking; | ||
import com.nowait.booking.domain.model.BookingSlot; | ||
import com.nowait.booking.domain.repository.BookingRepository; | ||
import com.nowait.booking.domain.repository.BookingSlotRepository; | ||
import com.nowait.booking.dto.TimeSlotDto; | ||
import com.nowait.booking.dto.response.BookingRes; | ||
import com.nowait.booking.dto.response.DailyBookingStatusRes; | ||
import com.nowait.place.domain.repository.PlaceRepository; | ||
import com.nowait.user.domain.repository.UserRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import com.nowait.application.dto.response.booking.BookingRes; | ||
import com.nowait.application.dto.response.booking.DailyBookingStatusRes; | ||
import com.nowait.application.dto.response.booking.TimeSlotDto; | ||
import com.nowait.application.event.BookingEventPublisher; | ||
import com.nowait.domain.model.booking.Booking; | ||
import com.nowait.domain.model.booking.BookingSlot; | ||
import com.nowait.domain.repository.BookingRepository; | ||
import com.nowait.domain.repository.BookingSlotRepository; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
@@ -25,9 +23,9 @@ public class BookingService { | |
|
||
private final BookingSlotRepository bookingSlotRepository; | ||
private final BookingRepository bookingRepository; | ||
private final UserRepository userRepository; | ||
private final PlaceRepository placeRepository; | ||
private final BookingEventPublisher bookingEventPublisher; | ||
private final UserService userService; | ||
private final PlaceService placeService; | ||
|
||
public DailyBookingStatusRes getDailyBookingStatus(Long placeId, LocalDate date) { | ||
List<BookingSlot> bookingSlots = bookingSlotRepository.findAllByPlaceIdAndDate( | ||
|
@@ -45,11 +43,11 @@ public DailyBookingStatusRes getDailyBookingStatus(Long placeId, LocalDate date) | |
@Transactional | ||
public BookingRes book(Long loginId, Long placeId, LocalDate date, LocalTime time, | ||
Integer partySize) { | ||
validateUserExist(loginId, "존재하지 않는 사용자의 요청입니다."); | ||
validatePlaceExist(placeId, "존재하지 않는 식당입니다."); | ||
userService.validateUserExist(loginId, "존재하지 않는 사용자의 요청입니다."); | ||
placeService.validatePlaceExist(placeId, "존재하지 않는 식당입니다."); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the above |
||
BookingSlot slot = findAvailableSlot(placeId, date, time); | ||
Booking booking = bookingRepository.save(Booking.of(loginId, partySize, slot)); | ||
Booking booking = bookingRepository.save(Booking.of(loginId, slot, partySize)); | ||
|
||
bookingEventPublisher.publishBookedEvent(booking, placeId); | ||
|
||
|
@@ -61,18 +59,6 @@ private boolean isAvailable(List<BookingSlot> slots) { | |
return slots.stream().anyMatch(slot -> !slot.isBooked()); | ||
} | ||
|
||
private void validateUserExist(Long userId, String errorMessage) { | ||
if (!userRepository.existsById(userId)) { | ||
throw new EntityNotFoundException(errorMessage); | ||
} | ||
} | ||
|
||
private void validatePlaceExist(Long placeId, String errorMessage) { | ||
if (!placeRepository.existsById(placeId)) { | ||
throw new EntityNotFoundException(errorMessage); | ||
} | ||
} | ||
|
||
private BookingSlot findAvailableSlot(Long placeId, LocalDate date, LocalTime time) { | ||
return bookingSlotRepository.findFirstByPlaceIdAndDateAndTimeAndIsBookedFalse(placeId, date, | ||
time).orElseThrow(() -> new IllegalArgumentException("예약 가능한 테이블이 없습니다.")); | ||
|
21 changes: 21 additions & 0 deletions
21
nowait-api/src/main/java/com/nowait/application/PlaceService.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,21 @@ | ||
package com.nowait.application; | ||
|
||
import com.nowait.domain.repository.PlaceRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class PlaceService { | ||
|
||
private final PlaceRepository placeRepository; | ||
|
||
public void validatePlaceExist(Long placeId, String errorMessage) { | ||
if (!placeRepository.existsById(placeId)) { | ||
throw new EntityNotFoundException(errorMessage); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
nowait-api/src/main/java/com/nowait/application/UserService.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,22 @@ | ||
package com.nowait.application; | ||
|
||
import com.nowait.domain.repository.UserRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public void validateUserExist(Long userId, String errorMessage) { | ||
if (!userRepository.existsById(userId)) { | ||
throw new EntityNotFoundException(errorMessage); | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...it/auth/dto/response/GetLoginPageRes.java → ...on/dto/response/auth/GetLoginPageRes.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
2 changes: 1 addition & 1 deletion
2
...om/nowait/auth/dto/response/LoginRes.java → ...plication/dto/response/auth/LoginRes.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
6 changes: 3 additions & 3 deletions
6
...wait/booking/dto/response/BookingRes.java → ...tion/dto/response/booking/BookingRes.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
3 changes: 1 addition & 2 deletions
3
...g/dto/response/DailyBookingStatusRes.java → ...sponse/booking/DailyBookingStatusRes.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
2 changes: 1 addition & 1 deletion
2
...oking/dto/response/GetBookingInfoRes.java → ...o/response/booking/GetBookingInfoRes.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
2 changes: 1 addition & 1 deletion
2
...oking/dto/response/GetDepositInfoRes.java → ...o/response/booking/GetDepositInfoRes.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
2 changes: 1 addition & 1 deletion
2
...a/com/nowait/booking/dto/TimeSlotDto.java → ...ion/dto/response/booking/TimeSlotDto.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
10 changes: 10 additions & 0 deletions
10
nowait-api/src/main/java/com/nowait/application/dto/response/payment/PayDepositRes.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,10 @@ | ||
package com.nowait.application.dto.response.payment; | ||
|
||
public record PayDepositRes( | ||
Long paymentId, | ||
String paymentStatus, | ||
String paymentMethod, | ||
String url | ||
) { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../com/nowait/common/event/BookedEvent.java → ...nowait/application/event/BookedEvent.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
5 changes: 2 additions & 3 deletions
5
...ng/application/BookingEventPublisher.java → ...lication/event/BookingEventPublisher.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
15 changes: 0 additions & 15 deletions
15
nowait-api/src/main/java/com/nowait/booking/domain/model/BookingStatus.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...a/com/nowait/common/config/JpaConfig.java → ...ain/java/com/nowait/config/JpaConfig.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
10 changes: 5 additions & 5 deletions
10
...ain/java/com/nowait/auth/api/AuthApi.java → ...va/com/nowait/controller/api/AuthApi.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
18 changes: 9 additions & 9 deletions
18
...va/com/nowait/booking/api/BookingApi.java → ...com/nowait/controller/api/BookingApi.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
6 changes: 3 additions & 3 deletions
6
...ait/notification/api/NotificationApi.java → ...owait/controller/api/NotificationApi.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
32 changes: 32 additions & 0 deletions
32
nowait-api/src/main/java/com/nowait/controller/api/PaymentApi.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,32 @@ | ||
package com.nowait.controller.api; | ||
|
||
import com.nowait.application.dto.response.payment.PayDepositRes; | ||
import com.nowait.controller.api.dto.request.PayDepositReq; | ||
import com.nowait.controller.api.dto.response.ApiResult; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/payments") | ||
@RequiredArgsConstructor | ||
public class PaymentApi { | ||
|
||
/** | ||
* 예약금 결제 API | ||
* | ||
* @param request 예약금 결제 요청 | ||
* @return 예약금 결제 결과 | ||
*/ | ||
@PostMapping("/deposit") | ||
public ApiResult<PayDepositRes> payDeposit( | ||
@RequestBody @Valid PayDepositReq request | ||
) { | ||
// TODO: 예약금 결제 비즈니스 로직 호출 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
return ApiResult.ok(null); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...owait/booking/dto/request/BookingReq.java → ...ontroller/api/dto/request/BookingReq.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
10 changes: 10 additions & 0 deletions
10
nowait-api/src/main/java/com/nowait/controller/api/dto/request/PayDepositReq.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,10 @@ | ||
package com.nowait.controller.api.dto.request; | ||
|
||
public record PayDepositReq( | ||
Long bookingId, | ||
String paymentMethod, | ||
Integer amount, | ||
String currency | ||
) { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ait/auth/dto/request/ReissueTokenReq.java → ...ller/api/dto/request/ReissueTokenReq.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
2 changes: 1 addition & 1 deletion
2
...to/request/SetVacancyNotificationReq.java → ...to/request/SetVacancyNotificationReq.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
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
2 changes: 1 addition & 1 deletion
2
...t/common/domain/model/BaseTimeEntity.java → ...m/nowait/domain/model/BaseTimeEntity.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
Oops, something went wrong.
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.
이름이 validateUserExist이니까, errorMessage도 userService가 가지고 있는 것이 더 바람직하지 않을까요? :-)
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.
loginId
를 확인하는 것이면, "존재하지 않는 사용자의 요청입니다"가 필요하고, 다른 서비스에서 사용자를 조회할 때는 "존재하지 않는 예약자입니다" 이런식으로 사용하는 입장에서 다른 에러 메시지를 전달해주고 싶을 것 같다고 생각해서errorMessage
도 매개변수에 포함 시켰습니다!차라리 메서드를 오버로딩 해서 필요할 때만 errorMessage를 추가하도록 하는 것이 나을까요? 아니면 에러 메시지를 구체적으로 내려주지 말고 하나로 통일하는 것이 나을까요..🤔 아니면 혹시 메서드명이 잘못된 것일까요?😅
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.
아, 이해했습니다. 이런 경우라면, vlidateUserExist를 boolean으로 하고, 그걸 받아서 에러를 내보내는 로직을 BookingService에 넣는 것이 더 좋을 것 같다는 생각이 드네요. 😎
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.
c22a745 반영했습니다:)