-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] 스케줄러를 통해서 커피챗 예정 시간이 지난 경우 커피챗 상태를 전환한다 (#174)
* feat: 커피챗 자동 취소에 대한 CoffeeChatStatus 필드 추가 * feat: 커피챗 ID 상태별 조회, 상태 일괄 업데이트 쿼리 * refactor: 커피챗 ID 상태별 조회에 진행 시작 시간 조건 추가 * feat: 대기, 예정된 커피챗들에 대해서 시간이 지난 경우 상태를 업데이트하는 프로세서 컴포넌트 * feat: 대기, 예정 커피챗 상태 전환 스케줄러 * fix .editorconfig * test: Kotest 단위 테스트 관련 `@UnitTestKt` 적용
- Loading branch information
Showing
19 changed files
with
472 additions
and
161 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
kotlin.code.style=ktlint_official | ||
|
||
### Application Version ### | ||
applicationVersion=0.0.1-SNAPSHOT | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
...java/com/koddy/server/coffeechat/application/scheduler/UpdateCoffeeChatStatusScheduler.kt
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,18 @@ | ||
package com.koddy.server.coffeechat.application.scheduler | ||
|
||
import com.koddy.server.coffeechat.domain.service.UpdateCoffeeChatStatusProcessor | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
class UpdateCoffeeChatStatusScheduler( | ||
private val updateCoffeeChatStatusProcessor: UpdateCoffeeChatStatusProcessor, | ||
) { | ||
@Scheduled(cron = "0 0/10 * * * *", zone = "Asia/Seoul") | ||
fun updateCoffeeChatStatus() { | ||
val now: LocalDateTime = LocalDateTime.now() | ||
updateCoffeeChatStatusProcessor.updateWaitingToAutoCancel(now) | ||
updateCoffeeChatStatusProcessor.updateScheduledToComplete(now) | ||
} | ||
} |
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
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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/koddy/server/coffeechat/domain/service/UpdateCoffeeChatStatusProcessor.kt
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,59 @@ | ||
package com.koddy.server.coffeechat.domain.service | ||
|
||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.AUTO_CANCEL_FROM_MENTEE_FLOW | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.AUTO_CANCEL_FROM_MENTOR_FLOW | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTEE_APPLY | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTEE_APPLY_COFFEE_CHAT_COMPLETE | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTEE_PENDING | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTOR_APPROVE | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTOR_FINALLY_APPROVE | ||
import com.koddy.server.coffeechat.domain.model.CoffeeChatStatus.MENTOR_SUGGEST_COFFEE_CHAT_COMPLETE | ||
import com.koddy.server.coffeechat.domain.repository.CoffeeChatRepository | ||
import com.koddy.server.global.annotation.KoddyWritableTransactional | ||
import com.koddy.server.global.log.logger | ||
import org.slf4j.Logger | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
class UpdateCoffeeChatStatusProcessor( | ||
private val coffeeChatRepository: CoffeeChatRepository, | ||
) { | ||
private val log: Logger = logger() | ||
|
||
@KoddyWritableTransactional | ||
fun updateWaitingToAutoCancel(standard: LocalDateTime) { | ||
// 1. MenteeFlow 신청 | ||
val applyCoffeeChatIds: List<Long> = coffeeChatRepository.findIdsByStatusAndReservationStandard(MENTEE_APPLY, standard) | ||
log.info("[updateWaitingToAutoCancel] MENTEE_APPLY Ids = {}", applyCoffeeChatIds) | ||
updateStatus(applyCoffeeChatIds, AUTO_CANCEL_FROM_MENTEE_FLOW) | ||
|
||
// 2. MentorFlow 1차 수락 | ||
val pendingCoffeeChatIds: List<Long> = coffeeChatRepository.findIdsByStatusAndReservationStandard(MENTEE_PENDING, standard) | ||
log.info("[updateWaitingToAutoCancel] MENTEE_PENDING Ids = {}", pendingCoffeeChatIds) | ||
updateStatus(pendingCoffeeChatIds, AUTO_CANCEL_FROM_MENTOR_FLOW) | ||
} | ||
|
||
@KoddyWritableTransactional | ||
fun updateScheduledToComplete(standard: LocalDateTime) { | ||
// 1. MenteeFlow 수락 | ||
val approveCoffeeChatIds: List<Long> = coffeeChatRepository.findIdsByStatusAndReservationStandard(MENTOR_APPROVE, standard) | ||
log.info("[updateScheduledToComplete] MENTOR_APPROVE Ids = {}", approveCoffeeChatIds) | ||
updateStatus(approveCoffeeChatIds, MENTEE_APPLY_COFFEE_CHAT_COMPLETE) | ||
|
||
// 2. MentorFlow 수락 | ||
val finallyApproveCoffeeChatIds: List<Long> = coffeeChatRepository.findIdsByStatusAndReservationStandard(MENTOR_FINALLY_APPROVE, standard) | ||
log.info("[updateScheduledToComplete] MENTOR_FINALLY_APPROVE Ids = {}", finallyApproveCoffeeChatIds) | ||
updateStatus(finallyApproveCoffeeChatIds, MENTOR_SUGGEST_COFFEE_CHAT_COMPLETE) | ||
} | ||
|
||
private fun updateStatus( | ||
coffeeChatIds: List<Long>, | ||
updateStatus: CoffeeChatStatus, | ||
) { | ||
if (coffeeChatIds.isNotEmpty()) { | ||
coffeeChatRepository.updateStatusInBatch(coffeeChatIds, updateStatus) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.