Skip to content

Commit

Permalink
[#177] refactor(PerformanceUpdateService): 해당 공연의 메이커만 공연 수정이 가능하도록 검…
Browse files Browse the repository at this point in the history
…증하는 메서드 추가
  • Loading branch information
hoonyworld committed Aug 21, 2024
1 parent 65cc779 commit cce415f
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -34,6 +35,7 @@
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;
Expand Down Expand Up @@ -61,10 +63,13 @@ public class PerformanceUpdateService {
public PerformanceUpdateResponse updatePerformance(Long memberId, PerformanceUpdateRequest request) {
log.info("Starting updatePerformance for memberId: {}, performanceId: {}", memberId, request.performanceId());

validateMember(memberId);
Member member = validateMember(memberId);
Long userId = member.getUser().getId();

Performance performance = findPerformance(request.performanceId());

validateOwnership(userId, performance);

updatePerformanceDetails(performance, request);

List<ScheduleDeleteResponse> deletedSchedules = deleteSchedules(request.scheduleDeleteRequests());
Expand All @@ -87,9 +92,9 @@ public PerformanceUpdateResponse updatePerformance(Long memberId, PerformanceUpd
return response;
}

private void validateMember(Long memberId) {
private Member validateMember(Long memberId) {
log.debug("Validating memberId: {}", memberId);
memberRepository.findById(memberId)
return memberRepository.findById(memberId)
.orElseThrow(() -> {
log.error("Member not found: memberId: {}", memberId);
return new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND);
Expand All @@ -105,6 +110,13 @@ private Performance findPerformance(Long performanceId) {
});
}

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) {
log.debug("Updating performance details for performanceId: {}", performance.getId());
performance.update(
Expand Down

0 comments on commit cce415f

Please sign in to comment.