Skip to content

Commit

Permalink
[fix] #170 - 예매자 삭제 시 판매 티켓 수에 반영하는 로직 구현 (#171)
Browse files Browse the repository at this point in the history
* [#170] feat: 예매자 삭제 관련 에러 메세지 추가

* [#170] feat(Schedule): soldTicketCount 변경 메소드 추가

* [#170] fix(TicketService): 예매자 삭제 시 soldTicketCount에 반영되도록 메소드 수정

* [#170] fix(Schedule): 예매자 삭제 시 exception 처리 방식 수정
  • Loading branch information
hyerinhwang-sailin authored Aug 13, 2024
1 parent b2f8530 commit dae27a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.beat.domain.performance.dao.PerformanceRepository;
import com.beat.domain.performance.domain.Performance;
import com.beat.domain.performance.exception.PerformanceErrorCode;
import com.beat.domain.schedule.dao.ScheduleRepository;
import com.beat.domain.schedule.domain.Schedule;
import com.beat.domain.schedule.domain.ScheduleNumber;
import com.beat.domain.booking.exception.BookingErrorCode;
import com.beat.global.common.exception.ForbiddenException;
Expand All @@ -32,6 +34,7 @@ public class TicketService {
private final PerformanceRepository performanceRepository;
private final MemberRepository memberRepository;
private final UserRepository userRepository;
private final ScheduleRepository scheduleRepository;
private final CoolSmsService coolSmsService;

public TicketRetrieveResponse getTickets(Long memberId, Long performanceId, ScheduleNumber scheduleNumber, Boolean isPaymentCompleted) {
Expand Down Expand Up @@ -125,6 +128,13 @@ public void deleteTickets(Long memberId, TicketDeleteRequest ticketDeleteRequest
.orElseThrow(() -> new NotFoundException(BookingErrorCode.NO_BOOKING_FOUND));

ticketRepository.delete(booking);

Schedule schedule = booking.getSchedule();

ticketRepository.delete(booking);

schedule.decreaseSoldTicketCount(booking.getPurchaseTicketCount());
scheduleRepository.save(schedule);
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/beat/domain/schedule/domain/Schedule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.beat.domain.schedule.domain;

import com.beat.domain.performance.domain.Performance;
import com.beat.domain.schedule.exception.ScheduleErrorCode;
import com.beat.global.common.exception.ConflictException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -78,4 +80,13 @@ public void update(LocalDateTime performanceDate, int totalTicketCount, Schedule
this.totalTicketCount = totalTicketCount;
this.scheduleNumber = scheduleNumber;
}

public void decreaseSoldTicketCount(int count) {
if (this.soldTicketCount >= count) {
this.soldTicketCount -= count;
} else {
throw new ConflictException(ScheduleErrorCode.EXCESS_TICKET_DELETE);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public enum ScheduleErrorCode implements BaseErrorCode {
INVALID_DATA_FORMAT(400, "잘못된 데이터 형식입니다."),
NO_SCHEDULE_FOUND(404, "해당 회차를 찾을 수 없습니다."),
INSUFFICIENT_TICKETS(409, "요청한 티켓 수량이 잔여 티켓 수를 초과했습니다. 다른 수량을 선택해 주세요.")
INSUFFICIENT_TICKETS(409, "요청한 티켓 수량이 잔여 티켓 수를 초과했습니다. 다른 수량을 선택해 주세요."),
EXCESS_TICKET_DELETE(409, "예매된 티켓 수 이상을 삭제할 수 없습니다.")
;

private final int status;
Expand Down

0 comments on commit dae27a6

Please sign in to comment.