diff --git a/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java b/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java index fa2e6a0..49c88e7 100644 --- a/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java +++ b/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java @@ -22,7 +22,6 @@ public class ScheduleCommandService { private final MemberQueryService memberQueryService; public CommonSuccessDto createSchedule(Long memberId, ScheduleRequestDto requestDto) { - Member member = memberQueryService.findMember(memberId); Schedule schedule = @@ -38,19 +37,24 @@ public CommonSuccessDto createSchedule(Long memberId, ScheduleRequestDto request return CommonSuccessDto.fromEntity(true); } - public CommonSuccessDto updateSchedule(Long scheduleId, ScheduleRequestDto requestDto) { - - Schedule schedule = scheduleQueryService.findById(scheduleId); + public CommonSuccessDto updateSchedule( + Long memberId, Long scheduleId, ScheduleRequestDto requestDto) { + Schedule schedule = scheduleQueryService.findSchedule(scheduleId); + Member member = schedule.getMember(); + member.validateId(memberId); schedule.updateSchedule(requestDto); - scheduleRepository.save(schedule); - return CommonSuccessDto.fromEntity(true); } - public CommonSuccessDto deleteSchedule(Long scheduleId) { + public CommonSuccessDto deleteSchedule(Long memberId, Long scheduleId) { + Schedule schedule = scheduleQueryService.findSchedule(scheduleId); + Member member = schedule.getMember(); + member.validateId(memberId); + scheduleRepository.deleteById(scheduleId); + return CommonSuccessDto.fromEntity(true); } } diff --git a/src/main/java/com/groom/orbit/schedule/app/ScheduleQueryService.java b/src/main/java/com/groom/orbit/schedule/app/ScheduleQueryService.java index 7a5e4f0..a3ef542 100644 --- a/src/main/java/com/groom/orbit/schedule/app/ScheduleQueryService.java +++ b/src/main/java/com/groom/orbit/schedule/app/ScheduleQueryService.java @@ -24,22 +24,21 @@ public class ScheduleQueryService { private final ScheduleRepository scheduleRepository; private final QuestRepository questRepository; - public Schedule findById(Long scheduleId) { + public Schedule findSchedule(Long scheduleId) { return scheduleRepository .findById(scheduleId) .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_SCHEDULE)); } public GetCalendarResponseDto getCalendar(Long memberId, Integer month, Integer year) { - List scheduleResponseDtoList = scheduleRepository.findAllByMonthAndMemberId(memberId, month, year).stream() - .map(schedule -> GetScheduleResponseDto.fromSchedule(schedule)) + .map(GetScheduleResponseDto::fromSchedule) .toList(); List questResponseDtoList = questRepository.findAllByMonthAndMemberId(memberId, month, year).stream() - .map(quest -> GetQuestResponseDto.fromQuest(quest)) + .map(GetQuestResponseDto::fromQuest) .toList(); return GetCalendarResponseDto.fromCalendarList(questResponseDtoList, scheduleResponseDtoList); diff --git a/src/main/java/com/groom/orbit/schedule/controller/ScheduleCommandController.java b/src/main/java/com/groom/orbit/schedule/controller/ScheduleCommandController.java index 0b4c9da..e3dcf60 100644 --- a/src/main/java/com/groom/orbit/schedule/controller/ScheduleCommandController.java +++ b/src/main/java/com/groom/orbit/schedule/controller/ScheduleCommandController.java @@ -28,12 +28,13 @@ public ResponseDto updateSchedule( @AuthMember Long memberId, @PathVariable Long scheduleId, @RequestBody ScheduleRequestDto scheduleRequestDto) { - return ResponseDto.ok(scheduleCommandService.updateSchedule(scheduleId, scheduleRequestDto)); + return ResponseDto.ok( + scheduleCommandService.updateSchedule(memberId, scheduleId, scheduleRequestDto)); } @DeleteMapping("/{scheduleId}") public ResponseDto deleteSchedule( @AuthMember Long memberId, @PathVariable Long scheduleId) { - return ResponseDto.ok(scheduleCommandService.deleteSchedule(scheduleId)); + return ResponseDto.ok(scheduleCommandService.deleteSchedule(memberId, scheduleId)); } }