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

[BE] issue188: 스터디 상태 자동 변경 #191

Merged
merged 21 commits into from Aug 4, 2022

Conversation

tco0427
Copy link
Collaborator

@tco0427 tco0427 commented Aug 3, 2022

요약

스터디 상태 자동 변경

세부사항

  • 스터디가 시작 기간(startDate)이 되면 자동으로 IN_PROGRESS 상태가 된다.
  • 스터디가 종료 기간(endDate)가 되면 자동으로 DONE 상태가 된다.
    • 스터디 종료 기간 (endDate) 은 필수가 아니므로 없는 경우에는 IN_PROGRESS 를 유지한다.
  • 데이터 응답시에 빈값인 경우 "" 가 아닌 "null" 을 반환한다.

close #188

@tco0427 tco0427 added 🚀 feature New feature or request 🖥 backend New backend feature labels Aug 3, 2022
@tco0427 tco0427 self-assigned this Aug 3, 2022
Copy link
Collaborator

@sc0116 sc0116 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

디우 기능 잘 구현해주셨네요
스케쥴링을 맡아본 적은 없지만 코드따라가면서 보니 이해가 쉬웠네요

@@ -28,7 +28,7 @@ CREATE TABLE study
max_member_count INTEGER,
created_at DATETIME not null,
enrollment_end_date DATE,
start_date DATE,
start_date DATE not null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not null 굿

@@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 이렇게 한거군요!

return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ErrorResponse> handleInternalServerError(RuntimeException e) {
e.printStackTrace();
log.error("RuntimeException : {}", e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Study 객체에서 상태 관리 👍

this.enrollmentEndDate = getNullableDate(study.getEnrollmentEndDate());
this.startDate = study.getStartDate().toString();
this.endDate = getNullableDate(study.getEndDate());
this.maxMemberCount = study.getMaxMemberCount();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

명세 변경 null 리팩터링 👍

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

밑에 있는 isPreparing 메서드 써도 좋을 것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 isProgress 메서드 써도 좋을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오!! 좋네요~_~

public class RecruitPlanner {

@Column(name = "max_member_count")
private Integer max;

@Enumerated(EnumType.STRING)
@Enumerated(value = STRING)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 제거해주세요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!! 일관성 있게 나머지 @Enumerated 도 통일해주었습니다!

Comment on lines 52 to 57
if (isNeedToCloseStudy(now)) {
studyStatus = DONE;
}
if (isNeedToChangeProgress(now)) {
studyStatus = IN_PROGRESS;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isNeedToCloseStudy(now)) {
studyStatus = DONE;
}
if (isNeedToChangeProgress(now)) {
studyStatus = IN_PROGRESS;
}
if (isNeedToChangeStatus(now)) {
studyStatus = nextStatus(now);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정해보았습니다~_~

Comment on lines 165 to 172
public void autoCloseStudyStatus() {
given(dateTimeSystem.now()).willReturn(LocalDateTime.now());

sut.getRunnable().run();

final Study linuxStudy = studyRepository.findById(linuxStudyId).orElseThrow();

assertThat(linuxStudy.isCloseStudy()).isEqualTo(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isAfter 케이스 확인해주세요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다!

@verus-j
Copy link
Collaborator

verus-j commented Aug 4, 2022

Study 불변식 확인하는 코드 부탁드려요.
생성자에서 StudyStatus와 RecruitStatus가 올바른 값인지 확인하는 코드 필요합니다.

…oamoa into feat/188-study-auto-close

# Conflicts:
#	backend/src/test/java/com/woowacourse/acceptance/study/GettingStudyDetailsAcceptanceTest.java
Comment on lines 18 to 24

@Bean
public ApplicationRunner runner() {
return args -> {
log.debug("hello !");
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

없애주세요

@verus-j verus-j merged commit d918cc9 into develop Aug 4, 2022
@verus-j verus-j deleted the feat/188-study-auto-close branch August 4, 2022 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖥 backend New backend feature 🚀 feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants