Skip to content

Commit

Permalink
유저와 사장님 날짜 예약 조회 반환값을 변경한다. (#183)
Browse files Browse the repository at this point in the history
* chore : not null 제거

* feat: 상품 ID , 날짜로 예약 조회

* feat: 사장님 상품id, 날짜로 예약 조회

* chore : Response Type 수정

* chore : swagger Scheme 변경

* refactor : uesr , shop owner 날짜로 예약 조회 반환값 변경

* docs : @Schema로 설명 추가
  • Loading branch information
hyunw9 authored Dec 1, 2023
1 parent a5883fc commit 59d8a28
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.shallwe.domain.reservation.application;

import com.shallwe.domain.reservation.dto.ReservationResponse;
import com.shallwe.domain.reservation.dto.ReservationIdOwnerRes;
import com.shallwe.domain.reservation.dto.ReservationIdUserRes;
import com.shallwe.global.config.security.token.UserPrincipal;
import java.time.LocalDate;
import java.util.List;

public interface ReservationService {

List<ReservationResponse> getReservationByDate (UserPrincipal userPrincipal, Long giftId, LocalDate date);

List<ReservationIdOwnerRes> getReservationByDateOwner (UserPrincipal userPrincipal, Long giftId, LocalDate date);
List<ReservationIdUserRes> getReservationByDateUser (UserPrincipal userPrincipal, Long giftId, LocalDate date);


}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.shallwe.domain.reservation.domain.ReservationStatus;
import com.shallwe.domain.reservation.domain.repository.ReservationRepository;
import com.shallwe.domain.reservation.dto.DeleteReservationRes;
import com.shallwe.domain.reservation.dto.ReservationIdOwnerRes;
import com.shallwe.domain.reservation.dto.ReservationIdUserRes;
import com.shallwe.domain.reservation.dto.ReservationRequest;
import com.shallwe.domain.reservation.dto.ReservationResponse;
import com.shallwe.domain.reservation.dto.ReservationUserReq;
Expand All @@ -36,7 +38,7 @@
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class ReservationServiceImpl implements ReservationService{
public class ReservationServiceImpl implements ReservationService {

private final ReservationRepository reservationRepository;
private final ExperienceGiftRepository experienceGiftRepository;
Expand All @@ -58,18 +60,32 @@ public List<ValidTimeSlotRes> getValidReservationTime(UserPrincipal userPrincipa
.build()).toList();
}

public List<ReservationResponse> getReservationByDate(UserPrincipal userPrincipal, Long giftId, LocalDate date){
public List<ReservationIdUserRes> getReservationByDateUser(UserPrincipal userPrincipal, Long giftId,
LocalDate date) {
ExperienceGift experienceGift = experienceGiftRepository.findById(giftId)
.orElseThrow(ExperienceGiftNotFoundException::new);

List<Reservation> reservations = reservationRepository.findAllByExperienceGiftAndDate(experienceGift,date)
List<Reservation> reservations = reservationRepository.findAllByExperienceGiftAndDate(
experienceGift, date)
.orElseThrow(InvalidReservationException::new);

return reservations.stream()
.map(ReservationResponse::toDtoUser)
.collect(Collectors.toList());
return reservations.stream()
.map(ReservationIdUserRes::toDtoUser)
.collect(Collectors.toList());
}

public List<ReservationIdOwnerRes> getReservationByDateOwner(UserPrincipal userPrincipal, Long giftId,
LocalDate date) {
ExperienceGift experienceGift = experienceGiftRepository.findById(giftId)
.orElseThrow(ExperienceGiftNotFoundException::new);

List<Reservation> reservations = reservationRepository.findAllByExperienceGiftAndDate(
experienceGift, date)
.orElseThrow(InvalidReservationException::new);

return reservations.stream()
.map(ReservationIdOwnerRes::toDtoOwner)

@Transactional
public List<ReservationResponse> addOwnerReservation(ReservationRequest reservationRequest,
UserPrincipal userPrincipal) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.shallwe.domain.reservation.dto;



import com.shallwe.domain.reservation.domain.Reservation;
import com.shallwe.domain.reservation.domain.ReservationStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalTime;
import java.util.Optional;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ReservationIdOwnerRes {
@Schema(description = "예약 Id")
Long reservationId;

@Schema(description = "예약 상태 {WAITING(예약대기), BOOKED(예약중), COMFIRMED(예약확정), COMPLETED(이용완료), CANCELED(예약취소)}")
ReservationStatus status;

@Schema(description = "보내는이 이름(예약자)")
String sender;

@Schema(description = "예약 시간")
LocalTime time;

@Schema(description = "전화번호")
String phoneNum;

@Schema(description = "예약 인원")
Long person;

@Builder
public ReservationIdOwnerRes(Long reservationId, ReservationStatus status, String sender,
LocalTime time, String phoneNum,Long person) {
this.reservationId = reservationId;
this.status = status;
this.sender = sender;
this.time = time;
this.phoneNum = phoneNum;
this.person = person;
}

public static ReservationIdOwnerRes toDtoOwner(Reservation reservation) {
return ReservationIdOwnerRes.builder()
.reservationId(reservation.getId())
.status(reservation.getReservationStatus())
.time(reservation.getTime())
.sender(Optional.ofNullable(reservation.getSender()).map(
com.shallwe.domain.user.domain.User::getName).orElse(null))
.phoneNum(reservation.getPhoneNumber())
.person(reservation.getPersons())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.shallwe.domain.reservation.dto;

import com.shallwe.domain.reservation.domain.Reservation;
import com.shallwe.domain.reservation.domain.ReservationStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
public class ReservationIdUserRes {

@Schema(description = "예약 Id")
Long reservationId;

@Schema(description = "예약 상태 {WAITING(예약대기), BOOKED(예약중), COMFIRMED(예약확정), COMPLETED(이용완료), CANCELED(예약취소)}")
ReservationStatus status;

@Builder
public ReservationIdUserRes(Long reservationId, ReservationStatus status) {
this.reservationId = reservationId;
this.status = status;
}

public static ReservationIdUserRes toDtoUser(Reservation reservation){
return ReservationIdUserRes.builder()
.reservationId(reservation.getId())
.status(reservation.getReservationStatus())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static ReservationResponse toDtoUser(Reservation reservation) {
.time(reservation.getTime().toString())
.phoneNumber(Optional.ofNullable(reservation.getPhoneNumber()).orElse(null))
.receiver(Optional.ofNullable(reservation.getReceiver()).map(User::getName).orElse(null))
.invitationImageURL(Optional.ofNullable(reservation.getInvitationImg()).map(AwsS3ImageUrlUtil::toUrl).orElse(null))
.invitationImageURL(
Optional.ofNullable(reservation.getInvitationImg()).map(AwsS3ImageUrlUtil::toUrl)
.orElse(null))
.invitationComment(Optional.ofNullable(reservation.getInvitationComment()).orElse(null))
.reservationStatus(reservation.getReservationStatus());

Expand All @@ -62,4 +64,5 @@ public static ReservationResponse toDtoOwner(Reservation reservation) {

return builder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.shallwe.domain.reservation.application.ReservationServiceImpl;
import com.shallwe.domain.reservation.dto.DeleteReservationRes;
import com.shallwe.domain.reservation.dto.ReservationIdUserRes;
import com.shallwe.domain.reservation.dto.ReservationRequest;
import com.shallwe.domain.reservation.dto.ReservationResponse;
import com.shallwe.domain.reservation.dto.ReservationUserReq;
Expand Down Expand Up @@ -76,17 +77,18 @@ public ResponseCustom<List<ValidTimeSlotRes>> getValidReservations(
@Operation(summary = "날짜로 예약 조회", description = "등록한 상품의 ID와 날짜로 이용 가능한 예약을 조회 합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "상품 예약 조회 성공", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ReservationResponse.class))}),
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = ReservationResponse.class)))}),
@ApiResponse(responseCode = "400", description = "상품 예약 조회 실패", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/date")
public ResponseCustom<List<ReservationResponse>> getReservationWithDate(
public ResponseCustom<List<ReservationIdUserRes>> getReservationWithDate(

@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "상품 ID를 입력해주세요", required = true) @RequestParam Long giftId,
@Parameter(description = "조회하려는 날짜를 입력해주세요 YYYY-MM-DD ", required = true) @RequestParam LocalDate date
) {
return ResponseCustom.OK(reservationServiceimpl.getReservationByDate(userPrincipal, giftId,date));
return ResponseCustom.OK(reservationServiceimpl.getReservationByDateUser(userPrincipal, giftId,date));
}

@Operation(summary = "해당 경험 선물에 생성된 예약 조회 ", description = "경험 ID로 검색")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.shallwe.domain.experiencegift.exception.ExperienceGiftNotFoundException;
import com.shallwe.domain.reservation.domain.Reservation;
import com.shallwe.domain.reservation.domain.repository.ReservationRepository;
import com.shallwe.domain.reservation.dto.ReservationResponse;
import com.shallwe.domain.reservation.dto.ValidTimeSlotRes;
import com.shallwe.domain.reservation.exception.InvalidAvailableTimeException;
import com.shallwe.domain.reservation.exception.InvalidReservationException;
Expand All @@ -24,7 +23,6 @@
import com.shallwe.global.payload.Message;
import jakarta.xml.bind.helpers.ValidationEventLocatorImpl;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
Expand All @@ -41,7 +39,6 @@ public class ShopOwnerServiceImpl implements ShopOwnerService {
private final ReservationRepository reservationRepository;
private final ExperienceGiftRepository experienceGiftRepository;


@Override
@Transactional
public Message deleteCurrentShopOwner(UserPrincipal userPrincipal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@


import com.shallwe.domain.reservation.application.ReservationServiceImpl;
import com.shallwe.domain.reservation.dto.ReservationIdOwnerRes;
import com.shallwe.domain.reservation.dto.ReservationResponse;
import com.shallwe.domain.reservation.dto.ValidTimeSlotRes;
import com.shallwe.domain.shopowner.application.ShopOwnerServiceImpl;
import com.shallwe.domain.shopowner.dto.ShopOwnerGiftManageRes;
import com.shallwe.global.config.security.token.CurrentUser;
import com.shallwe.global.config.security.token.UserPrincipal;
import com.shallwe.global.payload.ErrorResponse;
import com.shallwe.global.payload.Message;
import com.shallwe.global.payload.ResponseCustom;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -64,17 +65,19 @@ public ResponseCustom<List<ValidTimeSlotRes>> getCurrentGiftReservation(
@Operation(summary = "사장 예약 조회", description = "사장이 등록한 상품의 예약을 조회 합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "상품 예약 조회 성공", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ReservationResponse.class))}),
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = ReservationResponse.class)))}),

@ApiResponse(responseCode = "400", description = "상품 예약 조회 실패", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/date")
public ResponseCustom<List<ReservationResponse>> getReservationWithDate(
public ResponseCustom<List<ReservationIdOwnerRes>> getReservationWithDate(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "상품 ID를 입력해주세요", required = true) @RequestParam Long giftId,
@Parameter(description = "조회하려는 날짜를 입력해주세요 YYYY-MM-DD ", required = true) @RequestParam LocalDate date
) {
return ResponseCustom.OK(reservationService.getReservationByDate(userPrincipal, giftId,date));
return ResponseCustom.OK(reservationService.getReservationByDateOwner(userPrincipal, giftId,date));

}

@Operation(summary = "예약 확정", description = "유저 결제 확인 후 예약을 확정상태로 변경합니다.")
Expand Down

0 comments on commit 59d8a28

Please sign in to comment.