-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#110] feat: request DTO 생성 * [#110] feat: response DTO 생성 * [#110] feat(CastErrorCode): 등장인물 열거형 생성 * [#110] feat(StaffErrorCode): 스태프 에러 열거형 생성 * [#110] refactor(PerformanceSuccessCode): 공연 성공 수정 메시지 추가 * [#110] refactor(Performance): 업데이트 메서드 추가 * [#110] refactor(Schedule): 업데이트 메서드 추가 * [#110] refactor(Staff): 업데이트 메서드 추가 * [#110] test(GuestBookingServiceConcurrencyTest): 변경된 필드 추가 * [#110] refactor(Cast): 업데이트 메서드 추 * [#110] feat(PerformanceUpdateService): 공연 수정 서비스 로직 구현 * [#110] feat(PerformanceController): 공연 수정 PUT API 추가
- Loading branch information
1 parent
586f2a8
commit 3e74002
Showing
18 changed files
with
382 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/beat/domain/cast/exception/CastErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.beat.domain.cast.exception; | ||
|
||
import com.beat.global.common.exception.base.BaseErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum CastErrorCode implements BaseErrorCode { | ||
CAST_NOT_FOUND(404, "등장인물이 존재하지 않습니다.") | ||
; | ||
|
||
private final int status; | ||
private final String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package com.beat.domain.performance.application; | ||
|
||
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.exception.MemberErrorCode; | ||
import com.beat.domain.performance.application.dto.update.*; | ||
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.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
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; | ||
|
||
@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; | ||
|
||
@Transactional | ||
public PerformanceUpdateResponse updatePerformance(Long memberId, PerformanceUpdateRequest request) { | ||
memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND)); | ||
|
||
Performance performance = performanceRepository.findById(request.performanceId()) | ||
.orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND)); | ||
|
||
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() | ||
); | ||
performanceRepository.save(performance); | ||
|
||
List<Schedule> schedules = request.scheduleList().stream() | ||
.map(scheduleRequest -> { | ||
Schedule schedule = scheduleRepository.findById(scheduleRequest.scheduleId()) | ||
.orElseThrow(() -> new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND)); | ||
schedule.update( | ||
scheduleRequest.performanceDate(), | ||
scheduleRequest.totalTicketCount(), | ||
ScheduleNumber.valueOf(scheduleRequest.scheduleNumber()) | ||
); | ||
return schedule; | ||
}) | ||
.collect(Collectors.toList()); | ||
scheduleRepository.saveAll(schedules); | ||
|
||
List<Cast> casts = request.castList().stream() | ||
.map(castRequest -> { | ||
Cast cast = castRepository.findById(castRequest.castId()) | ||
.orElseThrow(() -> new NotFoundException(CastErrorCode.CAST_NOT_FOUND)); | ||
cast.update( | ||
castRequest.castName(), | ||
castRequest.castRole(), | ||
castRequest.castPhoto() | ||
); | ||
return cast; | ||
}) | ||
.collect(Collectors.toList()); | ||
castRepository.saveAll(casts); | ||
|
||
List<Staff> staffs = request.staffList().stream() | ||
.map(staffRequest -> { | ||
Staff staff = staffRepository.findById(staffRequest.staffId()) | ||
.orElseThrow(() -> new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND)); | ||
staff.update( | ||
staffRequest.staffName(), | ||
staffRequest.staffRole(), | ||
staffRequest.staffPhoto() | ||
); | ||
return staff; | ||
}) | ||
.collect(Collectors.toList()); | ||
staffRepository.saveAll(staffs); | ||
|
||
return mapToPerformanceResponse(performance, schedules, casts, staffs); | ||
} | ||
|
||
private PerformanceUpdateResponse mapToPerformanceResponse(Performance performance, List<Schedule> schedules, List<Cast> casts, List<Staff> staffs) { | ||
List<ScheduleUpdateResponse> scheduleResponses = schedules.stream() | ||
.map(schedule -> ScheduleUpdateResponse.of( | ||
schedule.getId(), | ||
schedule.getPerformanceDate(), | ||
schedule.getTotalTicketCount(), | ||
calculateDueDate(schedule.getPerformanceDate()), | ||
schedule.getScheduleNumber() | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
List<CastUpdateResponse> castResponses = casts.stream() | ||
.map(cast -> CastUpdateResponse.of( | ||
cast.getId(), | ||
cast.getCastName(), | ||
cast.getCastRole(), | ||
cast.getCastPhoto() | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
List<StaffUpdateResponse> staffResponses = staffs.stream() | ||
.map(staff -> StaffUpdateResponse.of( | ||
staff.getId(), | ||
staff.getStaffName(), | ||
staff.getStaffRole(), | ||
staff.getStaffPhoto() | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
return 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(), | ||
scheduleResponses, | ||
castResponses, | ||
staffResponses | ||
); | ||
} | ||
|
||
private int calculateDueDate(LocalDateTime performanceDate) { | ||
return (int) ChronoUnit.DAYS.between(LocalDate.now(), performanceDate.toLocalDate()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/beat/domain/performance/application/dto/update/CastUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
public record CastUpdateRequest( | ||
Long castId, | ||
String castName, | ||
String castRole, | ||
String castPhoto | ||
) {} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/beat/domain/performance/application/dto/update/CastUpdateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ain/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
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, | ||
List<ScheduleUpdateRequest> scheduleList, | ||
List<CastUpdateRequest> castList, | ||
List<StaffUpdateRequest> staffList | ||
) {} |
37 changes: 37 additions & 0 deletions
37
...in/java/com/beat/domain/performance/application/dto/update/PerformanceUpdateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
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<ScheduleUpdateResponse> scheduleList, | ||
List<CastUpdateResponse> castList, | ||
List<StaffUpdateResponse> staffList | ||
) { | ||
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<ScheduleUpdateResponse> scheduleList, List<CastUpdateResponse> castList, List<StaffUpdateResponse> staffList) { | ||
return new PerformanceUpdateResponse(userId, performanceId, performanceTitle, genre, runningTime, performanceDescription, performanceAttentionNote, bankName, accountNumber, | ||
accountHolder, posterImage, performanceTeamName, performanceVenue, performanceContact, performancePeriod, ticketPrice, totalScheduleCount, scheduleList, castList, staffList); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/beat/domain/performance/application/dto/update/ScheduleUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ScheduleUpdateRequest( | ||
Long scheduleId, | ||
LocalDateTime performanceDate, | ||
int totalTicketCount, | ||
String scheduleNumber | ||
) {} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/beat/domain/performance/application/dto/update/ScheduleUpdateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
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); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/beat/domain/performance/application/dto/update/StaffUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
public record StaffUpdateRequest( | ||
Long staffId, | ||
String staffName, | ||
String staffRole, | ||
String staffPhoto | ||
) {} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/beat/domain/performance/application/dto/update/StaffUpdateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.beat.domain.performance.application.dto.update; | ||
|
||
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); | ||
} | ||
} |
Oops, something went wrong.