-
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
[FEAT] 예약 취소 요청 구현 #42
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c886a62
[FEAT] ReservationCancelReason 엔티티 구현
sung-silver 2b11016
[FEAT] cancelReservation() 구현
sung-silver 0943378
[FEAT] ReservationCancelReason 엔티티에 빌더패턴 구현
sung-silver e247853
[ADD] ReservationCancelRequestDTO 추가
sung-silver 012a9b6
[ADD] ReservationIdResponseDTO 추가
sung-silver 3c9596d
[ADD] ReservationCancelReasonRepository 추가
sung-silver c06188b
[FEAT] 예약 취소 서비스 구현
sung-silver 05a9015
[ADD] 예약 취소 성공 타입 추가
sung-silver f1847dd
[FEAT] 예약 취소 컨트롤러 구현
sung-silver 184d099
[FEAT] ReservationCancelService에 트랜잭션 적용
sung-silver 52b37f8
[ADD] favicon 경로 수정
sung-silver 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
4 changes: 4 additions & 0 deletions
4
...SMWU/CarryUsServer/domain/reservation/controller/request/ReservationCancelRequestDTO.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,4 @@ | ||
package com.SMWU.CarryUsServer.domain.reservation.controller.request; | ||
|
||
public record ReservationCancelRequestDTO(long reservationId, String cancelReason) { | ||
} |
7 changes: 7 additions & 0 deletions
7
...m/SMWU/CarryUsServer/domain/reservation/controller/response/ReservationIdResponseDTO.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,7 @@ | ||
package com.SMWU.CarryUsServer.domain.reservation.controller.response; | ||
|
||
public record ReservationIdResponseDTO(long reservationId) { | ||
public static ReservationIdResponseDTO of(long reservationId) { | ||
return new ReservationIdResponseDTO(reservationId); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...c/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/ReservationCancelReason.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 com.SMWU.CarryUsServer.domain.reservation.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "RESERVATIONS_CANCEL_REASONS") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class ReservationCancelReason { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long reservationCancelReasonId; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "reservation_id") | ||
private Reservation reservation; | ||
|
||
private String cancelReason; | ||
|
||
@Builder | ||
public ReservationCancelReason(Reservation reservation, String cancelReason) { | ||
this.reservation = reservation; | ||
this.cancelReason = cancelReason; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
...m/SMWU/CarryUsServer/domain/reservation/repository/ReservationCancelReasonRepository.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,7 @@ | ||
package com.SMWU.CarryUsServer.domain.reservation.repository; | ||
|
||
import com.SMWU.CarryUsServer.domain.reservation.entity.ReservationCancelReason; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReservationCancelReasonRepository extends JpaRepository<ReservationCancelReason, Long>{ | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/com/SMWU/CarryUsServer/domain/reservation/service/ReservationCancelService.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,34 @@ | ||
package com.SMWU.CarryUsServer.domain.reservation.service; | ||
|
||
import com.SMWU.CarryUsServer.domain.reservation.controller.request.ReservationCancelRequestDTO; | ||
import com.SMWU.CarryUsServer.domain.reservation.controller.response.ReservationIdResponseDTO; | ||
import com.SMWU.CarryUsServer.domain.reservation.entity.Reservation; | ||
import com.SMWU.CarryUsServer.domain.reservation.entity.ReservationCancelReason; | ||
import com.SMWU.CarryUsServer.domain.reservation.exception.ReservationException; | ||
import com.SMWU.CarryUsServer.domain.reservation.repository.ReservationCancelReasonRepository; | ||
import com.SMWU.CarryUsServer.domain.reservation.repository.ReservationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.SMWU.CarryUsServer.domain.reservation.exception.ReservationExceptionType.NOT_FOUND_RESERVATION; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ReservationCancelService { | ||
private final ReservationCancelReasonRepository reservationCancelReasonRepository; | ||
private final ReservationRepository reservationRepository; | ||
|
||
@Transactional | ||
public ReservationIdResponseDTO cancelReservation(final ReservationCancelRequestDTO request) { | ||
final Reservation reservation = reservationRepository.findById(request.reservationId()).orElseThrow(() -> new ReservationException(NOT_FOUND_RESERVATION)); | ||
reservation.cancelReservation(); | ||
final ReservationCancelReason reservationCancelReason = ReservationCancelReason.builder() | ||
.reservation(reservation) | ||
.cancelReason(request.cancelReason()) | ||
.build(); | ||
reservationCancelReasonRepository.save(reservationCancelReason); | ||
return ReservationIdResponseDTO.of(reservation.getReservationId()); | ||
} | ||
} |
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.
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.
SUCCESS_GET_MEMBER_DEFAULT_RESERVATION
SUCCESS_CANCLE_RESERVATION
이런 변수명은 어떤지,,(사실 취향 차이같아요 ㅋㅋ) 보다보니 궁금한 게 회원 기본 예약 정보 조회와 예약 취소 성공은 같이 상태 구분에 쓰이는 케이스가 아니고 그냥 단지 성공했다는 공통점만 존재하는 것 같은데 왜 enum 클래스로 묶으신 건지 궁금해요.
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.
SuccessType을 구현하는 클래스로 따로 만든 이유는 HttpStatus가 달라질 수도 있기 때문입니다!! 같은 성공이더라고 httpstatus가 달라질 수 있거든요! 대부분 200 OK와 201 created로 지정해서 더욱 중복되어 보이는 것 같긴합니다 ㅎㅎ 변수명은 다른 패키지의 SuccessType과 ExceptionType 모두 한번 리팩토링 진행하면서 통일하겠습니다!