Skip to content

Commit

Permalink
Merge pull request #145 from dnd-side-project/fix/#142-schedule
Browse files Browse the repository at this point in the history
[Fix] 일정 수정 오류
  • Loading branch information
f1v3-dev authored Oct 21, 2024
2 parents 6d96441 + e7cbbbe commit 4da804b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,40 @@ public class DateOfScheduleService {
* @param requestDto 일정 날짜 생성 요청 DTO
*/
@Transactional
public void createDateOfSchedule(Long scheduleId, DateOfScheduleCreateRequestDto requestDto) {
public void createDateOfSchedule(Long scheduleId, List<DateOfScheduleCreateRequestDto> requestDto) {

Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(ScheduleNotFoundException::new);

validateDateOfSchedule(schedule, requestDto);

LocalDateTime startTime = requestDto.getStartTime();
LocalDateTime endTime = requestDto.getEndTime();
requestDto.forEach(dto -> {

// TODO : rank 값을 추후에 변경해야 함.
Integer rank = 1;
LocalDateTime startTime = dto.getStartTime();
LocalDateTime endTime = dto.getEndTime();

Duration interval = Duration.ofHours(1);
while (startTime.isBefore(endTime)) {
LocalDateTime nextEndTime = startTime.plus(interval);
Duration interval = Duration.ofHours(1);
while (startTime.isBefore(endTime)) {
LocalDateTime nextEndTime = startTime.plus(interval);

if (nextEndTime.isAfter(endTime)) {
nextEndTime = endTime;
}
if (nextEndTime.isAfter(endTime)) {
nextEndTime = endTime;
}

DateOfSchedule dateOfSchedule = DateOfSchedule.builder()
.schedule(schedule)
.dateOfScheduleStart(startTime)
.dateOfScheduleEnd(nextEndTime)
.dateOfScheduleRank(rank)
.build();
DateOfSchedule dateOfSchedule = DateOfSchedule.builder()
.schedule(schedule)
.dateOfScheduleStart(startTime)
.dateOfScheduleEnd(nextEndTime)
.dateOfScheduleRank(1)
.build();

dateOfScheduleRepository.save(dateOfSchedule);
dateOfScheduleRepository.save(dateOfSchedule);

startTime = nextEndTime;
}
startTime = nextEndTime;
}
});
}

private void validateDateOfSchedule(Schedule schedule, DateOfScheduleCreateRequestDto requestDto) {
Meeting meeting = schedule.getMeeting();
LocalDate meetingStartDate = meeting.getMeetingStartDate();
LocalDate meetingEndDate = meeting.getMeetingEndDate();

LocalDateTime startTime = requestDto.getStartTime();
LocalDateTime endTime = requestDto.getEndTime();

if (startTime.toLocalDate().isBefore(meetingStartDate) || endTime.toLocalDate().isAfter(meetingEndDate)) {
throw new ScheduleDateOutOfMeetingDateException();
}
}

/**
* 일정 날짜 리스트를 업데이트하는 메서드입니다. (모든 일정 날짜 삭제 후 새로 생성)
Expand All @@ -98,17 +86,49 @@ public void updateDateList(Long scheduleId, List<DateOfScheduleCreateRequestDto>
Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(ScheduleNotFoundException::new);

// dateOfSchedule 생성
validateDateOfSchedule(schedule, requestDto);

// TODO: rank 값 추후에 변경해줘야 함!
requestDto.forEach(dto -> {
DateOfSchedule dateOfSchedule = DateOfSchedule.builder()
.schedule(schedule)
.dateOfScheduleStart(dto.getStartTime())
.dateOfScheduleEnd(dto.getEndTime())
.dateOfScheduleRank(1)
.build();

dateOfScheduleRepository.save(dateOfSchedule);

LocalDateTime startTime = dto.getStartTime();
LocalDateTime endTime = dto.getEndTime();

Duration interval = Duration.ofHours(1);
while (startTime.isBefore(endTime)) {
LocalDateTime nextEndTime = startTime.plus(interval);

if (nextEndTime.isAfter(endTime)) {
nextEndTime = endTime;
}

DateOfSchedule dateOfSchedule = DateOfSchedule.builder()
.schedule(schedule)
.dateOfScheduleStart(startTime)
.dateOfScheduleEnd(nextEndTime)
.dateOfScheduleRank(1)
.build();

dateOfScheduleRepository.save(dateOfSchedule);

startTime = nextEndTime;
}
});
}

private void validateDateOfSchedule(Schedule schedule, List<DateOfScheduleCreateRequestDto> requestDtos) {
Meeting meeting = schedule.getMeeting();
LocalDate meetingStartDate = meeting.getMeetingStartDate();
LocalDate meetingEndDate = meeting.getMeetingEndDate();

for (DateOfScheduleCreateRequestDto requestDto : requestDtos) {

LocalDateTime startTime = requestDto.getStartTime();
LocalDateTime endTime = requestDto.getEndTime();

if (startTime.toLocalDate().isBefore(meetingStartDate) || endTime.toLocalDate().isAfter(meetingEndDate)) {
throw new ScheduleDateOutOfMeetingDateException();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dnd.jjakkak.domain.schedule.service;

import com.dnd.jjakkak.domain.dateofschedule.dto.request.DateOfScheduleCreateRequestDto;
import com.dnd.jjakkak.domain.dateofschedule.service.DateOfScheduleService;
import com.dnd.jjakkak.domain.meeting.entity.Meeting;
import com.dnd.jjakkak.domain.meeting.exception.MeetingAlreadyEndedException;
Expand Down Expand Up @@ -272,12 +271,7 @@ private void validateAndAssignSchedule(ScheduleAssignRequestDto requestDto, Sche
// 닉네임 변경
schedule.updateScheduleNickname(requestDto.getNickname() == null ? schedule.getScheduleNickname() : requestDto.getNickname());

// 일정 날짜 저장
for (DateOfScheduleCreateRequestDto dateOfScheduleCreateRequestDto : requestDto.getDateOfScheduleList()) {
dateOfScheduleService.createDateOfSchedule(schedule.getScheduleId(), dateOfScheduleCreateRequestDto);
}

// isAssigned -> true
dateOfScheduleService.createDateOfSchedule(schedule.getScheduleId(), requestDto.getDateOfScheduleList());
schedule.scheduleAssign();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void assign_schedule_to_guest_success() {
// then
verify(scheduleRepository, times(1)).findNotAssignedScheduleByMeetingUuid(MEETING_UUID);
verify(meetingRepository, times(1)).checkMeetingFull(any());
verify(dateOfScheduleService, times(2)).createDateOfSchedule(anyLong(), any());
verify(dateOfScheduleService, times(1)).createDateOfSchedule(anyLong(), any());
}

@Test
Expand Down Expand Up @@ -253,7 +253,7 @@ void assign_schedule_to_member_success() {
// then
verify(scheduleRepository, times(1)).findNotAssignedScheduleByMeetingUuid(MEETING_UUID);
verify(meetingRepository, times(1)).checkMeetingFull(any());
verify(dateOfScheduleService, times(2)).createDateOfSchedule(anyLong(), any());
verify(dateOfScheduleService, times(1)).createDateOfSchedule(anyLong(), any());
verify(meetingMemberService, times(1)).createMeetingMemberBySchedule(anyLong(), anyLong());
}

Expand Down

0 comments on commit 4da804b

Please sign in to comment.