-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 반복옵션 로직 추가 #34
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
base: dev
Are you sure you want to change the base?
Conversation
@Override
public int calculateCount(Instant startDate, Instant endDate) {
ZonedDateTime zdtStart = DateTimeUtils.toZonedDateTime(startDate);
ZonedDateTime zdtEnd = DateTimeUtils.toZonedDateTime(endDate);
return (int) ChronoUnit.WEEKS.between(zdtStart, zdtEnd) + 1;
} @Override
public int calculateCount(Instant startDate, Instant endDate) {
return DateTimeUtils.calculateWeeksBetween(startDate, endDate);
} @Override
public Instant calculateEndDate(Instant startDate, int count) {
ZonedDateTime zdtStart = startDate.atZone(ZoneId.systemDefault());
return zdtStart.plusMonths(count - 1).toInstant();
} @Override
public Instant calculateEndDate(Instant startDate, int count) {
return DateTimeUtils.plusMonths(startDate, count - 1)
} |
List을 해주면 어떨까요? {
"planIds": [1, 2, 3, 4, 5]
}다른 의견은 생성된 Plan의 개수를 알려주는게 좋을수도 있다는 생각이 드네요. 아니면 savePlan 한정으로 Plan Entity객체를 다 반환해주거나( |
crtEvent
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요!
|
|
||
| import com.flytrap.venusplanner.api.study.domain.Study; | ||
|
|
||
| public interface StudyValid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 StudyValidator라고 명명했어요. 이름 회의 때 이야기해보면 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 저도 Validator가 좀 더 자연스럽게 읽히는 것 같습니당
|
|
||
| import java.time.Instant; | ||
|
|
||
| public interface EndOptionCalculate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculate가 동사라서 Calculator나 Calculatable? 어떠세요?
| WEEKLY(ChronoUnit.WEEKS) { | ||
| @Override | ||
| public Instant calculateEndDate(Instant startDate, int count) { | ||
| ZonedDateTime zdtStart = DateTimeUtils.toZonedDateTime(startDate); | ||
| return DateTimeUtils.toInstant(zdtStart.plusWeeks(count - 1)); | ||
| } | ||
|
|
||
| @Override | ||
| public int calculateCount(Instant startDate, Instant endDate) { | ||
| ZonedDateTime zdtStart = DateTimeUtils.toZonedDateTime(startDate); | ||
| ZonedDateTime zdtEnd = DateTimeUtils.toZonedDateTime(endDate); | ||
| return (int) ChronoUnit.WEEKS.between(zdtStart, zdtEnd) + 1; | ||
| } | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 방식 보기 좋아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드에서부터 느껴지는 복잡함.. 너무 고생하셨습니다.
|
|
||
| import com.flytrap.venusplanner.api.study.domain.Study; | ||
|
|
||
| public interface StudyValid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 저도 Validator가 좀 더 자연스럽게 읽히는 것 같습니당
| Plan newPlan = Plan.builder() | ||
| .study(planTemplate.getStudy()) | ||
| .planCategory(planTemplate.getPlanCategory()) | ||
| .recurringOption(planTemplate.getRecurringOption()) | ||
| .title(planTemplate.getTitle()) | ||
| .description(planTemplate.getDescription()) | ||
| .startTime(startTime) | ||
| .endTime(endTime) | ||
| .notificationTime(planTemplate.getNotificationTime()) | ||
| .build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서비스 로직 코드 읽는데 빌더가 너무 길어서 Plan에 static으로 메서드 하나 만드는건 어떨까요
|
|
||
| public void calculate(Instant startDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculate 메서드명이 좀 더 구체적이면 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반복 옵션이 생성될 때 생성자에서 계산해서 넣어주면 안되나요?? calculate가 있어야 하는 이유가 궁금합니다
|
✨ Key changes
👋 To reviewers
반복 횟수, 종료 시간 서버에서 계산해서 넣어주기
Instant->ZonedDateTime-> 연산 로직 ->Instant변환Instant->ZonedDateTime->ChronoUnit활용하여 연산Instant->ZonedDateTime변환 유틸 클래스 분리 여부 질문path :
~/plan/util/DateTimeUtils.javaFrequency 코드
Frequency 코드
util 클래스로 분리해도 코드가 줄어들지 않고 그렇다고 엄청난 분리 효과..? 가 느껴지지 않는 거 같은데 어떤가요?
Plan 생성 시 반복옵션 수만큼 추가 생성
횟수 추가(3번) 쿼리
Hibernate: insert into recurring_option (end_date, end_option, frequency, recurrence_count) values (?, ?, ?, ?) Hibernate: insert into plan (description, end_time, notification_time, plan_category_id, recurring_option_id, start_time, study_id, title) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into plan (description, end_time, notification_time, plan_category_id, recurring_option_id, start_time, study_id, title) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into plan (description, end_time, notification_time, plan_category_id, recurring_option_id, start_time, study_id, title) values (?, ?, ?, ?, ?, ?, ?, ?)날짜 추가 (다음주 까지 총 2번 반복)
Hibernate: insert into recurring_option (end_date, end_option, frequency, recurrence_count) values (?, ?, ?, ?) Hibernate: insert into plan (description, end_time, notification_time, plan_category_id, recurring_option_id, start_time, study_id, title) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into plan (description, end_time, notification_time, plan_category_id, recurring_option_id, start_time, study_id, title) values (?, ?, ?, ?, ?, ?, ?, ?)@PrePersist 옵션 부작용(?)
@PrePersist 어노테이션이 붙은 메소드는 엔티티가 영속성 컨텍스트에 저장되기 직전에 자동으로 호출되는 특징이 있습니다.
현재 해당 메소드에서
recurringOption의 반복횟수 및 종료시간연산을 진행 중 입니다.추가로 생성된 plan이 저장될 때에도 반복옵션이 종료시간이 새롭게 생긴 시간을 기준으로 다시 연산을 하여 저장하게 되는 문제가 발생하였습니다.
아래 코드를 추가하여 추가로 연산되는 작업을 방지했습니다. 좀,, 코드가 별로라 혹시 다른 방법 있으면 추천 부탁드려요,,
반복옵션만큼 plan 이 생성됐을 때 반환값은 어떻게 할까요?
현재 첫번째로 생성된 Plan id 반환하고 있습니다.
해당 메소드 리턴값이
Long타입이라 어떤 것을 반환해야할지🤔Plan 삭제 시 전체 삭제일 경우, 관련 반복옵션 모두 삭제
임시로 기능을 구현하기 위해서 delete API 에
boolean applyAll이라는 쿼리 파라미터를 추가하여 구현하였습니다.추가 논의
plan 삭제를 누르면 반복옵션이 존재할 경우, 관련 paln 모두 삭제 / 하나만 삭제 여부를 묻는 팝업창이 필요할 것 같습니다.
전체 삭제 API 를 분리 여부도 논의가 필요할 것 같습니다.
TODO
Plan관련 예외처리도 아직 에이프 예외처리 PR이 머지되지 않아서 PR 머지 후에 추가하겠습니다.