Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Schedule 도메인의 반복 일정과 관련된 필드값을 Embedded로 분리 #70

Merged
merged 5 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.wypl.googleoauthclient.domain.AuthMember;
import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacalendardomain.calendar.domain.MemberCalendar;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.calendar.repository.ScheduleRepository;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.reopository.ScheduleRepository;
import com.wypl.jpamemberdomain.member.domain.Member;
import com.wypl.wyplcore.calendar.data.DateSearchCondition;
import com.wypl.wyplcore.calendar.data.request.CalendarFindRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.jpamongoreviewdomain.review.domain.Review;
import com.wypl.jpamongoreviewdomain.reviewcontents.domain.ReviewContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.jpamemberdomain.member.domain.Member;
import com.wypl.jpamongoreviewdomain.review.domain.Review;
import com.wypl.jpamongoreviewdomain.review.repository.ReviewRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wypl.jpacalendardomain.calendar.data.ConvertibleSchedule;
import com.wypl.jpacalendardomain.calendar.data.RepetitionCycle;
import com.wypl.jpacalendardomain.schedule.data.ConvertibleSchedule;
import com.wypl.jpacalendardomain.schedule.domain.embedded.RepetitionCycle;

import lombok.Builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;

public record ScheduleFindResponse(

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import com.wypl.googleoauthclient.domain.AuthMember;
import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.calendar.mapper.ScheduleInfoMapper;
import com.wypl.jpacalendardomain.calendar.mapper.ScheduleMapper;
import com.wypl.jpacalendardomain.calendar.repository.ScheduleInfoRepository;
import com.wypl.jpacalendardomain.calendar.repository.ScheduleRepository;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.schedule.mapper.ScheduleInfoMapper;
import com.wypl.jpacalendardomain.schedule.mapper.ScheduleMapper;
import com.wypl.jpacalendardomain.schedule.reopository.ScheduleInfoRepository;
import com.wypl.jpacalendardomain.schedule.reopository.ScheduleRepository;
import com.wypl.jpamemberdomain.member.domain.Member;
import com.wypl.wyplcore.schedule.data.request.ScheduleCreateRequest;
import com.wypl.wyplcore.schedule.data.response.ScheduleInfoCreateResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDate;
import java.util.List;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;
import com.wypl.wyplcore.schedule.service.repetition.strategy.RepetitionStrategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import com.wypl.jpacalendardomain.calendar.data.RepetitionCycle;
import com.wypl.jpacalendardomain.schedule.domain.embedded.RepetitionCycle;
import com.wypl.wyplcore.schedule.service.repetition.strategy.DayRepetitionStrategy;
import com.wypl.wyplcore.schedule.service.repetition.strategy.MonthRepetitionStrategy;
import com.wypl.wyplcore.schedule.service.repetition.strategy.RepetitionStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.stream.Collectors;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;

public class DayRepetitionStrategy implements RepetitionStrategy {
Expand All @@ -28,9 +28,9 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD

return searchStartDate.datesUntil(searchEndDate.plusDays(1)).map(
date -> {
LocalDateTime startDateTime = LocalDateTime.of(date, schedule.getStartDateTime().toLocalTime());
LocalDateTime endDateTime = LocalDateTime.of(date, schedule.getEndDateTime().toLocalTime());
return ScheduleFindResponse.of(schedule, startDateTime, endDateTime);
}).collect(Collectors.toList());
LocalDateTime startDateTime = LocalDateTime.of(date, schedule.getStartDateTime().toLocalTime());
LocalDateTime endDateTime = LocalDateTime.of(date, schedule.getEndDateTime().toLocalTime());
return ScheduleFindResponse.of(schedule, startDateTime, endDateTime);
}).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.time.Period;
import java.util.List;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;

