Skip to content

Commit

Permalink
[feat] #110 - 공연 수정 PUT API 구현 (#112)
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
hoonyworld authored Jul 17, 2024
1 parent 586f2a8 commit 3e74002
Show file tree
Hide file tree
Showing 18 changed files with 382 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/com/beat/domain/cast/domain/Cast.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public static Cast create(String castName, String castRole, String castPhoto, Pe
.performance(performance)
.build();
}

public void update(String castName, String castRole, String castPhoto) {
this.castName = castName;
this.castRole = castRole;
this.castPhoto = castPhoto;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/beat/domain/cast/exception/CastErrorCode.java
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;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.beat.domain.performance.api;

import com.beat.domain.performance.application.PerformanceCreateService;
import com.beat.domain.performance.application.PerformanceUpdateService;
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.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.exception.PerformanceSuccessCode;
import com.beat.domain.performance.application.PerformanceService;
import com.beat.global.auth.annotation.CurrentMember;
Expand All @@ -17,6 +20,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -28,6 +32,7 @@ public class PerformanceController {

private final PerformanceService performanceService;
private final PerformanceCreateService performanceCreateService;
private final PerformanceUpdateService performanceUpdateService;

@Operation(summary = "공연 생성 API", description = "공연을 생성하는 POST API입니다.")
@PostMapping
Expand All @@ -39,6 +44,16 @@ public ResponseEntity<SuccessResponse<PerformanceResponse>> createPerformance(
.body(SuccessResponse.of(PerformanceSuccessCode.PERFORMANCE_CREATE_SUCCESS, response));
}

@Operation(summary = "공연 정보 수정 API", description = "공연 정보를 수정하는 PUT API입니다.")
@PutMapping
public ResponseEntity<SuccessResponse<PerformanceUpdateResponse>> updatePerformance(
@CurrentMember Long memberId,
@RequestBody PerformanceUpdateRequest performanceUpdateRequest) {
PerformanceUpdateResponse response = performanceUpdateService.updatePerformance(memberId, performanceUpdateRequest);
return ResponseEntity.status(HttpStatus.OK)
.body(SuccessResponse.of(PerformanceSuccessCode.PERFORMANCE_UPDATE_SUCCESS, response));
}

@Operation(summary = "공연 상세정보 조회 API", description = "공연 상세페이지의 공연 상세정보를 조회하는 GET API입니다.")
@GetMapping("/detail/{performanceId}")
public ResponseEntity<SuccessResponse<PerformanceDetailResponse>> getPerformanceDetail(
Expand Down
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());
}
}
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
) {}
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);
}
}
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
) {}
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);
}
}
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
) {}
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);
}
}
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
) {}
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);
}
}
Loading

0 comments on commit 3e74002

Please sign in to comment.