-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a27da8
commit 85b9f11
Showing
6 changed files
with
229 additions
and
14 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
backend/src/main/java/corea/room/service/RoomAutomaticService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/corea/scheduler/service/AutomaticMatchingReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/corea/scheduler/service/AutomaticMatchingWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/corea/scheduler/service/AutomaticUpdateReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/corea/scheduler/service/AutomaticUpdateWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |