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
[BE] issue188: 스터디 상태 자동 변경 #191
Changes from 8 commits
43d759f
13935dd
edbdd6d
1d37bc2
b39181a
3bdaddf
e224dd1
604e9b4
f10eb90
a196411
5568c77
7392e40
ae0c1b0
d551ac7
e2ebea9
e1f1ce0
dc4d4ea
e87dc38
3cc64c2
88aa874
a89b0ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,19 +95,20 @@ public void participate(final Long memberId) { | |
} | ||
} | ||
|
||
private boolean isFullOfCapacity() { | ||
return recruitPlanner.hasCapacity() && recruitPlanner.getCapacity() == participants.getSize(); | ||
public void changeStatus(final LocalDate now) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Study 객체에서 상태 관리 👍 |
||
recruitPlanner.updateRecruiting(now); | ||
studyPlanner.updateStatus(now); | ||
} | ||
|
||
public boolean isNeedToCloseRecruiting(LocalDate now) { | ||
return recruitPlanner.isNeedToCloseRecruiting(now); | ||
public boolean isProgressStatus() { | ||
return studyPlanner.isProgress(); | ||
} | ||
|
||
public void closeEnrollment() { | ||
recruitPlanner.closeRecruiting(); | ||
public boolean isCloseStudy() { | ||
return studyPlanner.isCloseStudy(); | ||
} | ||
|
||
public boolean isCloseEnrollment() { | ||
return recruitPlanner.isCloseEnrollment(); | ||
private boolean isFullOfCapacity() { | ||
return recruitPlanner.hasCapacity() && recruitPlanner.getCapacity() == participants.getSize(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,17 +1,21 @@ | ||||||||||||||||||||
package com.woowacourse.moamoa.study.domain; | ||||||||||||||||||||
|
||||||||||||||||||||
import static com.woowacourse.moamoa.study.domain.StudyStatus.DONE; | ||||||||||||||||||||
import static com.woowacourse.moamoa.study.domain.StudyStatus.IN_PROGRESS; | ||||||||||||||||||||
import static com.woowacourse.moamoa.study.domain.StudyStatus.PREPARE; | ||||||||||||||||||||
import static javax.persistence.EnumType.STRING; | ||||||||||||||||||||
import static lombok.AccessLevel.PROTECTED; | ||||||||||||||||||||
|
||||||||||||||||||||
import com.woowacourse.moamoa.study.domain.exception.InvalidPeriodException; | ||||||||||||||||||||
import java.time.LocalDate; | ||||||||||||||||||||
import java.util.Objects; | ||||||||||||||||||||
import javax.persistence.Column; | ||||||||||||||||||||
import javax.persistence.Embeddable; | ||||||||||||||||||||
import javax.persistence.Enumerated; | ||||||||||||||||||||
import lombok.EqualsAndHashCode; | ||||||||||||||||||||
import lombok.NoArgsConstructor; | ||||||||||||||||||||
|
||||||||||||||||||||
@Embeddable | ||||||||||||||||||||
@EqualsAndHashCode | ||||||||||||||||||||
@NoArgsConstructor(access = PROTECTED) | ||||||||||||||||||||
public class StudyPlanner { | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -44,28 +48,32 @@ boolean isEndBeforeThan(LocalDate date) { | |||||||||||||||||||
return endDate.isBefore(date); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
boolean isPreparing() { | ||||||||||||||||||||
return studyStatus.equals(StudyStatus.PREPARE); | ||||||||||||||||||||
void updateStatus(final LocalDate now) { | ||||||||||||||||||||
if (isNeedToCloseStudy(now)) { | ||||||||||||||||||||
studyStatus = DONE; | ||||||||||||||||||||
} | ||||||||||||||||||||
if (isNeedToChangeProgress(now)) { | ||||||||||||||||||||
studyStatus = IN_PROGRESS; | ||||||||||||||||||||
} | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정해보았습니다~_~ |
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
public StudyStatus getStudyStatus() { | ||||||||||||||||||||
return studyStatus; | ||||||||||||||||||||
private boolean isNeedToCloseStudy(final LocalDate now) { | ||||||||||||||||||||
return (endDate != null) && (studyStatus.equals(IN_PROGRESS)) && (endDate.isAfter(now) || endDate.isEqual(now)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 isProgress 메서드 써도 좋을 것 같습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오!! 좋네요~_~ |
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
@Override | ||||||||||||||||||||
public boolean equals(final Object o) { | ||||||||||||||||||||
if (this == o) { | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
if (o == null || getClass() != o.getClass()) { | ||||||||||||||||||||
return false; | ||||||||||||||||||||
} | ||||||||||||||||||||
final StudyPlanner studyPlanner = (StudyPlanner) o; | ||||||||||||||||||||
return Objects.equals(startDate, studyPlanner.startDate) && Objects.equals(endDate, studyPlanner.endDate); | ||||||||||||||||||||
private boolean isNeedToChangeProgress(final LocalDate now) { | ||||||||||||||||||||
return (studyStatus.equals(PREPARE)) && (startDate.isAfter(now) || startDate.isEqual(now)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 오!! 변경하도록 하겠습니다~_~ |
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
boolean isProgress() { | ||||||||||||||||||||
return studyStatus.equals(IN_PROGRESS); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
boolean isPreparing() { | ||||||||||||||||||||
return studyStatus.equals(PREPARE); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
@Override | ||||||||||||||||||||
public int hashCode() { | ||||||||||||||||||||
return Objects.hash(startDate, endDate); | ||||||||||||||||||||
boolean isCloseStudy() { | ||||||||||||||||||||
return studyStatus.equals(DONE); | ||||||||||||||||||||
} | ||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
import com.woowacourse.moamoa.study.service.StudyService; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.scheduling.config.TriggerTask; | ||
|
@@ -27,7 +26,7 @@ private static Runnable runnable(final StudyService studyService) { | |
@Transactional | ||
public void run() { | ||
LOGGER.debug(LocalDateTime.now() + " : " + "start moamoa scheduled task!"); | ||
studyService.autoCloseStudies(); | ||
studyService.autoUpdateStatus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 이렇게 한거군요! |
||
} | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.woowacourse.moamoa.member.query.data.MemberData; | ||
import com.woowacourse.moamoa.study.query.data.StudyDetailsData; | ||
import com.woowacourse.moamoa.tag.query.response.TagData; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
@@ -22,11 +23,11 @@ public class StudyDetailResponse { | |
private String recruitmentStatus; | ||
private String description; | ||
private Integer currentMemberCount; | ||
private String maxMemberCount; | ||
private String createdDate; | ||
private String enrollmentEndDate; | ||
private String startDate; | ||
private String endDate; | ||
private Integer maxMemberCount; | ||
private LocalDate createdDate; | ||
private LocalDate enrollmentEndDate; | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
private MemberData owner; | ||
private List<MemberData> members; | ||
private List<TagData> tags; | ||
|
@@ -41,20 +42,13 @@ public StudyDetailResponse(final StudyDetailsData study, | |
this.recruitmentStatus = study.getRecruitmentStatus(); | ||
this.description = study.getDescription(); | ||
this.currentMemberCount = study.getCurrentMemberCount(); | ||
this.maxMemberCount = getNullableDate(study.getMaxMemberCount()); | ||
this.createdDate = study.getCreatedDate().toString(); | ||
this.enrollmentEndDate = getNullableDate(study.getEnrollmentEndDate()); | ||
this.startDate = study.getStartDate().toString(); | ||
this.endDate = getNullableDate(study.getEndDate()); | ||
this.maxMemberCount = study.getMaxMemberCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 명세 변경 null 리팩터링 👍 |
||
this.createdDate = study.getCreatedDate(); | ||
this.enrollmentEndDate = study.getEnrollmentEndDate(); | ||
this.startDate = study.getStartDate(); | ||
this.endDate = study.getEndDate(); | ||
this.owner = study.getOwner(); | ||
this.members = participants; | ||
this.tags = attachedTags; | ||
} | ||
|
||
private String getNullableDate(final Object value) { | ||
if (value == null) { | ||
return ""; | ||
} | ||
return value.toString(); | ||
} | ||
} |
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.
value 제거해주세요
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.
넵!! 일관성 있게 나머지 @Enumerated 도 통일해주었습니다!