diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/ReservationController.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/ReservationController.java index abf9ce0..64425f0 100644 --- a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/ReservationController.java +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/ReservationController.java @@ -2,9 +2,12 @@ import com.SMWU.CarryUsServer.domain.member.entity.Member; import com.SMWU.CarryUsServer.domain.member.service.MemberService; +import com.SMWU.CarryUsServer.domain.reservation.controller.request.ReservationCancelRequestDTO; import com.SMWU.CarryUsServer.domain.reservation.controller.request.ReviewCreateRequestDTO; import com.SMWU.CarryUsServer.domain.reservation.controller.response.MemberReservationDefaultInfoResponseDTO; +import com.SMWU.CarryUsServer.domain.reservation.controller.response.ReservationIdResponseDTO; import com.SMWU.CarryUsServer.domain.reservation.controller.response.ReviewIdResponseDTO; +import com.SMWU.CarryUsServer.domain.reservation.service.ReservationCancelService; import com.SMWU.CarryUsServer.domain.reservation.service.ReservationReviewService; import com.SMWU.CarryUsServer.global.response.SuccessResponse; import com.SMWU.CarryUsServer.global.security.AuthMember; @@ -12,6 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import static com.SMWU.CarryUsServer.domain.reservation.exception.ReservationSuccessType.RESERVATION_CANCEL_SUCCESS; import static com.SMWU.CarryUsServer.domain.reservation.exception.ReservationSuccessType.RESERVATION_MEMBER_DEFAULT_INFO_GET_SUCCESS; import static com.SMWU.CarryUsServer.domain.reservation.exception.ReviewSuccessType.REVIEW_CREATE_SUCCESS; @@ -21,6 +25,7 @@ public class ReservationController { private final ReservationReviewService reservationReviewService; private final MemberService memberService; + private final ReservationCancelService reservationCancelService; @PostMapping("/{reservationId}/review") public ResponseEntity> createReview(@PathVariable("reservationId") final Long reservationId, @RequestBody final ReviewCreateRequestDTO requestDTO, @AuthMember final Member member) { @@ -33,4 +38,10 @@ public ResponseEntity> final MemberReservationDefaultInfoResponseDTO responseDTO = memberService.getMemberReservationDefaultInfo(member); return ResponseEntity.ok(SuccessResponse.of(RESERVATION_MEMBER_DEFAULT_INFO_GET_SUCCESS, responseDTO)); } + + @PostMapping("") + public ResponseEntity> cancelReservation(@RequestBody final ReservationCancelRequestDTO request) { + final ReservationIdResponseDTO responseDTO = reservationCancelService.cancelReservation(request); + return ResponseEntity.ok(SuccessResponse.of(RESERVATION_CANCEL_SUCCESS, responseDTO)); + } } diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/request/ReservationCancelRequestDTO.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/request/ReservationCancelRequestDTO.java new file mode 100644 index 0000000..5cd9f3f --- /dev/null +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/request/ReservationCancelRequestDTO.java @@ -0,0 +1,4 @@ +package com.SMWU.CarryUsServer.domain.reservation.controller.request; + +public record ReservationCancelRequestDTO(long reservationId, String cancelReason) { +} diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/response/ReservationIdResponseDTO.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/response/ReservationIdResponseDTO.java new file mode 100644 index 0000000..2ef6e1a --- /dev/null +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/controller/response/ReservationIdResponseDTO.java @@ -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); + } +} diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/Reservation.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/Reservation.java index 9f5cdc2..99cd08d 100644 --- a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/Reservation.java +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/Reservation.java @@ -46,4 +46,8 @@ public String getReservationInfo(){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm 예약"); return reservationStartTime.format(formatter); } + + public void cancelReservation(){ + this.reservationType = ReservationType.CANCELED; + } } diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/ReservationCancelReason.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/ReservationCancelReason.java new file mode 100644 index 0000000..d78f002 --- /dev/null +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/entity/ReservationCancelReason.java @@ -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; + } +} diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/exception/ReservationSuccessType.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/exception/ReservationSuccessType.java index 37486d7..7453d84 100644 --- a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/exception/ReservationSuccessType.java +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/exception/ReservationSuccessType.java @@ -6,7 +6,8 @@ @RequiredArgsConstructor public enum ReservationSuccessType implements SuccessType { - RESERVATION_MEMBER_DEFAULT_INFO_GET_SUCCESS(HttpStatus.OK, "회원의 기본 예약 정보 조회에 성공하였습니다."); + RESERVATION_MEMBER_DEFAULT_INFO_GET_SUCCESS(HttpStatus.OK, "회원의 기본 예약 정보 조회에 성공하였습니다."), + RESERVATION_CANCEL_SUCCESS(HttpStatus.OK, "예약 취소에 성공하였습니다."),; private final HttpStatus status; private final String message; diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/repository/ReservationCancelReasonRepository.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/repository/ReservationCancelReasonRepository.java new file mode 100644 index 0000000..723bc51 --- /dev/null +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/repository/ReservationCancelReasonRepository.java @@ -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{ +} diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/service/ReservationCancelService.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/service/ReservationCancelService.java new file mode 100644 index 0000000..e74fb23 --- /dev/null +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/domain/reservation/service/ReservationCancelService.java @@ -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()); + } +} diff --git a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/global/security/config/SecurityConfig.java b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/global/security/config/SecurityConfig.java index 9e491d5..c24d166 100644 --- a/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/global/security/config/SecurityConfig.java +++ b/CarryUsServer/src/main/java/com/SMWU/CarryUsServer/global/security/config/SecurityConfig.java @@ -24,7 +24,7 @@ public class SecurityConfig { public static final String[] AUTH_WHITELIST = { "/", "/error", - "/favicon.ico", + "/favicon.ico.", "/actuator/health", "/check/profile" };