Skip to content

Commit

Permalink
[#162] refactor(TicketService): 해당 공연의 메이커가 아니면 예매자를 삭제하지 못하는 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonyworld committed Aug 5, 2024
1 parent ab4e85d commit 164a24f
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.beat.domain.performance.exception.PerformanceErrorCode;
import com.beat.domain.schedule.domain.ScheduleNumber;
import com.beat.domain.booking.exception.BookingErrorCode;
import com.beat.global.common.exception.ForbiddenException;
import com.beat.global.common.exception.NotFoundException;
import com.beat.domain.user.dao.UserRepository;
import com.beat.domain.user.domain.Users;
Expand Down Expand Up @@ -107,17 +108,20 @@ public void updateTickets(Long memberId, TicketUpdateRequest request) {
}

@Transactional
public void deleteTickets(Long memberId, TicketDeleteRequest request) {
Member member = memberRepository.findById(memberId).orElseThrow(
() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
public void deleteTickets(Long memberId, TicketDeleteRequest ticketDeleteRequest) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));

Users user = userRepository.findById(member.getUser().getId()).orElseThrow(
() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND));
Long userId = member.getUser().getId();

Performance performance = performanceRepository.findById(request.performanceId())
Performance performance = performanceRepository.findById(ticketDeleteRequest.performanceId())
.orElseThrow(() -> new NotFoundException(BookingErrorCode.NO_PERFORMANCE_FOUND));

for (Long bookingId : request.bookingList()) {
if (!performance.getUsers().getId().equals(userId)) {
throw new ForbiddenException(PerformanceErrorCode.NOT_PERFORMANCE_OWNER);
}

for (Long bookingId : ticketDeleteRequest.bookingList()) {
Booking booking = ticketRepository.findById(bookingId)
.orElseThrow(() -> new NotFoundException(BookingErrorCode.NO_BOOKING_FOUND));

Expand Down

0 comments on commit 164a24f

Please sign in to comment.