Skip to content
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] verify 요청 반환 response 변경 #135 #136

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.gamja.tiggle.common.BaseException;
import com.gamja.tiggle.common.BaseResponse;
import com.gamja.tiggle.common.BaseResponseStatus;
import com.gamja.tiggle.common.annotation.WebAdapter;
import com.gamja.tiggle.reservation.adapter.in.web.request.VerifySeatRequest;
import com.gamja.tiggle.reservation.adapter.in.web.response.VerifySeatResponse;
import com.gamja.tiggle.reservation.application.port.in.VerifySeatCommand;
import com.gamja.tiggle.reservation.application.port.in.VerifySeatUseCase;
import com.gamja.tiggle.user.domain.CustomUserDetails;
Expand All @@ -25,14 +25,14 @@ public class VerifySeatController {

@PostMapping
@Operation(summary = "좌석 예약 검증", description = "선택한 좌석이 예약 가능한지 검증하는 API 입니다.")
public BaseResponse<Void> verifySeatController(
public BaseResponse<VerifySeatResponse> verifySeatController(
@RequestBody @Valid VerifySeatRequest request,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {

VerifySeatCommand command = from(request,customUserDetails.getUser().getId());
try {
verifySeatUseCase.verifySeat(command);
return new BaseResponse<>(BaseResponseStatus.SUCCESS);
VerifySeatResponse response = verifySeatUseCase.verifySeat(command);
return new BaseResponse<>(response);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
@Getter
@Builder
public class VerifySeatResponse {

private List<Long> seatId;
private Long reservationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ public class SaveReservationAdapter implements SaveReservationPort {
private final ReservationRepository reservationRepository;

@Override
public void save(Reservation reservation) {

public Long save(Reservation reservation) {
ReservationEntity reservationEntity = from(reservation);
reservationRepository.save(reservationEntity);
ReservationEntity savedEntity = reservationRepository.save(reservationEntity);

return savedEntity.getId();
}


private static ReservationEntity from(Reservation reservation) {
return ReservationEntity.builder()
.programEntity(new ProgramEntity(reservation.getProgramId()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.gamja.tiggle.reservation.application.port.in;

import com.gamja.tiggle.common.BaseException;
import com.gamja.tiggle.reservation.adapter.in.web.response.VerifySeatResponse;

import java.util.List;

public interface VerifySeatUseCase {

void verifySeat(VerifySeatCommand command) throws BaseException;
VerifySeatResponse verifySeat(VerifySeatCommand command) throws BaseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public interface SaveReservationPort {

void save(Reservation reservation);
Long save(Reservation reservation);
void update(Reservation reservation);

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

import com.gamja.tiggle.common.BaseException;
import com.gamja.tiggle.common.annotation.UseCase;
import com.gamja.tiggle.reservation.adapter.in.web.response.VerifySeatResponse;
import com.gamja.tiggle.reservation.application.port.in.VerifySeatCommand;
import com.gamja.tiggle.reservation.application.port.in.VerifySeatUseCase;
import com.gamja.tiggle.reservation.application.port.out.SaveReservationPort;
import com.gamja.tiggle.reservation.application.port.out.VerifySeatPort;
import com.gamja.tiggle.reservation.domain.Reservation;
import com.gamja.tiggle.reservation.domain.Seat;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -23,7 +23,7 @@ public class VerifySeatService implements VerifySeatUseCase {
private final SaveReservationPort saveReservationPort;

@Override
public void verifySeat(VerifySeatCommand command) throws BaseException {
public VerifySeatResponse verifySeat(VerifySeatCommand command) throws BaseException {

//좌석 검증
Seat seat = Seat.builder().id(command.getSeatId()).build();
Expand All @@ -33,8 +33,9 @@ public void verifySeat(VerifySeatCommand command) throws BaseException {
//검증했으면 예약 임시 저장
String ticketNumber = getTicketNumber();
Reservation reservation = from(command, ticketNumber);
saveReservationPort.save(reservation);
Long id = saveReservationPort.save(reservation);

return VerifySeatResponse.builder().reservationId(id).build();
}

private static String getTicketNumber() {
Expand Down