From 41e7092c24793def5e3ee1e98df4c28f06d6d708 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Wed, 17 Jul 2024 23:27:06 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[#113]=20refactor(BookingRepository):=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EA=B3=B5=EC=97=B0=EC=9D=84=20=EC=98=88?= =?UTF-8?q?=EB=A7=A4=ED=95=9C=20=EC=82=AC=EB=9E=8C=EC=9D=B4=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=EC=A7=80=20=ED=8C=90=EB=8B=A8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/beat/domain/booking/dao/BookingRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/beat/domain/booking/dao/BookingRepository.java b/src/main/java/com/beat/domain/booking/dao/BookingRepository.java index 8c60d54f..35ee4fa8 100644 --- a/src/main/java/com/beat/domain/booking/dao/BookingRepository.java +++ b/src/main/java/com/beat/domain/booking/dao/BookingRepository.java @@ -22,4 +22,6 @@ Optional findFirstByBookerNameAndBookerPhoneNumberAndBirthDateAndPasswo ); List findByUsersId(Long userId); + + boolean existsBySchedulePerformanceId(Long performanceId); } \ No newline at end of file From 6cd6949d47a92af8871ee52cd611df1476de465a Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Wed, 17 Jul 2024 23:27:45 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[#113]=20refactor(PerformanceErrorCode):=20?= =?UTF-8?q?=EC=98=88=EB=A7=A4=EC=9E=90=EA=B0=80=20=ED=95=9C=EB=AA=85=20?= =?UTF-8?q?=EC=9E=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EA=B3=B5=EC=97=B0=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=EA=B0=80=20=EC=95=88=EB=90=A0=EB=95=8C=20?= =?UTF-8?q?=EB=B3=B4=EC=97=AC=EC=A3=BC=EB=8A=94=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beat/domain/performance/exception/PerformanceErrorCode.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java b/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java index 9846a018..d51a81a5 100644 --- a/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java +++ b/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java @@ -12,6 +12,7 @@ public enum PerformanceErrorCode implements BaseErrorCode { INVALID_DATA_FORMAT(400, "잘못된 데이터 형식입니다."), INVALID_REQUEST_FORMAT(400, "잘못된 요청 형식입니다."), NO_PERFORMANCE_FOUND(404, "공연을 찾을 수 없습니다."), + PERFORMANCE_DELETE_FAILED(400, "예매자가 1명 이상 있을 경우, 공연을 삭제할 수 없습니다."), INTERNAL_SERVER_ERROR(500, "서버 내부 오류입니다.") ; From 5365f48a0741f4ae1f113e9f4795f68fc376cd85 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Wed, 17 Jul 2024 23:28:07 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[#113]=20refactor(PerformanceSuccessCode):?= =?UTF-8?q?=20=EA=B3=B5=EC=97=B0=EC=9D=B4=20=EC=82=AD=EC=A0=9C=EB=90=98?= =?UTF-8?q?=EC=97=88=EC=9D=84=20=EB=95=8C=20=EB=B3=B4=EC=97=AC=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20=EC=84=B1=EA=B3=B5=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/performance/exception/PerformanceSuccessCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/beat/domain/performance/exception/PerformanceSuccessCode.java b/src/main/java/com/beat/domain/performance/exception/PerformanceSuccessCode.java index 83c51436..702e3225 100644 --- a/src/main/java/com/beat/domain/performance/exception/PerformanceSuccessCode.java +++ b/src/main/java/com/beat/domain/performance/exception/PerformanceSuccessCode.java @@ -7,8 +7,9 @@ @Getter @RequiredArgsConstructor public enum PerformanceSuccessCode implements BaseSuccessCode { - PERFORMANCE_CREATE_SUCCESS(201, "공연이 성공정으로 생성되었습니다."), + PERFORMANCE_CREATE_SUCCESS(201, "공연이 성공적으로 생성되었습니다."), PERFORMANCE_RETRIEVE_SUCCESS(200, "공연 상세 정보 조회가 성공적으로 완료되었습니다."), + PERFORMANCE_DELETE_SUCCESS(200, "공연이 성공적으로 삭제되었습니다."), BOOKING_PERFORMANCE_RETRIEVE_SUCCESS(200, "예매 관련 공연 정보 조회가 성공적으로 완료되었습니다."), HOME_PERFORMANCE_RETRIEVE_SUCCESS(200, "홈 화면 공연 목록 조회가 성공적으로 완료되었습니다."), MAKER_PERFORMANCE_RETRIEVE_SUCCESS(200, "회원이 등록한 공연 목록의 조회가 성공적으로 완료되었습니다.") From 501bf764a90a53222e1690831ba579ef09b2ad76 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Wed, 17 Jul 2024 23:29:28 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[#113]=20refactor(PerformanceManagementServ?= =?UTF-8?q?ice):=20=EB=A9=A4=EB=B2=84=20=EC=95=84=EC=9D=B4=EB=94=94?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B8=EC=9E=90=EB=A1=9C=20=EB=B0=9B=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EA=B3=B5=EC=97=B0?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...java => PerformanceManagementService.java} | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) rename src/main/java/com/beat/domain/performance/application/{PerformanceCreateService.java => PerformanceManagementService.java} (81%) diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceCreateService.java b/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java similarity index 81% rename from src/main/java/com/beat/domain/performance/application/PerformanceCreateService.java rename to src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java index 82e06031..e619f158 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceCreateService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java @@ -1,7 +1,11 @@ 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.member.dao.MemberRepository; +import com.beat.domain.member.domain.Member; +import com.beat.domain.member.exception.MemberErrorCode; import com.beat.domain.performance.application.dto.create.CastResponse; import com.beat.domain.performance.application.dto.create.PerformanceRequest; import com.beat.domain.performance.application.dto.create.PerformanceResponse; @@ -9,6 +13,7 @@ import com.beat.domain.performance.application.dto.create.StaffResponse; 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.staff.dao.StaffRepository; @@ -16,6 +21,7 @@ import com.beat.domain.user.dao.UserRepository; import com.beat.domain.user.domain.Users; import com.beat.domain.user.exception.UserErrorCode; +import com.beat.global.common.exception.BadRequestException; import com.beat.global.common.exception.NotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -28,18 +34,21 @@ @Service @RequiredArgsConstructor -public class PerformanceCreateService { +public class PerformanceManagementService { private final PerformanceRepository performanceRepository; private final ScheduleRepository scheduleRepository; - private final UserRepository userRepository; private final CastRepository castRepository; private final StaffRepository staffRepository; + private final BookingRepository bookingRepository; + private final MemberRepository memberRepository; @Transactional - public PerformanceResponse createPerformance(Long userId, PerformanceRequest request) { - Users user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND)); + public PerformanceResponse createPerformance(Long memberId, PerformanceRequest request) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND)); + + Users user = member.getUser(); Performance performance = Performance.create( request.performanceTitle(), @@ -152,4 +161,19 @@ private PerformanceResponse mapToPerformanceResponse(Performance performance, Li private int calculateDueDate(LocalDate performanceDate) { return (int) ChronoUnit.DAYS.between(LocalDate.now(), performanceDate); } + + @Transactional + public void deletePerformance(Long memberId, Long performanceId) { + memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND)); + + Performance performance = performanceRepository.findById(performanceId) + .orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND)); + + boolean hasBookings = bookingRepository.existsBySchedulePerformanceId(performanceId); + if (hasBookings) { + throw new BadRequestException(PerformanceErrorCode.PERFORMANCE_DELETE_FAILED); + } + + performanceRepository.delete(performance); + } } \ No newline at end of file From e4bb03cb2850decf8cdfbae09501e13107d54a5e Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Wed, 17 Jul 2024 23:29:52 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[#113]=20feat(PerformanceController):=20?= =?UTF-8?q?=EA=B3=B5=EC=97=B0=20=EC=82=AD=EC=A0=9C=20DELETE=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/PerformanceController.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 72c685d9..9cdf3171 100644 --- a/src/main/java/com/beat/domain/performance/api/PerformanceController.java +++ b/src/main/java/com/beat/domain/performance/api/PerformanceController.java @@ -1,6 +1,6 @@ package com.beat.domain.performance.api; -import com.beat.domain.performance.application.PerformanceCreateService; +import com.beat.domain.performance.application.PerformanceManagementService; import com.beat.domain.performance.application.dto.BookingPerformanceDetailResponse; import com.beat.domain.performance.application.dto.MakerPerformanceResponse; import com.beat.domain.performance.application.dto.PerformanceDetailResponse; @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -27,14 +28,14 @@ public class PerformanceController { private final PerformanceService performanceService; - private final PerformanceCreateService performanceCreateService; + private final PerformanceManagementService performanceManagementService; @Operation(summary = "공연 생성 API", description = "공연을 생성하는 POST API입니다.") @PostMapping public ResponseEntity> createPerformance( - @CurrentMember Long userId, + @CurrentMember Long memberId, @RequestBody PerformanceRequest performanceRequest) { - PerformanceResponse response = performanceCreateService.createPerformance(userId, performanceRequest); + PerformanceResponse response = performanceManagementService.createPerformance(memberId, performanceRequest); return ResponseEntity.status(HttpStatus.CREATED) .body(SuccessResponse.of(PerformanceSuccessCode.PERFORMANCE_CREATE_SUCCESS, response)); } @@ -61,4 +62,13 @@ public ResponseEntity> getUserPerforma MakerPerformanceResponse response = performanceService.getMemberPerformances(memberId); return ResponseEntity.ok(SuccessResponse.of(PerformanceSuccessCode.MAKER_PERFORMANCE_RETRIEVE_SUCCESS, response)); } -} + + @Operation(summary = "공연 삭제 API", description = "공연을 삭제하는 DELETE API입니다.") + @DeleteMapping("/{performanceId}") + public ResponseEntity> deletePerformance( + @CurrentMember Long memberId, + @PathVariable Long performanceId) { + performanceManagementService.deletePerformance(memberId, performanceId); + return ResponseEntity.ok(SuccessResponse.of(PerformanceSuccessCode.PERFORMANCE_DELETE_SUCCESS, null)); + } +} \ No newline at end of file