Skip to content

Commit

Permalink
Merge pull request #274 from 9oormthon-univ/fix/#273
Browse files Browse the repository at this point in the history
fix: schedule 검증 로직 추가
  • Loading branch information
koosco authored Dec 6, 2024
2 parents 7586652 + ab251ab commit 77d1e93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetScheduleResponseDto> scheduleResponseDtoList =
scheduleRepository.findAllByMonthAndMemberId(memberId, month, year).stream()
.map(schedule -> GetScheduleResponseDto.fromSchedule(schedule))
.map(GetScheduleResponseDto::fromSchedule)
.toList();

List<GetQuestResponseDto> questResponseDtoList =
questRepository.findAllByMonthAndMemberId(memberId, month, year).stream()
.map(quest -> GetQuestResponseDto.fromQuest(quest))
.map(GetQuestResponseDto::fromQuest)
.toList();

return GetCalendarResponseDto.fromCalendarList(questResponseDtoList, scheduleResponseDtoList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public ResponseDto<CommonSuccessDto> 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<CommonSuccessDto> deleteSchedule(
@AuthMember Long memberId, @PathVariable Long scheduleId) {
return ResponseDto.ok(scheduleCommandService.deleteSchedule(scheduleId));
return ResponseDto.ok(scheduleCommandService.deleteSchedule(memberId, scheduleId));
}
}

0 comments on commit 77d1e93

Please sign in to comment.