-
Notifications
You must be signed in to change notification settings - Fork 8
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] 방 수정 기능 & 스케줄러 부분 분리 및 리팩토링(#605) #606
Changes from 1 commit
4a27da8
85b9f11
adb297b
e05bc8a
38a083b
e5264b8
800c48b
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package corea.room.service; | ||
|
||
import corea.room.domain.Room; | ||
import corea.scheduler.domain.AutomaticMatching; | ||
import corea.scheduler.domain.AutomaticUpdate; | ||
import corea.scheduler.domain.ScheduleStatus; | ||
import corea.scheduler.service.*; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class RoomAutomaticService { | ||
|
||
private final AutomaticUpdateWriter automaticUpdateWriter; | ||
private final AutomaticUpdateReader automaticUpdateReader; | ||
|
||
private final AutomaticMatchingWriter automaticMatchingWriter; | ||
private final AutomaticMatchingReader automaticMatchingReader; | ||
|
||
private final AutomaticMatchingService automaticMatchingService; | ||
private final AutomaticUpdateService automaticUpdateService; | ||
|
||
@Transactional | ||
public void updateTime(Room updateRoom) { | ||
AutomaticMatching automaticMatching = automaticMatchingReader.findWithRoom(updateRoom); | ||
AutomaticUpdate automaticUpdate = automaticUpdateReader.findWithRoom(updateRoom); | ||
|
||
automaticMatchingWriter.updateTime(automaticMatching, updateRoom.getRecruitmentDeadline()); | ||
automaticUpdateWriter.updateTime(automaticUpdate, updateRoom.getReviewDeadline()); | ||
|
||
automaticMatchingService.modifyTask(updateRoom); | ||
automaticUpdateService.modifyTask(updateRoom); | ||
} | ||
|
||
@Transactional | ||
public void createAutomatic(Room room) { | ||
automaticMatchingWriter.create(room); | ||
automaticUpdateWriter.create(room); | ||
|
||
automaticMatchingService.matchOnRecruitmentDeadline(room); | ||
automaticUpdateService.updateAtReviewDeadline(room); | ||
} | ||
|
||
@Transactional | ||
public void deleteAutomatic(Room room) { | ||
AutomaticMatching automaticMatching = automaticMatchingReader.findWithRoom(room); | ||
AutomaticUpdate automaticUpdate = automaticUpdateReader.findWithRoom(room); | ||
|
||
automaticMatchingWriter.delete(automaticMatching); | ||
automaticUpdateWriter.delete(automaticUpdate); | ||
|
||
automaticMatchingService.cancel(room.getId()); | ||
automaticUpdateService.cancel(room.getId()); | ||
} | ||
|
||
@EventListener(ApplicationReadyEvent.class) | ||
public void schedulePendingAutomaticMatching() { | ||
List<AutomaticMatching> matchings = automaticMatchingReader.findByStatus(ScheduleStatus.PENDING); | ||
|
||
log.info("{}개의 방에 대해 자동 매칭 재예약 시작", matchings.size()); | ||
|
||
matchings.forEach(automaticMatchingService::matchOnRecruitmentDeadline); | ||
|
||
log.info("{}개의 방에 대해 자동 매칭 재예약 완료", matchings.size()); | ||
} | ||
|
||
@EventListener(ApplicationReadyEvent.class) | ||
public void schedulePendingAutomaticUpdate() { | ||
List<AutomaticUpdate> updates = automaticUpdateReader.findByStatus(ScheduleStatus.PENDING); | ||
|
||
log.info("{}개의 방에 대해 자동 상태 업데이트 재예약 시작", updates.size()); | ||
|
||
updates.forEach(automaticUpdateService::updateAtReviewDeadline); | ||
|
||
log.info("{}개의 방에 대해 자동 상태 업데이트 재예약 완료", updates.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package corea.scheduler.service; | ||
|
||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.room.domain.Room; | ||
import corea.scheduler.domain.AutomaticMatching; | ||
import corea.scheduler.domain.ScheduleStatus; | ||
import corea.scheduler.repository.AutomaticMatchingRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AutomaticMatchingReader { | ||
|
||
private final AutomaticMatchingRepository automaticMatchingRepository; | ||
|
||
public AutomaticMatching findWithRoom(Room room) { | ||
return automaticMatchingRepository.findByRoomId(room.getId()) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.AUTOMATIC_MATCHING_NOT_FOUND)); | ||
} | ||
|
||
public List<AutomaticMatching> findByStatus(ScheduleStatus status) { | ||
return automaticMatchingRepository.findAllByStatus(status); | ||
} | ||
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. 제안: 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package corea.scheduler.service; | ||
|
||
import corea.room.domain.Room; | ||
import corea.scheduler.domain.AutomaticMatching; | ||
import corea.scheduler.repository.AutomaticMatchingRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class AutomaticMatchingWriter { | ||
|
||
private final AutomaticMatchingRepository automaticMatchingRepository; | ||
|
||
public AutomaticMatching updateTime(AutomaticMatching automaticMatching, LocalDateTime matchingStartTime) { | ||
AutomaticMatching updateEntity = new AutomaticMatching( | ||
automaticMatching.getId(), | ||
automaticMatching.getRoomId(), | ||
matchingStartTime, | ||
automaticMatching.getStatus() | ||
); | ||
return automaticMatchingRepository.save(updateEntity); | ||
} | ||
|
||
public AutomaticMatching create(Room room) { | ||
AutomaticMatching entity = new AutomaticMatching(room.getId(),room.getRecruitmentDeadline()); | ||
return automaticMatchingRepository.save(entity); | ||
} | ||
|
||
public void delete(AutomaticMatching automaticMatching) { | ||
automaticMatchingRepository.delete(automaticMatching); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package corea.scheduler.service; | ||
|
||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.room.domain.Room; | ||
import corea.scheduler.domain.AutomaticUpdate; | ||
import corea.scheduler.domain.ScheduleStatus; | ||
import corea.scheduler.repository.AutomaticUpdateRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AutomaticUpdateReader { | ||
|
||
private final AutomaticUpdateRepository automaticUpdateRepository; | ||
|
||
public AutomaticUpdate findWithRoom(Room room) { | ||
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. 네이밍 관련 코멘트 동일합니다.
|
||
return automaticUpdateRepository.findByRoomId(room.getId()) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.AUTOMATIC_UPDATE_NOT_FOUND)); | ||
} | ||
|
||
public List<AutomaticUpdate> findByStatus(ScheduleStatus status) { | ||
return automaticUpdateRepository.findAllByStatus(status) | ||
.stream() | ||
.toList(); | ||
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package corea.scheduler.service; | ||
|
||
import corea.room.domain.Room; | ||
import corea.scheduler.domain.AutomaticUpdate; | ||
import corea.scheduler.repository.AutomaticUpdateRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class AutomaticUpdateWriter { | ||
|
||
private final AutomaticUpdateRepository automaticUpdateRepository; | ||
|
||
public AutomaticUpdate updateTime(AutomaticUpdate automaticUpdate, LocalDateTime reviewDeadline) { | ||
AutomaticUpdate updateEntity = new AutomaticUpdate( | ||
automaticUpdate.getId(), | ||
automaticUpdate.getRoomId(), | ||
reviewDeadline, | ||
automaticUpdate.getStatus() | ||
); | ||
return automaticUpdateRepository.save(updateEntity); | ||
} | ||
|
||
public AutomaticUpdate create(Room room) { | ||
AutomaticUpdate createEntity = new AutomaticUpdate( | ||
room.getId(), | ||
room.getReviewDeadline() | ||
); | ||
return automaticUpdateRepository.save(createEntity); | ||
} | ||
|
||
public void delete(AutomaticUpdate automaticUpdate) { | ||
automaticUpdateRepository.delete(automaticUpdate); | ||
} | ||
} |
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.
P5
네이밍 얘기가 나온 김에
아래 메서드가
findByXXX
이니위 메서드도
findByRoom
이 되어도 좋겠네요~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.
위에 코멘트가 안달려서 밑에 남깁니당.
Reader
와Writer
는 최대한 Reader 와 Writer 인걸 명확하게 사용하고 싶어요.(
AutomaticMatchingReader
라는 클래스만 봐도AutomaticMatching
을 읽을거라 기대 )그렇기에 findByStatus 만 해도 충분할 거 같다는 생각이 드는데 어떤가요?