public class MonthRepetitionStrategy implements RepetitionStrategy {
Expand All @@ -24,7 +24,7 @@ public class MonthRepetitionStrategy implements RepetitionStrategy {
public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalDate searchStartDate,
LocalDate searchEndDate) {

searchStartDate = getMaxDate(searchStartDate, schedule.getRepetitionStartDate());
searchStartDate = getMaxDate(searchStartDate, schedule.getRepetitionStartDate());
searchEndDate = getMinDate(searchEndDate, schedule.getRepetitionEndDate());
LocalDate startDate = getFirstScheduleStartDate(schedule, searchStartDate);

Expand All @@ -44,9 +44,11 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD
*/
private LocalDate getFirstScheduleStartDate(Schedule schedule, LocalDate searchStartDate) {

LocalDate firstScheduleEndDate = findNextOrSameByDayOfMonth(searchStartDate, schedule.getEndDateTime().getDayOfMonth());
LocalDate firstScheduleEndDate = findNextOrSameByDayOfMonth(searchStartDate,
schedule.getEndDateTime().getDayOfMonth());

LocalDateTime firstScheduleEndDateTime = LocalDateTime.of(firstScheduleEndDate, schedule.getEndDateTime().toLocalTime());
LocalDateTime firstScheduleEndDateTime = LocalDateTime.of(firstScheduleEndDate,
schedule.getEndDateTime().toLocalTime());

return firstScheduleEndDateTime.minus(schedule.getDuration()).toLocalDate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDate;
import java.util.List;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;

public interface RepetitionStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import java.util.Comparator;
import java.util.List;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;

public class WeekRepetitionStrategy implements RepetitionStrategy {

/**
* RepetitionCycle = Week 인 경우, Schedule 반복 일정을 조회한다.
* @param schedule Target Schedule
*
* @param schedule Target Schedule
* @param searchStartDate 검색 시작일자
* @param searchEndDate 검색 종료일자
* @param searchEndDate 검색 종료일자
* @return {List<ScheduleFindResponse>}
*/
@Override
Expand All @@ -33,8 +34,8 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD
List<ScheduleFindResponse> responses = new ArrayList<>();

if (!schedule.existsDayOfWeek()) { // 반복 요일을 설정하지 않았을 경우

LocalDate firstScheduleStartDate = getFirstScheduleStartDate(searchStartDate, schedule); // 검색 조건에 부합하는 첫 번째 일정의 시작일
LocalDate firstScheduleStartDate = getFirstScheduleStartDate(searchStartDate,
schedule); // 검색 조건에 부합하는 첫 번째 일정의 시작일

for (LocalDate date = firstScheduleStartDate; date.isBefore(searchEndDate); date = date.plusWeeks(
schedule.getWeekInterval())) {
Expand All @@ -43,16 +44,14 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD
responses.add(ScheduleFindResponse.of(schedule, startDateTime, endDateTime));
}
return responses;

} else { // 반복 요일을 설정했을 경우

int repetitionDayOfWeek = schedule.getDayOfWeek();

for (int dayOfWeek = 1; dayOfWeek <= 7; dayOfWeek++) { // 요일마다 처리
if (isSelectedDayOfWeek(repetitionDayOfWeek, dayOfWeek)) {
LocalDate nearestDate = findNextOrSameByDayOfWeek(searchStartDate, DayOfWeek.of(dayOfWeek));
for (LocalDate date = nearestDate; date.isBefore(searchEndDate.plusDays(1)); date = date.plusWeeks(schedule.getWeekInterval())) {

for (LocalDate date = nearestDate; date.isBefore(searchEndDate.plusDays(1)); date =
date.plusWeeks(schedule.getWeekInterval())) {
responses.add(ScheduleFindResponse.of(schedule, date, date));
}
}
Expand All @@ -64,11 +63,12 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD

/**
* searchStartDate 이후 주의 반복 주기를 고려한 첫 번째 일정의 시작일을 찾는다.
*
* @param searchStartDate 검색 시작 날짜
* @param schedule 일정
* @param schedule 일정
* @return 검색된 첫 번째 일정의 시작일
*/
private LocalDate getFirstScheduleStartDate(LocalDate searchStartDate, Schedule schedule){
private LocalDate getFirstScheduleStartDate(LocalDate searchStartDate, Schedule schedule) {

LocalDate scheduleStartDate = schedule.getStartDateTime().toLocalDate();
LocalDate unadjustedStartDate = findNearestStartDate(searchStartDate, schedule); // WeekInterval 반영되지 않은 상태
Expand All @@ -89,8 +89,9 @@ private LocalDate getFirstScheduleStartDate(LocalDate searchStartDate, Schedule

/**
* 검색시작일자(searchStartDate)에 부합하는 가장 가까운 일정시작요일(dayOfWeek of startDateTime of schedule)을 검색한다.
*
* @param searchStartDate 검색시작일자
* @param schedule 일정
* @param schedule 일정
* @return LocalDateTime 검색 조건과 일정의 시작 및 끝나는 요일에 부합하는 가장 가까운 시작일시
*/
private LocalDate findNearestStartDate(LocalDate searchStartDate, Schedule schedule) {
Expand All @@ -105,11 +106,12 @@ private LocalDate findNearestStartDate(LocalDate searchStartDate, Schedule sched

/**
* dayOfWeek 가 repetitionDayOfWeek에 포함됐는지 확인한다.
*
* @param repetitionDayOfWeek 일정의 반복 요일을 비트마스킹한 값
* @param dayOfWeek from 1 to 7 (1: 월요일, 2: 화요일, 3: 수요일, 4: 목요일, 5: 금요일, 6: 토요일, 7: 일요일)
* @param dayOfWeek from 1 to 7 (1: 월요일, 2: 화요일, 3: 수요일, 4: 목요일, 5: 금요일, 6: 토요일, 7: 일요일)
* @return boolean
*/
private boolean isSelectedDayOfWeek(int repetitionDayOfWeek, int dayOfWeek) {
return (repetitionDayOfWeek & (1 << dayOfWeek)) != 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@

import org.springframework.stereotype.Service;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;

@Service
public class YearRepetitionStrategy implements RepetitionStrategy {

/**
* searchStartDate 와 같거나 그 이후의 첫 번째 일정 시작일을 찾는다.
* @param schedule 할일
* @param searchStartDate 검색 시작 일자
* @return LocalDateTime
*/
private static LocalDate getFirstScheduleStartDate(Schedule schedule, LocalDate searchStartDate) {
LocalDate firstScheduleEndDate = findNextOrSame(searchStartDate, schedule.getEndDateTime().getMonth(),
schedule.getEndDateTime().getDayOfMonth());
LocalDateTime firstScheduleEndDateTime = LocalDateTime.of(firstScheduleEndDate,
schedule.getEndDateTime().toLocalTime());
return firstScheduleEndDateTime.minus(schedule.getDuration()).toLocalDate();
}

/**
* RepetitionCycle = Year 인 경우, Schedule 반복 일정을 조회한다.
* @param schedule Target Schedule
Expand Down Expand Up @@ -45,16 +59,4 @@ public List<ScheduleFindResponse> getScheduleResponses(Schedule schedule, LocalD
}
).toList();
}

/**
* searchStartDate 와 같거나 그 이후의 첫 번째 일정 시작일을 찾는다.
* @param schedule 할일
* @param searchStartDate 검색 시작 일자
* @return LocalDateTime
*/
private static LocalDate getFirstScheduleStartDate(Schedule schedule, LocalDate searchStartDate) {
LocalDate firstScheduleEndDate = findNextOrSame(searchStartDate, schedule.getEndDateTime().getMonth(), schedule.getEndDateTime().getDayOfMonth());
LocalDateTime firstScheduleEndDateTime = LocalDateTime.of(firstScheduleEndDate, schedule.getEndDateTime().toLocalTime());
return firstScheduleEndDateTime.minus(schedule.getDuration()).toLocalDate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

import com.wypl.jpacalendardomain.calendar.data.RepetitionCycle;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.schedule.domain.Schedule;
import com.wypl.jpacalendardomain.schedule.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.schedule.domain.embedded.RepetitionCycle;

public enum ScheduleFixture {
DAILY_SCHEDULE(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wypl.wyplcore;

import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.schedule.domain.ScheduleInfo;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import com.wypl.googleoauthclient.data.response.GoogleTokenValidationResponse;
import com.wypl.googleoauthclient.domain.AuthMember;
import com.wypl.jpamemberdomain.member.OauthProvider;
import com.wypl.jpamemberdomain.member.repository.SocialMemberRepository;
import com.wypl.jpamemberdomain.member.domain.SocialMember;
import com.wypl.jpamemberdomain.member.exception.MemberErrorCode;
import com.wypl.jpamemberdomain.member.exception.MemberException;
import com.wypl.jpamemberdomain.member.repository.SocialMemberRepository;
import com.wypl.wyplcore.auth.service.AuthMemberServiceImpl;

@ExtendWith(MockitoExtension.class)
Expand Down
Loading