Skip to content

Commit

Permalink
Merge pull request #100 from TeamMiso/feat/environment-scheduler
Browse files Browse the repository at this point in the history
🔀 :: 환경 정보 스케쥴러 구현
  • Loading branch information
uuuuuuuk authored Apr 11, 2024
2 parents 1df2af9 + 0c16b84 commit e68ae76
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.environment.application.port.input

interface UpdateTodayEnvironmentUseCase {
fun execute()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package andreas311.miso.domain.environment.application.scheduler

import andreas311.miso.domain.environment.application.port.input.UpdateTodayEnvironmentUseCase
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class UpdateTodayEnvironmentScheduler(
private val updateTodayEnvironmentUseCase: UpdateTodayEnvironmentUseCase
) {
@Scheduled(cron = "0 0 0 * * ?")
fun updateTodayEnvironment() {
updateTodayEnvironmentUseCase.execute()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package andreas311.miso.domain.environment.application.service

import andreas311.miso.common.annotation.RollbackService
import andreas311.miso.domain.environment.application.port.input.UpdateTodayEnvironmentUseCase
import andreas311.miso.domain.environment.application.port.output.QueryEnvironmentPort
import andreas311.miso.domain.environment.application.port.output.QueryTodayEnvironmentPort
import andreas311.miso.domain.environment.domain.Environment

@RollbackService
class UpdateTodayEnvironmentService(
private val queryEnvironmentPort: QueryEnvironmentPort,
private val queryTodayEnvironmentPort: QueryTodayEnvironmentPort
) : UpdateTodayEnvironmentUseCase {
override fun execute() {
val todayEnvironment = queryTodayEnvironmentPort.findOne()

val environment = getRandomEnvironment(todayEnvironment.title)

todayEnvironment.updateTodayEnvironment(environment)
}

private fun getRandomEnvironment(title: String): Environment {

val environments = queryEnvironmentPort.findAll().filterNot { it.title == title }
return environments.shuffled().first()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ data class TodayEnvironment(
var title: String,
var content: String,
var imageUrl: String?,
)
) {
fun updateTodayEnvironment(environment: Environment): TodayEnvironment {
title = environment.title
content = environment.content
imageUrl = environment.imageUrl
return this
}
}

0 comments on commit e68ae76

Please sign in to comment.