From 3676e206c463a832f38cc9b3aceb3cb4bb6d2216 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Mon, 4 Nov 2024 16:47:22 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[#243]=20feat(PerformanceErrorCode):=20sche?= =?UTF-8?q?dulelist=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C,=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/PerformanceErrorCode.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 8e4f3a0..30ace89 100644 --- a/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java +++ b/src/main/java/com/beat/domain/performance/exception/PerformanceErrorCode.java @@ -8,22 +8,25 @@ @Getter @RequiredArgsConstructor public enum PerformanceErrorCode implements BaseErrorCode { - PERFORMANCE_NOT_FOUND(404, "해당 공연 정보를 찾을 수 없습니다."), REQUIRED_DATA_MISSING(400, "필수 데이터가 누락되었습니다."), INVALID_DATA_FORMAT(400, "잘못된 데이터 형식입니다."), INVALID_REQUEST_FORMAT(400, "잘못된 요청 형식입니다."), PRICE_UPDATE_NOT_ALLOWED(400, "예매자가 존재하여 가격을 수정할 수 없습니다."), NEGATIVE_TICKET_PRICE(400, "티켓 가격은 음수일 수 없습니다."), - NO_PERFORMANCE_FOUND(404, "공연을 찾을 수 없습니다."), - PERFORMANCE_DELETE_FAILED(403, "예매자가 1명 이상 있을 경우, 공연을 삭제할 수 없습니다."), - NOT_PERFORMANCE_OWNER(403, "해당 공연의 메이커가 아닙니다."), MAX_SCHEDULE_LIMIT_EXCEEDED(400, "공연 회차는 최대 10개까지 추가할 수 있습니다."), INVALID_PERFORMANCE_DESCRIPTION_LENGTH(400, "공연 소개 글자수가 500자를 초과했습니다."), INVALID_ATTENTION_NOTE_LENGTH(400, "공연 유의사항 글자수가 500자를 초과했습니다."), - INTERNAL_SERVER_ERROR(500, "서버 내부 오류입니다."), PAST_SCHEDULE_NOT_ALLOWED(400, "과거 날짜 회차를 포함한 공연을 생성할 수 없습니다."), SCHEDULE_MODIFICATION_NOT_ALLOWED_FOR_ENDED_SCHEDULE(400, "종료된 회차를 수정할 수 없습니다."), - INVALID_TICKET_COUNT(400, "판매된 티켓 수보다 적은 수로 판매할 티켓 매수를 수정할 수 없습니다."); + INVALID_TICKET_COUNT(400, "판매된 티켓 수보다 적은 수로 판매할 티켓 매수를 수정할 수 없습니다."), + + PERFORMANCE_DELETE_FAILED(403, "예매자가 1명 이상 있을 경우, 공연을 삭제할 수 없습니다."), + NOT_PERFORMANCE_OWNER(403, "해당 공연의 메이커가 아닙니다."), + + PERFORMANCE_NOT_FOUND(404, "해당 공연 정보를 찾을 수 없습니다."), + SCHEDULE_LIST_NOT_FOUND(404, "스케쥴 리스트에 스케쥴이 없습니다."), + + INTERNAL_SERVER_ERROR(500, "서버 내부 오류입니다."); private final int status; private final String message; From 238fdcdc9315468e101215bc153e3237b40ae110 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Mon, 4 Nov 2024 16:49:43 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#243]=20feat(Performance):=20updatePerform?= =?UTF-8?q?ancePeriod,=20assignScheduleNumbers=20=EB=A1=9C=EC=A7=81=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 --- .../performance/domain/Performance.java | 331 ++++++++++-------- 1 file changed, 191 insertions(+), 140 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/domain/Performance.java b/src/main/java/com/beat/domain/performance/domain/Performance.java index 8ba1af3..fa4368a 100644 --- a/src/main/java/com/beat/domain/performance/domain/Performance.java +++ b/src/main/java/com/beat/domain/performance/domain/Performance.java @@ -1,158 +1,209 @@ package com.beat.domain.performance.domain; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + import com.beat.domain.BaseTimeEntity; import com.beat.domain.performance.exception.PerformanceErrorCode; import com.beat.domain.promotion.domain.Promotion; +import com.beat.domain.schedule.domain.Schedule; +import com.beat.domain.schedule.domain.ScheduleNumber; import com.beat.domain.user.domain.Users; import com.beat.global.common.exception.BadRequestException; -import jakarta.persistence.*; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; - -import java.util.ArrayList; -import java.util.List; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Performance extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - private String performanceTitle; - - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private Genre genre; - - @Column(nullable = false) - private int runningTime; - - @Column(nullable = false, length = 500) - private String performanceDescription; - - @Column(nullable = false, length = 500) - private String performanceAttentionNote; - - @Enumerated(EnumType.STRING) - @Column(nullable = true) - private BankName bankName; - - @Column(nullable = true) - private String accountNumber; - - @Column(nullable = true) - private String accountHolder; - - @Column(nullable = false) - private String posterImage; - - @Column(nullable = false) - private String performanceTeamName; - - @Column(nullable = false) - private String performanceVenue; - - @Column(nullable = false) - private String performanceContact; - - @Column(nullable = false) - private String performancePeriod; - - @Column(nullable = false) - private int ticketPrice = 0; - - @Column(nullable = false) - private int totalScheduleCount; - - @OneToMany(mappedBy = "performance", cascade = CascadeType.ALL, orphanRemoval = true) - private List promotions = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private Users users; - - @OneToMany(mappedBy = "performance", cascade = CascadeType.ALL, orphanRemoval = true) - private List performanceImageList = new ArrayList<>(); - - @Builder - public Performance(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, Users users) { - this.performanceTitle = performanceTitle; - this.genre = genre; - this.runningTime = runningTime; - this.performanceDescription = performanceDescription; - this.performanceAttentionNote = performanceAttentionNote; - this.bankName = bankName; - this.accountNumber = accountNumber; - this.accountHolder = accountHolder; - this.posterImage = posterImage; - this.performanceTeamName = performanceTeamName; - this.performanceVenue = performanceVenue; - this.performanceContact = performanceContact; - this.performancePeriod = performancePeriod; - this.ticketPrice = ticketPrice; - this.totalScheduleCount = totalScheduleCount; - this.users = users; - } - - public static Performance create( - 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, Users users) { - return Performance.builder() - .performanceTitle(performanceTitle) - .genre(genre) - .runningTime(runningTime) - .performanceDescription(performanceDescription) - .performanceAttentionNote(performanceAttentionNote) - .bankName(bankName) - .accountNumber(accountNumber) - .accountHolder(accountHolder) - .posterImage(posterImage) - .performanceTeamName(performanceTeamName) - .performanceVenue(performanceVenue) - .performanceContact(performanceContact) - .performancePeriod(performancePeriod) - .ticketPrice(ticketPrice) - .totalScheduleCount(totalScheduleCount) - .users(users) - .build(); - } - - public void update( - 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) { - this.performanceTitle = performanceTitle; - this.genre = genre; - this.runningTime = runningTime; - this.performanceDescription = performanceDescription; - this.performanceAttentionNote = performanceAttentionNote; - this.bankName = bankName; - this.accountNumber = accountNumber; - this.accountHolder = accountHolder; - this.posterImage = posterImage; - this.performanceTeamName = performanceTeamName; - this.performanceVenue = performanceVenue; - this.performanceContact = performanceContact; - this.performancePeriod = performancePeriod; - this.totalScheduleCount = totalScheduleCount; - } - - public void updateTicketPrice(int newTicketPrice) { - if (newTicketPrice < 0) { - throw new BadRequestException(PerformanceErrorCode.NEGATIVE_TICKET_PRICE); - } - this.ticketPrice = newTicketPrice; - } + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String performanceTitle; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private Genre genre; + + @Column(nullable = false) + private int runningTime; + + @Column(nullable = false, length = 500) + private String performanceDescription; + + @Column(nullable = false, length = 500) + private String performanceAttentionNote; + + @Enumerated(EnumType.STRING) + @Column(nullable = true) + private BankName bankName; + + @Column(nullable = true) + private String accountNumber; + + @Column(nullable = true) + private String accountHolder; + + @Column(nullable = false) + private String posterImage; + + @Column(nullable = false) + private String performanceTeamName; + + @Column(nullable = false) + private String performanceVenue; + + @Column(nullable = false) + private String performanceContact; + + @Column(nullable = false) + private String performancePeriod; + + @Column(nullable = false) + private int ticketPrice = 0; + + @Column(nullable = false) + private int totalScheduleCount; + + @OneToMany(mappedBy = "performance", cascade = CascadeType.ALL, orphanRemoval = true) + private List promotions = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) + private Users users; + + @OneToMany(mappedBy = "performance", cascade = CascadeType.ALL, orphanRemoval = true) + private List performanceImageList = new ArrayList<>(); + + @Builder + public Performance(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, Users users) { + this.performanceTitle = performanceTitle; + this.genre = genre; + this.runningTime = runningTime; + this.performanceDescription = performanceDescription; + this.performanceAttentionNote = performanceAttentionNote; + this.bankName = bankName; + this.accountNumber = accountNumber; + this.accountHolder = accountHolder; + this.posterImage = posterImage; + this.performanceTeamName = performanceTeamName; + this.performanceVenue = performanceVenue; + this.performanceContact = performanceContact; + this.performancePeriod = performancePeriod; + this.ticketPrice = ticketPrice; + this.totalScheduleCount = totalScheduleCount; + this.users = users; + } + + public static Performance create( + 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, Users users) { + return Performance.builder() + .performanceTitle(performanceTitle) + .genre(genre) + .runningTime(runningTime) + .performanceDescription(performanceDescription) + .performanceAttentionNote(performanceAttentionNote) + .bankName(bankName) + .accountNumber(accountNumber) + .accountHolder(accountHolder) + .posterImage(posterImage) + .performanceTeamName(performanceTeamName) + .performanceVenue(performanceVenue) + .performanceContact(performanceContact) + .performancePeriod(performancePeriod) + .ticketPrice(ticketPrice) + .totalScheduleCount(totalScheduleCount) + .users(users) + .build(); + } + + public void update( + 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) { + this.performanceTitle = performanceTitle; + this.genre = genre; + this.runningTime = runningTime; + this.performanceDescription = performanceDescription; + this.performanceAttentionNote = performanceAttentionNote; + this.bankName = bankName; + this.accountNumber = accountNumber; + this.accountHolder = accountHolder; + this.posterImage = posterImage; + this.performanceTeamName = performanceTeamName; + this.performanceVenue = performanceVenue; + this.performanceContact = performanceContact; + this.performancePeriod = performancePeriod; + this.totalScheduleCount = totalScheduleCount; + } + + public void updateTicketPrice(int newTicketPrice) { + if (newTicketPrice < 0) { + throw new BadRequestException(PerformanceErrorCode.NEGATIVE_TICKET_PRICE); + } + this.ticketPrice = newTicketPrice; + } + + public void updatePerformancePeriod(List performanceDates) { + if (performanceDates.isEmpty()) { + throw new BadRequestException(PerformanceErrorCode.SCHEDULE_LIST_NOT_FOUND); + } + + LocalDateTime startDate = performanceDates.stream().min(Comparator.naturalOrder()).get(); + LocalDateTime endDate = performanceDates.stream().max(Comparator.naturalOrder()).get(); + + this.performancePeriod = formatPerformancePeriod(startDate, endDate); + } + + private String formatPerformancePeriod(LocalDateTime startDate, LocalDateTime endDate) { + if (startDate.toLocalDate().equals(endDate.toLocalDate())) { + return startDate.toLocalDate().toString().replace("-", "."); + } else { + return startDate.toLocalDate().toString().replace("-", ".") + + "~" + endDate.toLocalDate().toString().replace("-", "."); + } + } + + public 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).setScheduleNumber(scheduleNumber); + } + } } \ No newline at end of file From 0a3479ba02bbd5885c7f8425fa9c28fb445ad279 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Mon, 4 Nov 2024 16:50:51 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[#243]=20refactor(PerformanceManagementServ?= =?UTF-8?q?ice):=20=EA=B3=B5=EC=97=B0=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20u?= =?UTF-8?q?pdatePerformancePeriod,=20assignScheduleNumbers=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/PerformanceManagementService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java b/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java index 289a77a..ccc2a8d 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceManagementService.java @@ -79,7 +79,7 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r request.performanceTeamName(), request.performanceVenue(), request.performanceContact(), - request.performancePeriod(), + " ", request.ticketPrice(), request.totalScheduleCount(), user @@ -101,10 +101,18 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r ); }) .collect(Collectors.toList()); + + performance.assignScheduleNumbers(schedules); scheduleRepository.saveAll(schedules); schedules.forEach(jobSchedulerService::addScheduleIfNotExists); + List performanceDates = schedules.stream() + .map(Schedule::getPerformanceDate) + .collect(Collectors.toList()); + performance.updatePerformancePeriod(performanceDates); + performanceRepository.save(performance); + List casts = request.castList().stream() .map(castRequest -> Cast.create( castRequest.castName(), From 88b97b7f953cb57d77b1410d75b2e66bada0b180 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Mon, 4 Nov 2024 16:51:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[#243]=20fix(PerformanceModifyService):=20?= =?UTF-8?q?=EA=B3=B5=EC=97=B0=20=ED=9A=8C=EC=B0=A8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=8B=9C=20updatePerformancePeriod,=20assignScheduleNumbers=20?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/PerformanceModifyService.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java b/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java index 48db2f4..60a5342 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceModifyService.java @@ -3,7 +3,6 @@ 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; @@ -144,6 +143,11 @@ private void updatePerformanceDetails(Performance performance, PerformanceModify request.totalScheduleCount() ); + List performanceDates = request.scheduleModifyRequests().stream() + .map(ScheduleModifyRequest::performanceDate) + .collect(Collectors.toList()); + performance.updatePerformancePeriod(performanceDates); + if (!isBookerExist) { log.debug("Updating ticket price to {}", request.ticketPrice()); performance.updateTicketPrice(request.ticketPrice()); @@ -186,7 +190,7 @@ private List processSchedules(List ScheduleModifyResponse.of( @@ -199,15 +203,6 @@ private List processSchedules(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());