-
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.
[YS-268] 매칭 공고 전송 수동 트리거 API 구현 & 공고 memberName 변경 (#83)
- Loading branch information
Showing
14 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/dobby/backend/application/service/SchedulerService.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,15 @@ | ||
package com.dobby.backend.application.service | ||
|
||
import com.dobby.backend.application.usecase.quartz.TriggerSchedulerUseCase | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SchedulerService( | ||
private val schedulerTriggerUseCase: TriggerSchedulerUseCase | ||
) { | ||
@Transactional | ||
fun triggerSendMatchingEmailJob() { | ||
schedulerTriggerUseCase.execute(TriggerSchedulerUseCase.Input("matching_email_send_job")) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/dobby/backend/application/usecase/quartz/TriggerSchedulerUseCase.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,22 @@ | ||
package com.dobby.backend.application.usecase.quartz | ||
|
||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.gateway.SchedulerTriggerGateway | ||
|
||
class TriggerSchedulerUseCase( | ||
private val schedulerTriggerGateway: SchedulerTriggerGateway | ||
): UseCase<TriggerSchedulerUseCase.Input, TriggerSchedulerUseCase.Output> { | ||
|
||
data class Input( | ||
val jobName: String, | ||
val jobGroup: String = "DEFAULT" | ||
) | ||
|
||
object Output | ||
|
||
override fun execute(input: Input): Output { | ||
schedulerTriggerGateway.triggerJob(input.jobName, input.jobGroup) | ||
return Output | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/dobby/backend/domain/gateway/SchedulerTriggerGateway.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,5 @@ | ||
package com.dobby.backend.domain.gateway | ||
|
||
interface SchedulerTriggerGateway { | ||
fun triggerJob(jobName: String, jobGroup: String) | ||
} |
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
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/dobby/backend/infrastructure/gateway/SchedulerTriggerGatewayImpl.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,21 @@ | ||
package com.dobby.backend.infrastructure.gateway | ||
|
||
import com.dobby.backend.domain.gateway.SchedulerTriggerGateway | ||
import org.quartz.Scheduler | ||
import org.quartz.JobKey | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SchedulerTriggerGatewayImpl( | ||
private val scheduler: Scheduler | ||
) : SchedulerTriggerGateway { | ||
override fun triggerJob(jobName: String, jobGroup: String) { | ||
val jobKey = JobKey.jobKey(jobName, jobGroup) | ||
if (scheduler.checkExists(jobKey)) { | ||
scheduler.triggerJob(jobKey) | ||
} else { | ||
throw IllegalArgumentException("Job with name $jobName and group $jobGroup does not exist.") | ||
} | ||
} | ||
} | ||
|
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
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/dobby/backend/presentation/api/controller/SchedulerController.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,24 @@ | ||
package com.dobby.backend.presentation.api.controller | ||
|
||
import com.dobby.backend.application.service.SchedulerService | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "스케줄러 수동 트리거 API - /v1/scheduler") | ||
@RestController | ||
@RequestMapping("/v1/scheduler") | ||
class SchedulerController( | ||
private val schedulerService: SchedulerService | ||
) { | ||
@GetMapping("/email-trigger") | ||
@Operation( | ||
summary = "매칭 공고 이메일 전송 수동 트리거 API", | ||
description = "이메일 UT 검증을 위한 테스트 API입니다. 실제 비즈니스 로직이 아니기에, 추후 조정될 여지가 있습니다." | ||
) | ||
fun triggerSendMatchingEmailJob() { | ||
schedulerService.triggerSendMatchingEmailJob() | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/com/dobby/backend/application/usecase/quartz/TriggerSchedulerUseCaseTest.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,48 @@ | ||
package com.dobby.backend.application.usecase.quartz | ||
|
||
import com.dobby.backend.domain.gateway.SchedulerTriggerGateway | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.* | ||
|
||
class TriggerSchedulerUseCaseTest : BehaviorSpec({ | ||
|
||
// Mock 객체 생성 | ||
val schedulerTriggerGateway = mockk<SchedulerTriggerGateway>(relaxed = true) | ||
|
||
// UseCase 생성 | ||
val triggerSchedulerUseCase = TriggerSchedulerUseCase(schedulerTriggerGateway) | ||
|
||
beforeTest { | ||
clearMocks(schedulerTriggerGateway) | ||
} | ||
|
||
given("스케줄러 트리거 실행 요청이 들어왔을 때") { | ||
|
||
`when`("유효한 jobName과 jobGroup을 전달하면") { | ||
val input = TriggerSchedulerUseCase.Input(jobName = "testJob", jobGroup = "testGroup") | ||
|
||
every { schedulerTriggerGateway.triggerJob(input.jobName, input.jobGroup) } just Runs // Void method | ||
|
||
then("스케줄러 트리거가 정상적으로 실행되어야 한다") { | ||
val output = triggerSchedulerUseCase.execute(input) | ||
|
||
output shouldBe TriggerSchedulerUseCase.Output | ||
verify(exactly = 1) { schedulerTriggerGateway.triggerJob(input.jobName, input.jobGroup) } | ||
} | ||
} | ||
|
||
`when`("jobGroup을 지정하지 않고 jobName만 전달하면") { | ||
val input = TriggerSchedulerUseCase.Input(jobName = "testJob") | ||
|
||
every { schedulerTriggerGateway.triggerJob(input.jobName, "DEFAULT") } just Runs | ||
|
||
then("기본 jobGroup인 'DEFAULT'로 실행되어야 한다") { | ||
val output = triggerSchedulerUseCase.execute(input) | ||
|
||
output shouldBe TriggerSchedulerUseCase.Output | ||
verify(exactly = 1) { schedulerTriggerGateway.triggerJob(input.jobName, "DEFAULT") } | ||
} | ||
} | ||
} | ||
}) |