diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java b/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java index 9e3b3749..0832f634 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceUpdateService.java @@ -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; @@ -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; @@ -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 deletedSchedules = deleteSchedules(request.scheduleDeleteRequests()); @@ -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); @@ -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(