diff --git a/src/main/java/com/beat/domain/booking/application/GuestBookingService.java b/src/main/java/com/beat/domain/booking/application/GuestBookingService.java index f15601c8..d67befe3 100644 --- a/src/main/java/com/beat/domain/booking/application/GuestBookingService.java +++ b/src/main/java/com/beat/domain/booking/application/GuestBookingService.java @@ -79,7 +79,7 @@ public GuestBookingResponse createGuestBooking(GuestBookingRequest guestBookingR booking.isPaymentCompleted(), schedule.getPerformance().getBankName(), schedule.getPerformance().getAccountNumber(), - totalPaymentAmount, + totalPaymentAmount, // 회원 예매랑 다른 부분 확인하기 booking.getCreatedAt() ); } diff --git a/src/main/java/com/beat/domain/booking/application/MemberBookingService.java b/src/main/java/com/beat/domain/booking/application/MemberBookingService.java index 2d6d9ccb..58019edf 100644 --- a/src/main/java/com/beat/domain/booking/application/MemberBookingService.java +++ b/src/main/java/com/beat/domain/booking/application/MemberBookingService.java @@ -70,7 +70,7 @@ public MemberBookingResponse createMemberBooking(Long memberId, MemberBookingReq booking.isPaymentCompleted(), schedule.getPerformance().getBankName(), schedule.getPerformance().getAccountNumber(), - memberBookingRequest.totalPaymentAmount(), + memberBookingRequest.totalPaymentAmount(), // 비회원 예매처럼 int totalPaymentAmount = ticketPrice * guestBookingRequest.purchaseTicketCount();로 계산해서 반영하기 + 요청한 총 가격 == 티켓 가격 * 수 같은지 검증하는 로직 추가하기 booking.getCreatedAt() ); } diff --git a/src/main/java/com/beat/domain/cast/dao/CastRepository.java b/src/main/java/com/beat/domain/cast/dao/CastRepository.java index 37eb520b..98e6214b 100644 --- a/src/main/java/com/beat/domain/cast/dao/CastRepository.java +++ b/src/main/java/com/beat/domain/cast/dao/CastRepository.java @@ -2,6 +2,7 @@ import com.beat.domain.cast.domain.Cast; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; @@ -9,4 +10,7 @@ public interface CastRepository extends JpaRepository { List findByPerformanceId(Long performanceId); List findAllByPerformanceId(Long performanceId); + + @Query("SELECT c.id FROM Cast c WHERE c.performance.id = :performanceId") + List findIdsByPerformanceId(Long performanceId); } diff --git a/src/main/java/com/beat/domain/cast/exception/CastErrorCode.java b/src/main/java/com/beat/domain/cast/exception/CastErrorCode.java index 9658d8ab..15189c27 100644 --- a/src/main/java/com/beat/domain/cast/exception/CastErrorCode.java +++ b/src/main/java/com/beat/domain/cast/exception/CastErrorCode.java @@ -7,6 +7,7 @@ @Getter @RequiredArgsConstructor public enum CastErrorCode implements BaseErrorCode { + CAST_NOT_BELONG_TO_PERFORMANCE(403,"해당 등장인물은 해당 공연에 속해 있지 않습니다."), CAST_NOT_FOUND(404, "등장인물이 존재하지 않습니다.") ; diff --git a/src/main/java/com/beat/domain/performance/api/PerformanceController.java b/src/main/java/com/beat/domain/performance/api/PerformanceController.java index ecabf3d6..7af7d46d 100644 --- a/src/main/java/com/beat/domain/performance/api/PerformanceController.java +++ b/src/main/java/com/beat/domain/performance/api/PerformanceController.java @@ -1,15 +1,15 @@ package com.beat.domain.performance.api; import com.beat.domain.performance.application.PerformanceManagementService; -import com.beat.domain.performance.application.PerformanceUpdateService; +import com.beat.domain.performance.application.PerformanceModifyService; import com.beat.domain.performance.application.dto.BookingPerformanceDetailResponse; import com.beat.domain.performance.application.dto.MakerPerformanceResponse; import com.beat.domain.performance.application.dto.PerformanceDetailResponse; import com.beat.domain.performance.application.dto.PerformanceEditResponse; import com.beat.domain.performance.application.dto.create.PerformanceRequest; import com.beat.domain.performance.application.dto.create.PerformanceResponse; -import com.beat.domain.performance.application.dto.update.PerformanceUpdateRequest; -import com.beat.domain.performance.application.dto.update.PerformanceUpdateResponse; +import com.beat.domain.performance.application.dto.modify.PerformanceModifyRequest; +import com.beat.domain.performance.application.dto.modify.PerformanceModifyResponse; import com.beat.domain.performance.exception.PerformanceSuccessCode; import com.beat.domain.performance.application.PerformanceService; import com.beat.global.auth.annotation.CurrentMember; @@ -36,7 +36,7 @@ public class PerformanceController { private final PerformanceService performanceService; private final PerformanceManagementService performanceManagementService; - private final PerformanceUpdateService performanceUpdateService; + private final PerformanceModifyService performanceModifyService; @Operation(summary = "공연 생성 API", description = "공연을 생성하는 POST API입니다.") @PostMapping @@ -63,10 +63,10 @@ public ResponseEntity> createPerformance( @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) @PutMapping - public ResponseEntity> updatePerformance( + public ResponseEntity> updatePerformance( @CurrentMember Long memberId, - @RequestBody PerformanceUpdateRequest performanceUpdateRequest) { - PerformanceUpdateResponse response = performanceUpdateService.updatePerformance(memberId, performanceUpdateRequest); + @RequestBody PerformanceModifyRequest performanceModifyRequest) { + PerformanceModifyResponse response = performanceModifyService.modifyPerformance(memberId, performanceModifyRequest); return ResponseEntity.status(HttpStatus.OK) .body(SuccessResponse.of(PerformanceSuccessCode.PERFORMANCE_UPDATE_SUCCESS, response)); } diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java b/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java new file mode 100644 index 00000000..40aa7eef --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java @@ -0,0 +1,453 @@ +package com.beat.domain.performance.application; + +import com.beat.domain.booking.dao.BookingRepository; +import com.beat.domain.cast.dao.CastRepository; +import com.beat.domain.cast.domain.Cast; +import com.beat.domain.cast.exception.CastErrorCode; +import com.beat.domain.member.dao.MemberRepository; +import com.beat.domain.member.domain.Member; +import com.beat.domain.member.exception.MemberErrorCode; +import com.beat.domain.performance.application.dto.modify.*; +import com.beat.domain.performance.application.dto.modify.cast.CastModifyRequest; +import com.beat.domain.performance.application.dto.modify.cast.CastModifyResponse; +import com.beat.domain.performance.application.dto.modify.schedule.ScheduleModifyRequest; +import com.beat.domain.performance.application.dto.modify.schedule.ScheduleModifyResponse; +import com.beat.domain.performance.application.dto.modify.staff.StaffModifyRequest; +import com.beat.domain.performance.application.dto.modify.staff.StaffModifyResponse; +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.schedule.exception.ScheduleErrorCode; +import com.beat.domain.staff.dao.StaffRepository; +import com.beat.domain.staff.domain.Staff; +import com.beat.domain.staff.exception.StaffErrorCode; +import com.beat.global.common.exception.BadRequestException; +import com.beat.global.common.exception.ForbiddenException; +import com.beat.global.common.exception.NotFoundException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +@Slf4j +@Service +@RequiredArgsConstructor +public class PerformanceModifyService { + + private final PerformanceRepository performanceRepository; + private final ScheduleRepository scheduleRepository; + private final MemberRepository memberRepository; + private final CastRepository castRepository; + private final StaffRepository staffRepository; + private final BookingRepository bookingRepository; + + @Transactional + public PerformanceModifyResponse modifyPerformance(Long memberId, PerformanceModifyRequest request) { + log.info("Starting updatePerformance for memberId: {}, performanceId: {}", memberId, request.performanceId()); + + Member member = validateMember(memberId); + Long userId = member.getUser().getId(); + + Performance performance = findPerformance(request.performanceId()); + + validateOwnership(userId, performance); + + List scheduleIds = scheduleRepository.findIdsByPerformanceId(request.performanceId()); + boolean isBookerExist = bookingRepository.existsByScheduleIdIn(scheduleIds); + + if (isBookerExist && request.ticketPrice() != performance.getTicketPrice()) { + log.error("Ticket price update failed due to existing bookings for performanceId: {}", performance.getId()); + throw new BadRequestException(PerformanceErrorCode.PRICE_UPDATE_NOT_ALLOWED); + } + + updatePerformanceDetails(performance, request, isBookerExist); + + List modifiedSchedules = processSchedules(request.scheduleModifyRequests(), performance); + List modifiedCasts = processCasts(request.castModifyRequests(), performance); + List modifiedStaffs = processStaffs(request.staffModifyRequests(), performance); + + PerformanceModifyResponse response = completeModifyResponse(performance, modifiedSchedules, modifiedCasts, modifiedStaffs); + + log.info("Successfully completed updatePerformance for performanceId: {}", request.performanceId()); + return response; + } + + private Member validateMember(Long memberId) { + log.debug("Validating memberId: {}", memberId); + return memberRepository.findById(memberId) + .orElseThrow(() -> { + log.error("Member not found: memberId: {}", memberId); + return new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND); + }); + } + + private Performance findPerformance(Long performanceId) { + log.debug("Finding performance with performanceId: {}", performanceId); + return performanceRepository.findById(performanceId) + .orElseThrow(() -> { + log.error("Performance not found: performanceId: {}", performanceId); + return new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND); + }); + } + + private void validateOwnership(Long userId, Performance performance) { + if (!performance.getUsers().getId().equals(userId)) { + log.error("User ID {} does not own performance ID {}", userId, performance.getId()); + throw new ForbiddenException(PerformanceErrorCode.NOT_PERFORMANCE_OWNER); + } + } + + private void updatePerformanceDetails(Performance performance, PerformanceModifyRequest request, boolean isBookerExist) { + log.debug("Updating performance details for performanceId: {}", performance.getId()); + + performance.update( + request.performanceTitle(), + request.genre(), + request.runningTime(), + request.performanceDescription(), + request.performanceAttentionNote(), + request.bankName(), + request.accountNumber(), + request.accountHolder(), + request.posterImage(), + request.performanceTeamName(), + request.performanceVenue(), + request.performanceContact(), + request.performancePeriod(), + request.totalScheduleCount() + ); + + if (!isBookerExist) { + log.debug("Updating ticket price to {}", request.ticketPrice()); + performance.updateTicketPrice(request.ticketPrice()); + } + + performanceRepository.save(performance); + log.debug("Performance details updated for performanceId: {}", performance.getId()); + } + + private List processSchedules(List scheduleRequests, Performance performance) { + List existingScheduleIds = scheduleRepository.findIdsByPerformanceId(performance.getId()); + + List requestScheduleIds = scheduleRequests.stream() + .map(ScheduleModifyRequest::scheduleId) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + List schedulesToDelete = existingScheduleIds.stream() + .filter(id -> !requestScheduleIds.contains(id)) + .collect(Collectors.toList()); + + deleteRemainingSchedules(schedulesToDelete); + + List schedules = scheduleRequests.stream() + .map(request -> { + if (request.scheduleId() == null) { + return addSchedule(request, performance); + } else { + return updateSchedule(request, performance); + } + }) + .collect(Collectors.toList()); + + assignScheduleNumbers(schedules); + + return schedules.stream() + .map(schedule -> ScheduleModifyResponse.of( + schedule.getId(), + schedule.getPerformanceDate(), + schedule.getTotalTicketCount(), + calculateDueDate(schedule.getPerformanceDate()), + schedule.getScheduleNumber() + )) + .collect(Collectors.toList()); + } + + private void assignScheduleNumbers(List schedules) { + schedules.sort(Comparator.comparing(Schedule::getPerformanceDate)); + + for (int i = 0; i < schedules.size(); i++) { + ScheduleNumber scheduleNumber = ScheduleNumber.values()[i]; + schedules.get(i).updateScheduleNumber(scheduleNumber); + } + } + + private Schedule addSchedule(ScheduleModifyRequest request, Performance performance) { + log.debug("Adding schedules for performanceId: {}", performance.getId()); + + long existingSchedulesCount = scheduleRepository.countByPerformanceId(performance.getId()); + + if ((existingSchedulesCount + 1) > 3) { + throw new BadRequestException(PerformanceErrorCode.MAX_SCHEDULE_LIMIT_EXCEEDED); + } + + Schedule schedule = Schedule.create( + request.performanceDate(), + request.totalTicketCount(), + 0, + true, + ScheduleNumber.FIRST, // 임시로 1회차 + performance + ); + + Schedule savedSchedule = scheduleRepository.save(schedule); + log.debug("Added schedule with scheduleId: {} for performanceId: {}", savedSchedule.getId(), performance.getId()); + return savedSchedule; + } + + private Schedule updateSchedule(ScheduleModifyRequest request, Performance performance) { + log.debug("Updating schedules for scheduleId: {}", request.scheduleId()); + + Schedule schedule = scheduleRepository.findById(request.scheduleId()) + .orElseThrow(() -> { + log.error("Schedule not found: scheduleId: {}", request.scheduleId()); + return new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND); + }); + + if (!schedule.getPerformance().equals(performance)) { + throw new ForbiddenException(ScheduleErrorCode.SCHEDULE_NOT_BELONG_TO_PERFORMANCE); + } + + schedule.update( + request.performanceDate(), + request.totalTicketCount(), + schedule.getScheduleNumber() // 기존 scheduleNumber 유지 + ); + return scheduleRepository.save(schedule); + } + + private void deleteRemainingSchedules(List scheduleIds) { + if (scheduleIds == null || scheduleIds.isEmpty()) { + log.debug("No schedules to delete"); + return; + } + + scheduleIds.forEach(scheduleId -> { + Schedule schedule = scheduleRepository.findById(scheduleId) + .orElseThrow(() -> { + log.error("Schedule not found: scheduleId: {}", scheduleId); + return new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND); + }); + scheduleRepository.delete(schedule); + log.debug("Deleted schedule with scheduleId: {}", scheduleId); + }); + } + + private List processCasts(List castRequests, Performance performance) { + log.debug("Processing casts for performanceId: {}", performance.getId()); + + List existingCastIds = castRepository.findIdsByPerformanceId(performance.getId()); + + List responses = castRequests.stream() + .map(request -> { + if (request.castId() == null) { + return addCast(request, performance); + } else { + existingCastIds.remove(request.castId()); + return updateCast(request, performance); + } + }) + .toList(); + + deleteRemainingCasts(existingCastIds); + + return responses; + } + + private CastModifyResponse addCast(CastModifyRequest request, Performance performance) { + log.debug("Adding casts for performanceId: {}", performance.getId()); + + Cast cast = Cast.create( + request.castName(), + request.castRole(), + request.castPhoto(), + performance + ); + Cast savedCast = castRepository.save(cast); + log.debug("Added cast with castId: {} for performanceId: {}", savedCast.getId(), performance.getId()); + return CastModifyResponse.of( + savedCast.getId(), + savedCast.getCastName(), + savedCast.getCastRole(), + savedCast.getCastPhoto() + ); + } + + private CastModifyResponse updateCast(CastModifyRequest request, Performance performance) { + log.debug("Updating casts for castId: {}", request.castId()); + + Cast cast = castRepository.findById(request.castId()) + .orElseThrow(() -> { + log.error("Cast not found: castId: {}", request.castId()); + return new NotFoundException(CastErrorCode.CAST_NOT_FOUND); + }); + + if (!cast.getPerformance().equals(performance)) { + throw new ForbiddenException(CastErrorCode.CAST_NOT_BELONG_TO_PERFORMANCE); + } + + cast.update( + request.castName(), + request.castRole(), + request.castPhoto() + ); + castRepository.save(cast); + log.debug("Updated cast with castId: {}", cast.getId()); + return CastModifyResponse.of( + cast.getId(), + cast.getCastName(), + cast.getCastRole(), + cast.getCastPhoto() + ); + } + + private void deleteRemainingCasts(List castIds) { + if (castIds == null || castIds.isEmpty()) { + log.debug("No casts to delete"); + return; + } + + castIds.forEach(castId -> { + Cast cast = castRepository.findById(castId) + .orElseThrow(() -> { + log.error("Cast not found: castId: {}", castId); + return new NotFoundException(CastErrorCode.CAST_NOT_FOUND); + }); + castRepository.delete(cast); + log.debug("Deleted cast with castId: {}", castId); + }); + } + + private List processStaffs(List staffRequests, Performance performance) { + log.debug("Processing staffs for performanceId: {}", performance.getId()); + + List existingStaffIds = staffRepository.findIdsByPerformanceId(performance.getId()); + + List responses = staffRequests.stream() + .map(request -> { + if (request.staffId() == null) { + return addStaff(request, performance); + } else { + existingStaffIds.remove(request.staffId()); // 요청에 포함된 ID는 삭제 후보에서 제거 + return updateStaff(request, performance); + } + }) + .collect(Collectors.toList()); + + deleteRemainingStaffs(existingStaffIds); + + return responses; + } + + private StaffModifyResponse addStaff(StaffModifyRequest request, Performance performance) { + log.debug("Adding staffs for performanceId: {}", performance.getId()); + + Staff staff = Staff.create( + request.staffName(), + request.staffRole(), + request.staffPhoto(), + performance + ); + Staff savedStaff = staffRepository.save(staff); + log.debug("Added staff with staffId: {} for performanceId: {}", savedStaff.getId(), performance.getId()); + return StaffModifyResponse.of( + savedStaff.getId(), + savedStaff.getStaffName(), + savedStaff.getStaffRole(), + savedStaff.getStaffPhoto() + ); + } + + private StaffModifyResponse updateStaff(StaffModifyRequest request, Performance performance) { + log.debug("Updating staffs for staffId: {}", request.staffId()); + + Staff staff = staffRepository.findById(request.staffId()) + .orElseThrow(() -> { + log.error("Staff not found: staffId: {}", request.staffId()); + return new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND); + }); + + if (!staff.getPerformance().equals(performance)) { + throw new ForbiddenException(StaffErrorCode.STAFF_NOT_BELONG_TO_PERFORMANCE); + } + + staff.update( + request.staffName(), + request.staffRole(), + request.staffPhoto() + ); + staffRepository.save(staff); + log.debug("Updated staff with staffId: {}", staff.getId()); + return StaffModifyResponse.of( + staff.getId(), + staff.getStaffName(), + staff.getStaffRole(), + staff.getStaffPhoto() + ); + } + + private void deleteRemainingStaffs(List staffIds) { + if (staffIds == null || staffIds.isEmpty()) { + log.debug("No staffs to delete"); + return; + } + + staffIds.forEach(staffId -> { + Staff staff = staffRepository.findById(staffId) + .orElseThrow(() -> { + log.error("Staff not found: staffId: {}", staffId); + return new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND); + }); + staffRepository.delete(staff); + log.debug("Deleted staff with staffId: {}", staffId); + }); + } + + private int calculateDueDate(LocalDateTime performanceDate) { + return (int) ChronoUnit.DAYS.between(LocalDate.now(), performanceDate.toLocalDate()); + } + + private PerformanceModifyResponse completeModifyResponse( + Performance performance, + List scheduleModifyResponses, + List castModifyResponses, + List staffModifyResponses + ) { + log.debug("Creating PerformanceModifyResponse for performanceId: {}", performance.getId()); + PerformanceModifyResponse response = PerformanceModifyResponse.of( + performance.getUsers().getId(), + performance.getId(), + performance.getPerformanceTitle(), + performance.getGenre(), + performance.getRunningTime(), + performance.getPerformanceDescription(), + performance.getPerformanceAttentionNote(), + performance.getBankName(), + performance.getAccountNumber(), + performance.getAccountHolder(), + performance.getPosterImage(), + performance.getPerformanceTeamName(), + performance.getPerformanceVenue(), + performance.getPerformanceContact(), + performance.getPerformancePeriod(), + performance.getTicketPrice(), + performance.getTotalScheduleCount(), + scheduleModifyResponses, + castModifyResponses, + staffModifyResponses + ); + log.info("PerformanceModifyResponse created successfully for performanceId: {}", performance.getId()); + return response; + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java b/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java deleted file mode 100644 index 380240b9..00000000 --- a/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java +++ /dev/null @@ -1,455 +0,0 @@ -package com.beat.domain.performance.application; - -import com.beat.domain.booking.dao.BookingRepository; -import com.beat.domain.cast.dao.CastRepository; -import com.beat.domain.cast.domain.Cast; -import com.beat.domain.cast.exception.CastErrorCode; -import com.beat.domain.member.dao.MemberRepository; -import com.beat.domain.member.domain.Member; -import com.beat.domain.member.exception.MemberErrorCode; -import com.beat.domain.performance.application.dto.update.*; -import com.beat.domain.performance.application.dto.update.cast.CastAddRequest; -import com.beat.domain.performance.application.dto.update.cast.CastAddResponse; -import com.beat.domain.performance.application.dto.update.cast.CastDeleteRequest; -import com.beat.domain.performance.application.dto.update.cast.CastDeleteResponse; -import com.beat.domain.performance.application.dto.update.cast.CastUpdateRequest; -import com.beat.domain.performance.application.dto.update.cast.CastUpdateResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleAddRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleAddResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleDeleteRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleDeleteResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleUpdateRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleUpdateResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffAddRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffAddResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffDeleteRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffDeleteResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffUpdateRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffUpdateResponse; -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.exception.ScheduleErrorCode; -import com.beat.domain.staff.dao.StaffRepository; -import com.beat.domain.staff.domain.Staff; -import com.beat.domain.staff.exception.StaffErrorCode; -import com.beat.global.common.exception.BadRequestException; -import com.beat.global.common.exception.ForbiddenException; -import com.beat.global.common.exception.NotFoundException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; -import java.util.stream.Collectors; - -@Slf4j -@Service -@RequiredArgsConstructor -public class PerformanceUpdateService { - - private final PerformanceRepository performanceRepository; - private final ScheduleRepository scheduleRepository; - private final MemberRepository memberRepository; - private final CastRepository castRepository; - private final StaffRepository staffRepository; - private final BookingRepository bookingRepository; - - @Transactional - public PerformanceUpdateResponse updatePerformance(Long memberId, PerformanceUpdateRequest request) { - log.info("Starting updatePerformance for memberId: {}, performanceId: {}", memberId, request.performanceId()); - - Member member = validateMember(memberId); - Long userId = member.getUser().getId(); - - Performance performance = findPerformance(request.performanceId()); - - validateOwnership(userId, performance); - - List scheduleIds = scheduleRepository.findIdsByPerformanceId(request.performanceId()); - boolean isBookerExist = bookingRepository.existsByScheduleIdIn(scheduleIds); - - if (isBookerExist && request.ticketPrice() != performance.getTicketPrice()) { - log.error("Ticket price update failed due to existing bookings for performanceId: {}", performance.getId()); - throw new BadRequestException(PerformanceErrorCode.PRICE_UPDATE_NOT_ALLOWED); - } - - updatePerformanceDetails(performance, request, isBookerExist); - - List deletedSchedules = deleteSchedules(request.scheduleDeleteRequests()); - List updatedSchedules = updateSchedules(request.scheduleUpdateRequests()); - List addedSchedules = addSchedules(request.scheduleAddRequests(), performance); - - List deletedCasts = deleteCasts(request.castDeleteRequests()); - List updatedCasts = updateCasts(request.castUpdateRequests()); - List addedCasts = addCasts(request.castAddRequests(), performance); - - List deletedStaffs = deleteStaffs(request.staffDeleteRequests()); - List updatedStaffs = updateStaffs(request.staffUpdateRequests()); - List addedStaffs = addStaffs(request.staffAddRequests(), performance); - - PerformanceUpdateResponse response = completeUpdateResponse(performance, addedSchedules, updatedSchedules, deletedSchedules, - addedCasts, updatedCasts, deletedCasts, - addedStaffs, updatedStaffs, deletedStaffs); - - log.info("Successfully completed updatePerformance for performanceId: {}", request.performanceId()); - return response; - } - - private Member validateMember(Long memberId) { - log.debug("Validating memberId: {}", memberId); - return memberRepository.findById(memberId) - .orElseThrow(() -> { - log.error("Member not found: memberId: {}", memberId); - return new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND); - }); - } - - private Performance findPerformance(Long performanceId) { - log.debug("Finding performance with performanceId: {}", performanceId); - return performanceRepository.findById(performanceId) - .orElseThrow(() -> { - log.error("Performance not found: performanceId: {}", performanceId); - return new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND); - }); - } - - private void validateOwnership(Long userId, Performance performance) { - if (!performance.getUsers().getId().equals(userId)) { - log.error("User ID {} does not own performance ID {}", userId, performance.getId()); - throw new ForbiddenException(PerformanceErrorCode.NOT_PERFORMANCE_OWNER); - } - } - - private void updatePerformanceDetails(Performance performance, PerformanceUpdateRequest request, boolean isBookerExist) { - log.debug("Updating performance details for performanceId: {}", performance.getId()); - - performance.update( - request.performanceTitle(), - request.genre(), - request.runningTime(), - request.performanceDescription(), - request.performanceAttentionNote(), - request.bankName(), - request.accountNumber(), - request.accountHolder(), - request.posterImage(), - request.performanceTeamName(), - request.performanceVenue(), - request.performanceContact(), - request.performancePeriod(), - request.totalScheduleCount() - ); - - if (!isBookerExist) { - log.debug("Updating ticket price to {}", request.ticketPrice()); - performance.updateTicketPrice(request.ticketPrice()); - } - - performanceRepository.save(performance); - log.debug("Performance details updated for performanceId: {}", performance.getId()); - } - - private List addSchedules(List requests, Performance performance) { - log.debug("Adding schedules for performanceId: {}", performance.getId()); - - long existingSchedulesCount = scheduleRepository.countByPerformanceId(performance.getId()); - - if (requests != null && (existingSchedulesCount + requests.size()) > 3) { - throw new BadRequestException(PerformanceErrorCode.MAX_SCHEDULE_LIMIT_EXCEEDED); - } - - if (requests == null || requests.isEmpty()) { - log.debug("No schedules to add for performanceId: {}", performance.getId()); - return List.of(); - } - - return requests.stream() - .map(request -> { - Schedule schedule = Schedule.create( - request.performanceDate(), - request.totalTicketCount(), - 0, - true, - request.scheduleNumber(), - performance - ); - Schedule savedSchedule = scheduleRepository.save(schedule); - log.debug("Added schedule with scheduleId: {} for performanceId: {}", savedSchedule.getId(), performance.getId()); - return ScheduleAddResponse.of( - savedSchedule.getId(), - savedSchedule.getPerformanceDate(), - savedSchedule.getTotalTicketCount(), - calculateDueDate(savedSchedule.getPerformanceDate()), - savedSchedule.getScheduleNumber() - ); - }) - .collect(Collectors.toList()); - } - - private List updateSchedules(List requests) { - log.debug("Updating schedules"); - if (requests == null || requests.isEmpty()) { - log.debug("No schedules to update"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Schedule schedule = scheduleRepository.findById(request.scheduleId()) - .orElseThrow(() -> { - log.error("Schedule not found: scheduleId: {}", request.scheduleId()); - return new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND); - }); - schedule.update( - request.performanceDate(), - request.totalTicketCount(), - request.scheduleNumber() - ); - scheduleRepository.save(schedule); - log.debug("Updated schedule with scheduleId: {}", schedule.getId()); - return ScheduleUpdateResponse.of( - schedule.getId(), - schedule.getPerformanceDate(), - schedule.getTotalTicketCount(), - calculateDueDate(schedule.getPerformanceDate()), - schedule.getScheduleNumber() - ); - }) - .collect(Collectors.toList()); - } - - private List deleteSchedules(List requests) { - log.debug("Deleting schedules"); - if (requests == null || requests.isEmpty()) { - log.debug("No schedules to delete"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Schedule schedule = scheduleRepository.findById(request.scheduleId()) - .orElseThrow(() -> { - log.error("Schedule not found: scheduleId: {}", request.scheduleId()); - return new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND); - }); - scheduleRepository.delete(schedule); - log.debug("Deleted schedule with scheduleId: {}", schedule.getId()); - return ScheduleDeleteResponse.from(schedule.getId()); - }) - .collect(Collectors.toList()); - } - - private List addCasts(List requests, Performance performance) { - log.debug("Adding casts for performanceId: {}", performance.getId()); - if (requests == null || requests.isEmpty()) { - log.debug("No casts to add for performanceId: {}", performance.getId()); - return List.of(); - } - - return requests.stream() - .map(request -> { - Cast cast = Cast.create( - request.castName(), - request.castRole(), - request.castPhoto(), - performance - ); - Cast savedCast = castRepository.save(cast); - log.debug("Added cast with castId: {} for performanceId: {}", savedCast.getId(), performance.getId()); - return CastAddResponse.of( - savedCast.getId(), - savedCast.getCastName(), - savedCast.getCastRole(), - savedCast.getCastPhoto() - ); - }) - .collect(Collectors.toList()); - } - - private List updateCasts(List requests) { - log.debug("Updating casts"); - if (requests == null || requests.isEmpty()) { - log.debug("No casts to update"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Cast cast = castRepository.findById(request.castId()) - .orElseThrow(() -> { - log.error("Cast not found: castId: {}", request.castId()); - return new NotFoundException(CastErrorCode.CAST_NOT_FOUND); - }); - cast.update( - request.castName(), - request.castRole(), - request.castPhoto() - ); - castRepository.save(cast); - log.debug("Updated cast with castId: {}", cast.getId()); - return CastUpdateResponse.of( - cast.getId(), - cast.getCastName(), - cast.getCastRole(), - cast.getCastPhoto() - ); - }) - .collect(Collectors.toList()); - } - - private List deleteCasts(List requests) { - log.debug("Deleting casts"); - if (requests == null || requests.isEmpty()) { - log.debug("No casts to delete"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Cast cast = castRepository.findById(request.castId()) - .orElseThrow(() -> { - log.error("Cast not found: castId: {}", request.castId()); - return new NotFoundException(CastErrorCode.CAST_NOT_FOUND); - }); - castRepository.delete(cast); - log.debug("Deleted cast with castId: {}", cast.getId()); - return CastDeleteResponse.from(cast.getId()); - }) - .collect(Collectors.toList()); - } - - private List addStaffs(List requests, Performance performance) { - log.debug("Adding staffs for performanceId: {}", performance.getId()); - if (requests == null || requests.isEmpty()) { - log.debug("No staffs to add for performanceId: {}", performance.getId()); - return List.of(); - } - - return requests.stream() - .map(request -> { - Staff staff = Staff.create( - request.staffName(), - request.staffRole(), - request.staffPhoto(), - performance - ); - Staff savedStaff = staffRepository.save(staff); - log.debug("Added staff with staffId: {} for performanceId: {}", savedStaff.getId(), performance.getId()); - return StaffAddResponse.of( - savedStaff.getId(), - savedStaff.getStaffName(), - savedStaff.getStaffRole(), - savedStaff.getStaffPhoto() - ); - }) - .collect(Collectors.toList()); - } - - private List updateStaffs(List requests) { - log.debug("Updating staffs"); - if (requests == null || requests.isEmpty()) { - log.debug("No staffs to update"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Staff staff = staffRepository.findById(request.staffId()) - .orElseThrow(() -> { - log.error("Staff not found: staffId: {}", request.staffId()); - return new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND); - }); - staff.update( - request.staffName(), - request.staffRole(), - request.staffPhoto() - ); - staffRepository.save(staff); - log.debug("Updated staff with staffId: {}", staff.getId()); - return StaffUpdateResponse.of( - staff.getId(), - staff.getStaffName(), - staff.getStaffRole(), - staff.getStaffPhoto() - ); - }) - .collect(Collectors.toList()); - } - - private List deleteStaffs(List requests) { - log.debug("Deleting staffs"); - if (requests == null || requests.isEmpty()) { - log.debug("No staffs to delete"); - return List.of(); - } - - return requests.stream() - .map(request -> { - Staff staff = staffRepository.findById(request.staffId()) - .orElseThrow(() -> { - log.error("Staff not found: staffId: {}", request.staffId()); - return new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND); - }); - staffRepository.delete(staff); - log.debug("Deleted staff with staffId: {}", staff.getId()); - return StaffDeleteResponse.from(staff.getId()); - }) - .collect(Collectors.toList()); - } - - private int calculateDueDate(LocalDateTime performanceDate) { - return (int) ChronoUnit.DAYS.between(LocalDate.now(), performanceDate.toLocalDate()); - } - - private PerformanceUpdateResponse completeUpdateResponse( - Performance performance, - List addedSchedules, - List updatedSchedules, - List deletedSchedules, - List addedCasts, - List updatedCasts, - List deletedCasts, - List addedStaffs, - List updatedStaffs, - List deletedStaffs - ) { - log.debug("Creating PerformanceUpdateResponse for performanceId: {}", performance.getId()); - PerformanceUpdateResponse response = PerformanceUpdateResponse.of( - performance.getUsers().getId(), - performance.getId(), - performance.getPerformanceTitle(), - performance.getGenre(), - performance.getRunningTime(), - performance.getPerformanceDescription(), - performance.getPerformanceAttentionNote(), - performance.getBankName(), - performance.getAccountNumber(), - performance.getAccountHolder(), - performance.getPosterImage(), - performance.getPerformanceTeamName(), - performance.getPerformanceVenue(), - performance.getPerformanceContact(), - performance.getPerformancePeriod(), - performance.getTicketPrice(), - performance.getTotalScheduleCount(), - addedSchedules, - deletedSchedules, - updatedSchedules, - addedCasts, - deletedCasts, - updatedCasts, - addedStaffs, - deletedStaffs, - updatedStaffs - ); - log.info("PerformanceUpdateResponse created successfully for performanceId: {}", performance.getId()); - return response; - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyRequest.java b/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyRequest.java new file mode 100644 index 00000000..89cca1d2 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyRequest.java @@ -0,0 +1,31 @@ +package com.beat.domain.performance.application.dto.modify; + +import com.beat.domain.performance.application.dto.modify.cast.CastModifyRequest; +import com.beat.domain.performance.application.dto.modify.schedule.ScheduleModifyRequest; +import com.beat.domain.performance.application.dto.modify.staff.StaffModifyRequest; +import com.beat.domain.performance.domain.BankName; +import com.beat.domain.performance.domain.Genre; + +import java.util.List; + +public record PerformanceModifyRequest( + Long performanceId, + String performanceTitle, + Genre genre, + int runningTime, + String performanceDescription, + String performanceAttentionNote, + BankName bankName, + String accountNumber, + String accountHolder, + String posterImage, + String performanceTeamName, + String performanceVenue, + String performanceContact, + String performancePeriod, + int totalScheduleCount, + int ticketPrice, + List scheduleModifyRequests, + List castModifyRequests, + List staffModifyRequests +) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyResponse.java b/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyResponse.java new file mode 100644 index 00000000..734e2086 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/PerformanceModifyResponse.java @@ -0,0 +1,79 @@ +package com.beat.domain.performance.application.dto.modify; + +import com.beat.domain.performance.application.dto.modify.cast.CastModifyResponse; +import com.beat.domain.performance.application.dto.modify.schedule.ScheduleModifyResponse; +import com.beat.domain.performance.application.dto.modify.staff.StaffModifyResponse; +import com.beat.domain.performance.domain.BankName; +import com.beat.domain.performance.domain.Genre; + +import java.util.List; + +public record PerformanceModifyResponse( + Long userId, + Long performanceId, + String performanceTitle, + Genre genre, + int runningTime, + String performanceDescription, + String performanceAttentionNote, + BankName bankName, + String accountNumber, + String accountHolder, + String posterImage, + String performanceTeamName, + String performanceVenue, + String performanceContact, + String performancePeriod, + int ticketPrice, + int totalScheduleCount, + List scheduleModifyResponses, + List castModifyResponses, + List staffModifyResponses +) { + public static PerformanceModifyResponse of( + Long userId, + Long performanceId, + String performanceTitle, + Genre genre, + int runningTime, + String performanceDescription, + String performanceAttentionNote, + BankName bankName, + String accountNumber, + String accountHolder, + String posterImage, + String performanceTeamName, + String performanceVenue, + String performanceContact, + String performancePeriod, + int ticketPrice, + int totalScheduleCount, + List scheduleModifyRespons, + List castModifyRespons, + List staffModifyRespons) + { + + return new PerformanceModifyResponse( + userId, + performanceId, + performanceTitle, + genre, + runningTime, + performanceDescription, + performanceAttentionNote, + bankName, + accountNumber, + accountHolder, + posterImage, + performanceTeamName, + performanceVenue, + performanceContact, + performancePeriod, + ticketPrice, + totalScheduleCount, + scheduleModifyRespons, + castModifyRespons, + staffModifyRespons + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyRequest.java b/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyRequest.java new file mode 100644 index 00000000..3f3b56d2 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyRequest.java @@ -0,0 +1,12 @@ +package com.beat.domain.performance.application.dto.modify.cast; + +import org.jetbrains.annotations.Nullable; + +public record CastModifyRequest( + @Nullable + Long castId, + String castName, + String castRole, + String castPhoto +) { +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyResponse.java b/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyResponse.java new file mode 100644 index 00000000..bfed8151 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/cast/CastModifyResponse.java @@ -0,0 +1,11 @@ +package com.beat.domain.performance.application.dto.modify.cast; + +public record CastModifyResponse(Long castId, + String castName, + String castRole, + String castPhoto) { + + public static CastModifyResponse of(Long castId, String castName, String castRole, String castPhoto) { + return new CastModifyResponse(castId, castName, castRole, castPhoto); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyRequest.java b/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyRequest.java new file mode 100644 index 00000000..fcda2a5f --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyRequest.java @@ -0,0 +1,13 @@ +package com.beat.domain.performance.application.dto.modify.schedule; + +import org.jetbrains.annotations.Nullable; + +import java.time.LocalDateTime; + +public record ScheduleModifyRequest( + @Nullable + Long scheduleId, + LocalDateTime performanceDate, + int totalTicketCount +) { +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyResponse.java b/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyResponse.java new file mode 100644 index 00000000..fadf4dc9 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/schedule/ScheduleModifyResponse.java @@ -0,0 +1,16 @@ +package com.beat.domain.performance.application.dto.modify.schedule; + +import com.beat.domain.schedule.domain.ScheduleNumber; + +import java.time.LocalDateTime; + +public record ScheduleModifyResponse(Long scheduleId, + LocalDateTime performanceDate, + int totalTicketCount, + int dueDate, + ScheduleNumber scheduleNumber) { + + public static ScheduleModifyResponse of(Long scheduleId, LocalDateTime performanceDate, int totalTicketCount, int dueDate, ScheduleNumber scheduleNumber) { + return new ScheduleModifyResponse(scheduleId, performanceDate, totalTicketCount, dueDate, scheduleNumber); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyRequest.java b/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyRequest.java new file mode 100644 index 00000000..67020ed1 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyRequest.java @@ -0,0 +1,12 @@ +package com.beat.domain.performance.application.dto.modify.staff; + +import org.jetbrains.annotations.Nullable; + +public record StaffModifyRequest( + @Nullable + Long staffId, + String staffName, + String staffRole, + String staffPhoto +) { +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyResponse.java b/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyResponse.java new file mode 100644 index 00000000..afe97f49 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/modify/staff/StaffModifyResponse.java @@ -0,0 +1,11 @@ +package com.beat.domain.performance.application.dto.modify.staff; + +public record StaffModifyResponse(Long staffId, + String staffName, + String staffRole, + String staffPhoto) { + + public static StaffModifyResponse of(Long staffId, String staffName, String staffRole, String staffPhoto) { + return new StaffModifyResponse(staffId, staffName, staffRole, staffPhoto); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateRequest.java deleted file mode 100644 index 89948cca..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateRequest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.beat.domain.performance.application.dto.update; - -import com.beat.domain.performance.application.dto.update.cast.CastAddRequest; -import com.beat.domain.performance.application.dto.update.cast.CastDeleteRequest; -import com.beat.domain.performance.application.dto.update.cast.CastUpdateRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleAddRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleDeleteRequest; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleUpdateRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffAddRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffDeleteRequest; -import com.beat.domain.performance.application.dto.update.staff.StaffUpdateRequest; -import com.beat.domain.performance.domain.BankName; -import com.beat.domain.performance.domain.Genre; - -import java.util.List; - -public record PerformanceUpdateRequest( - Long performanceId, - String performanceTitle, - Genre genre, - int runningTime, - String performanceDescription, - String performanceAttentionNote, - BankName bankName, - String accountNumber, - String accountHolder, - String posterImage, - String performanceTeamName, - String performanceVenue, - String performanceContact, - String performancePeriod, - int totalScheduleCount, - int ticketPrice, - List scheduleAddRequests, - List scheduleDeleteRequests, - List scheduleUpdateRequests, - List castAddRequests, - List castDeleteRequests, - List castUpdateRequests, - List staffAddRequests, - List staffDeleteRequests, - List staffUpdateRequests -) {} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateResponse.java deleted file mode 100644 index 842d6b10..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateResponse.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.beat.domain.performance.application.dto.update; - -import com.beat.domain.performance.application.dto.update.cast.CastAddResponse; -import com.beat.domain.performance.application.dto.update.cast.CastDeleteResponse; -import com.beat.domain.performance.application.dto.update.cast.CastUpdateResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleAddResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleDeleteResponse; -import com.beat.domain.performance.application.dto.update.schedule.ScheduleUpdateResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffAddResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffDeleteResponse; -import com.beat.domain.performance.application.dto.update.staff.StaffUpdateResponse; -import com.beat.domain.performance.domain.BankName; -import com.beat.domain.performance.domain.Genre; - -import java.util.List; - -public record PerformanceUpdateResponse( - Long userId, - Long performanceId, - String performanceTitle, - Genre genre, - int runningTime, - String performanceDescription, - String performanceAttentionNote, - BankName bankName, - String accountNumber, - String accountHolder, - String posterImage, - String performanceTeamName, - String performanceVenue, - String performanceContact, - String performancePeriod, - int ticketPrice, - int totalScheduleCount, - List addedSchedules, - List deletedSchedules, - List updatedSchedules, - List addedCasts, - List deletedCasts, - List updatedCasts, - List addedStaffs, - List deletedStaffs, - List updatedStaffs -) { - public static PerformanceUpdateResponse of( - Long userId, - Long performanceId, - String performanceTitle, - Genre genre, - int runningTime, - String performanceDescription, - String performanceAttentionNote, - BankName bankName, - String accountNumber, - String accountHolder, - String posterImage, - String performanceTeamName, - String performanceVenue, - String performanceContact, - String performancePeriod, - int ticketPrice, - int totalScheduleCount, - List addedSchedules, - List deletedSchedules, - List updatedSchedules, - List addedCasts, - List deletedCasts, - List updatedCasts, - List addedStaffs, - List deletedStaffs, - List updatedStaffs) { - - return new PerformanceUpdateResponse( - userId, - performanceId, - performanceTitle, - genre, - runningTime, - performanceDescription, - performanceAttentionNote, - bankName, - accountNumber, - accountHolder, - posterImage, - performanceTeamName, - performanceVenue, - performanceContact, - performancePeriod, - ticketPrice, - totalScheduleCount, - addedSchedules, - deletedSchedules, - updatedSchedules, - addedCasts, - deletedCasts, - updatedCasts, - addedStaffs, - deletedStaffs, - updatedStaffs - ); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddRequest.java deleted file mode 100644 index 32087591..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddRequest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastAddRequest( - String castName, - String castRole, - String castPhoto -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddResponse.java deleted file mode 100644 index b8360963..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastAddResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastAddResponse( - Long castId, - String castName, - String castRole, - String castPhoto -) { - public static CastAddResponse of(Long castId, String castName, String castRole, String castPhoto) { - return new CastAddResponse(castId, castName, castRole, castPhoto); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteRequest.java deleted file mode 100644 index e8b9e9b8..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastDeleteRequest( - Long castId -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteResponse.java deleted file mode 100644 index 67a8648a..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastDeleteResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastDeleteResponse( - Long castId -) { - public static CastDeleteResponse from(Long castId) { - return new CastDeleteResponse(castId); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateRequest.java deleted file mode 100644 index e2a27e17..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastUpdateRequest( - Long castId, - String castName, - String castRole, - String castPhoto -) {} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateResponse.java deleted file mode 100644 index 21cabf25..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/cast/CastUpdateResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.update.cast; - -public record CastUpdateResponse( - Long castId, - String castName, - String castRole, - String castPhoto -) { - public static CastUpdateResponse of(Long castId, String castName, String castRole, String castPhoto) { - return new CastUpdateResponse(castId, castName, castRole, castPhoto); - } -} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddRequest.java deleted file mode 100644 index a370e492..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -import com.beat.domain.schedule.domain.ScheduleNumber; - -import java.time.LocalDateTime; - -public record ScheduleAddRequest( - LocalDateTime performanceDate, - int totalTicketCount, - ScheduleNumber scheduleNumber -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddResponse.java deleted file mode 100644 index 08a6b13b..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleAddResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -import com.beat.domain.schedule.domain.ScheduleNumber; - -import java.time.LocalDateTime; - -public record ScheduleAddResponse( - Long scheduleId, - LocalDateTime performanceDate, - int totalTicketCount, - int dueDate, - ScheduleNumber scheduleNumber -) { - public static ScheduleAddResponse of( - Long scheduleId, - LocalDateTime performanceDate, - int totalTicketCount, - int dueDate, - ScheduleNumber scheduleNumber - ) { - return new ScheduleAddResponse(scheduleId, performanceDate, totalTicketCount, dueDate, scheduleNumber); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteRequest.java deleted file mode 100644 index 1f7bfde4..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -public record ScheduleDeleteRequest( - Long scheduleId -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteResponse.java deleted file mode 100644 index 1e75d14c..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleDeleteResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -public record ScheduleDeleteResponse( - Long scheduleId -) { - public static ScheduleDeleteResponse from(Long scheduleId) { - return new ScheduleDeleteResponse(scheduleId); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateRequest.java deleted file mode 100644 index 825690df..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -import com.beat.domain.schedule.domain.ScheduleNumber; - -import java.time.LocalDateTime; - -public record ScheduleUpdateRequest( - Long scheduleId, - LocalDateTime performanceDate, - int totalTicketCount, - ScheduleNumber scheduleNumber -) {} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateResponse.java deleted file mode 100644 index 6f12981b..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/schedule/ScheduleUpdateResponse.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.beat.domain.performance.application.dto.update.schedule; - -import com.beat.domain.schedule.domain.ScheduleNumber; - -import java.time.LocalDateTime; - -public record ScheduleUpdateResponse( - Long scheduleId, - LocalDateTime performanceDate, - int totalTicketCount, - int dueDate, - ScheduleNumber scheduleNumber -) { - public static ScheduleUpdateResponse of(Long scheduleId, LocalDateTime performanceDate, int totalTicketCount, int dueDate, ScheduleNumber scheduleNumber) { - return new ScheduleUpdateResponse(scheduleId, performanceDate, totalTicketCount, dueDate, scheduleNumber); - } -} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddRequest.java deleted file mode 100644 index a9899c90..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddRequest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffAddRequest( - String staffName, - String staffRole, - String staffPhoto -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddResponse.java deleted file mode 100644 index 421ba869..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffAddResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffAddResponse( - Long staffId, - String staffName, - String staffRole, - String staffPhoto -) { - public static StaffAddResponse of(Long staffId, String staffName, String staffRole, String staffPhoto) { - return new StaffAddResponse(staffId, staffName, staffRole, staffPhoto); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteRequest.java deleted file mode 100644 index f0785c26..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffDeleteRequest( - Long staffId -) {} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteResponse.java deleted file mode 100644 index 0714c97f..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffDeleteResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffDeleteResponse( - Long staffId -) { - public static StaffDeleteResponse from(Long staffId) { - return new StaffDeleteResponse(staffId); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateRequest.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateRequest.java deleted file mode 100644 index 9e1b11a7..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffUpdateRequest( - Long staffId, - String staffName, - String staffRole, - String staffPhoto -) {} diff --git a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateResponse.java b/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateResponse.java deleted file mode 100644 index 56833808..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/update/staff/StaffUpdateResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.update.staff; - -public record StaffUpdateResponse( - Long staffId, - String staffName, - String staffRole, - String staffPhoto -) { - public static StaffUpdateResponse of(Long staffId, String staffName, String staffRole, String staffPhoto) { - return new StaffUpdateResponse(staffId, staffName, staffRole, staffPhoto); - } -} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/schedule/domain/Schedule.java b/src/main/java/com/beat/domain/schedule/domain/Schedule.java index d3e33df4..b3f17cc6 100644 --- a/src/main/java/com/beat/domain/schedule/domain/Schedule.java +++ b/src/main/java/com/beat/domain/schedule/domain/Schedule.java @@ -89,4 +89,7 @@ public void decreaseSoldTicketCount(int count) { } } + public void updateScheduleNumber(ScheduleNumber scheduleNumber) { + this.scheduleNumber = scheduleNumber; + } } \ No newline at end of file diff --git a/src/main/java/com/beat/domain/schedule/exception/ScheduleErrorCode.java b/src/main/java/com/beat/domain/schedule/exception/ScheduleErrorCode.java index e9af170a..98e02ad1 100644 --- a/src/main/java/com/beat/domain/schedule/exception/ScheduleErrorCode.java +++ b/src/main/java/com/beat/domain/schedule/exception/ScheduleErrorCode.java @@ -8,6 +8,7 @@ @RequiredArgsConstructor public enum ScheduleErrorCode implements BaseErrorCode { INVALID_DATA_FORMAT(400, "잘못된 데이터 형식입니다."), + SCHEDULE_NOT_BELONG_TO_PERFORMANCE(403,"해당 스케줄은 해당 공연에 속해 있지 않습니다."), NO_SCHEDULE_FOUND(404, "해당 회차를 찾을 수 없습니다."), INSUFFICIENT_TICKETS(409, "요청한 티켓 수량이 잔여 티켓 수를 초과했습니다. 다른 수량을 선택해 주세요."), EXCESS_TICKET_DELETE(409, "예매된 티켓 수 이상을 삭제할 수 없습니다.") diff --git a/src/main/java/com/beat/domain/staff/dao/StaffRepository.java b/src/main/java/com/beat/domain/staff/dao/StaffRepository.java index d3af9518..f32801ea 100644 --- a/src/main/java/com/beat/domain/staff/dao/StaffRepository.java +++ b/src/main/java/com/beat/domain/staff/dao/StaffRepository.java @@ -2,6 +2,7 @@ import com.beat.domain.staff.domain.Staff; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; @@ -9,4 +10,7 @@ public interface StaffRepository extends JpaRepository { List findByPerformanceId(Long performanceId); List findAllByPerformanceId(Long performanceId); + + @Query("SELECT s.id FROM Staff s WHERE s.performance.id = :performanceId") + List findIdsByPerformanceId(Long performanceId); } diff --git a/src/main/java/com/beat/domain/staff/exception/StaffErrorCode.java b/src/main/java/com/beat/domain/staff/exception/StaffErrorCode.java index 706e50d8..495ee148 100644 --- a/src/main/java/com/beat/domain/staff/exception/StaffErrorCode.java +++ b/src/main/java/com/beat/domain/staff/exception/StaffErrorCode.java @@ -7,6 +7,7 @@ @Getter @RequiredArgsConstructor public enum StaffErrorCode implements BaseErrorCode { + STAFF_NOT_BELONG_TO_PERFORMANCE(403, "해당 스태프는 해당 공연에 속해있지 않습니다."), STAFF_NOT_FOUND(404, "스태프가 존재하지 않습니다.") ;