-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature: 화면 구현에 필요한 API를 추가 구현한다. #128
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dd5a272
feat: 좌석이 일정 시간 선택되지 않으면 release 해주는 로직 구현
seminchoi ae23686
feat: 본인 티켓 조회 기능 구현
seminchoi 9affd11
fix: 좌석 점유 해제 필드 주입 오류 수정
seminchoi 24d4fb2
docs: 공연 상세 정보 조회 API 문서 작성
seminchoi 2938b81
fix: 테스트 실패 수정
seminchoi 12f4cb6
setting: yml 파일에 좌석 점유 대기 시간 설정 값 추가
seminchoi fce33b3
docs: 좌석 점유 해제 API 문서 작성
seminchoi c37a35e
feat: 좌석 점유 해제 로직 수정
seminchoi e3751e0
fix: 좌석 점유 해제가 아무런 기능을 하지 않는 오류 수정
seminchoi f9ca9b5
fix: 좌석 점유를 바로 해제해서 테스트가 실패하던 것 수정
seminchoi 657a031
refactor: 락에 의해 좌석 점유 실패 시 500이아닌 409 상태코드를 반환하도록 수정
seminchoi 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
Submodule backend-config
updated
from 193789 to a43389
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
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
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
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
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: 18 additions & 0 deletions
18
src/main/java/com/thirdparty/ticketing/domain/ticket/dto/response/TicketSeatDetail.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,18 @@ | ||
package com.thirdparty.ticketing.domain.ticket.dto.response; | ||
|
||
import com.thirdparty.ticketing.domain.seat.Seat; | ||
import com.thirdparty.ticketing.domain.seat.dto.response.SeatGradeElement; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class TicketSeatDetail { | ||
private final long seatId; | ||
private final String seatCode; | ||
private final SeatGradeElement grade; | ||
|
||
public static TicketSeatDetail of(Seat seat) { | ||
return new TicketSeatDetail( | ||
seat.getSeatId(), seat.getSeatCode(), SeatGradeElement.of(seat.getSeatGrade())); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/thirdparty/ticketing/domain/ticket/service/ReservationManager.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,27 @@ | ||
package com.thirdparty.ticketing.domain.ticket.service; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.thirdparty.ticketing.domain.common.ErrorCode; | ||
import com.thirdparty.ticketing.domain.common.TicketingException; | ||
import com.thirdparty.ticketing.domain.member.Member; | ||
import com.thirdparty.ticketing.domain.seat.Seat; | ||
import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ReservationManager { | ||
private final SeatRepository seatRepository; | ||
|
||
@Transactional | ||
public void releaseSeat(Member loginMember, long seatId) { | ||
Seat seat = | ||
seatRepository | ||
.findById(seatId) | ||
.orElseThrow(() -> new TicketingException(ErrorCode.NOT_FOUND_SEAT)); | ||
seat.releaseSeat(loginMember); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package com.thirdparty.ticketing.domain.ticket.service; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.thirdparty.ticketing.domain.common.ErrorCode; | ||
|
@@ -10,9 +16,11 @@ | |
import com.thirdparty.ticketing.domain.payment.PaymentProcessor; | ||
import com.thirdparty.ticketing.domain.payment.dto.PaymentRequest; | ||
import com.thirdparty.ticketing.domain.seat.Seat; | ||
import com.thirdparty.ticketing.domain.ticket.Ticket; | ||
import com.thirdparty.ticketing.domain.ticket.dto.event.PaymentEvent; | ||
import com.thirdparty.ticketing.domain.ticket.dto.request.SeatSelectionRequest; | ||
import com.thirdparty.ticketing.domain.ticket.dto.request.TicketPaymentRequest; | ||
import com.thirdparty.ticketing.domain.ticket.repository.TicketRepository; | ||
import com.thirdparty.ticketing.domain.ticket.service.strategy.LockSeatStrategy; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
@@ -21,11 +29,18 @@ | |
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ReservationTransactionService implements ReservationService { | ||
private final TicketRepository ticketRepository; | ||
private final MemberRepository memberRepository; | ||
private final PaymentProcessor paymentProcessor; | ||
private final LockSeatStrategy lockSeatStrategy; | ||
private final EventPublisher eventPublisher; | ||
|
||
private final ReservationManager reservationManager; | ||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5); | ||
|
||
@Value("${ticketing.reservation.release-delay-seconds}") | ||
private int reservationReleaseDelay; | ||
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. 밖에서 주입하고 final로 선언하는 건 어떤가요? |
||
|
||
@Override | ||
@Transactional | ||
public void selectSeat(String memberEmail, SeatSelectionRequest seatSelectionRequest) { | ||
|
@@ -42,6 +57,21 @@ public void selectSeat(String memberEmail, SeatSelectionRequest seatSelectionReq | |
.orElseThrow(() -> new TicketingException(ErrorCode.NOT_FOUND_MEMBER)); | ||
|
||
seat.assignByMember(member); | ||
scheduler.schedule( | ||
() -> reservationManager.releaseSeat(member, seatId), | ||
reservationReleaseDelay, | ||
TimeUnit.SECONDS); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void releaseSeat(String memberEmail, SeatSelectionRequest seatSelectionRequest) { | ||
Member member = | ||
memberRepository | ||
.findByEmail(memberEmail) | ||
.orElseThrow(() -> new TicketingException(ErrorCode.NOT_FOUND_MEMBER)); | ||
|
||
reservationManager.releaseSeat(member, seatSelectionRequest.getSeatId()); | ||
} | ||
|
||
@Override | ||
|
@@ -60,12 +90,21 @@ public void reservationTicket(String memberEmail, TicketPaymentRequest ticketPay | |
|
||
processPayment(seat, loginMember); | ||
|
||
if (seat.isAssignedByMember(loginMember)) { | ||
throw new TicketingException(ErrorCode.NOT_SELECTABLE_SEAT); | ||
} | ||
Ticket ticket = | ||
Ticket.builder() | ||
.ticketSerialNumber(UUID.randomUUID()) | ||
.seat(seat) | ||
.member(loginMember) | ||
.build(); | ||
|
||
ticketRepository.save(ticket); | ||
} | ||
|
||
private void processPayment(Seat seat, Member loginMember) { | ||
if (!seat.isAssignedByMember(loginMember)) { | ||
throw new TicketingException(ErrorCode.NOT_SELECTABLE_SEAT); | ||
} | ||
|
||
seat.markAsPendingPayment(); | ||
paymentProcessor.processPayment(new PaymentRequest()); | ||
seat.markAsPaid(); | ||
|
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.
디폴트 메서드로 정의하신 이유가 있나요?
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.
수정했습니다~