From 837689ae9cbb503987729950326375cddc18549c Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 15 Apr 2024 16:57:13 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20Sentry=20test=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../render/controller/SentryController.kt | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/main/kotlin/org/gitanimals/render/controller/SentryController.kt diff --git a/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt b/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt deleted file mode 100644 index 364bfd4..0000000 --- a/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.gitanimals.render.controller - -import io.sentry.Sentry -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class SentryController { - - @GetMapping("/sentries") - fun sentryCall() { - Sentry.captureException(IllegalArgumentException("This is test.")) - } -} From 6071e93337d0ab324770be26ea60cdd2311a8025 Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 15 Apr 2024 16:57:13 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20Sentry=20test=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../render/controller/SentryController.kt | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/main/kotlin/org/gitanimals/render/controller/SentryController.kt diff --git a/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt b/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt deleted file mode 100644 index 364bfd4..0000000 --- a/src/main/kotlin/org/gitanimals/render/controller/SentryController.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.gitanimals.render.controller - -import io.sentry.Sentry -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class SentryController { - - @GetMapping("/sentries") - fun sentryCall() { - Sentry.captureException(IllegalArgumentException("This is test.")) - } -} From d110bcd592ad2040d098ced3ec0d1647593bed41 Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 15 Apr 2024 17:47:28 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20user=20create=EC=8B=9C,=20Orche?= =?UTF-8?q?strator=EB=A5=BC=20=EC=A0=9C=EA=B1=B0=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitanimals/render/app/AnimationFacade.kt | 62 +++++-------------- .../org/gitanimals/render/domain/User.kt | 2 + 2 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt b/src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt index 41c737f..fd5d15d 100644 --- a/src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt +++ b/src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt @@ -1,22 +1,19 @@ package org.gitanimals.render.app -import jakarta.annotation.PostConstruct import org.gitanimals.render.domain.User import org.gitanimals.render.domain.UserService import org.gitanimals.render.domain.event.Visited -import org.rooftop.netx.api.* +import org.rooftop.netx.api.SagaManager import org.springframework.stereotype.Service +import org.springframework.web.client.RestClientException @Service class AnimationFacade( private val userService: UserService, private val contributionApi: ContributionApi, - private val orchestratorFactory: OrchestratorFactory, private val sagaManager: SagaManager, ) { - private lateinit var registerNewUserOrchestrator: Orchestrator - fun getFarmAnimation(username: String): String { return when (userService.existsByName(username)) { true -> { @@ -26,15 +23,14 @@ class AnimationFacade( } false -> { - registerNewUserOrchestrator.sagaSync(10000, username) - - userService.getFarmAnimationByUsername(username) + val user = createNewUser(username) + userService.getFarmAnimationByUsername(user.name) } } } fun getLineAnimation(username: String, personaId: Long): String { - return when(userService.existsByName(username)) { + return when (userService.existsByName(username)) { true -> { val svgAnimation = userService.getLineAnimationByUsername(username, personaId) sagaManager.startSync(Visited(username)) @@ -42,45 +38,21 @@ class AnimationFacade( } false -> { - registerNewUserOrchestrator.sagaSync(10000, username) - - userService.getLineAnimationByUsername(username ,personaId) + val user = createNewUser(username) + userService.getLineAnimationByUsername(user.name, personaId) } } } - @PostConstruct - fun registerNewUserOrchestrator() { - registerNewUserOrchestrator = orchestratorFactory.create("register new user") - .startWithContext( - contextOrchestrate = { context, username -> - context.set("username", username) - contributionApi.getAllContributionYears(username) - } - ) - .joinWithContext( - contextOrchestrate = object : ContextOrchestrate, Map> { - override fun orchestrate(context: Context, request: List): Map { - val username = context.decodeContext("username", String::class) - return contributionApi.getContributionCount(username, request) - } - - override fun reified(): TypeReference> { - return object : TypeReference>() {} - } - } - ) - .commitWithContext( - contextOrchestrate = object : ContextOrchestrate, User> { - override fun orchestrate(context: Context, request: Map): User { - val username = context.decodeContext("username", String::class) - return userService.createNewUser(username, request) - } - - override fun reified(): TypeReference> { - return object : TypeReference>() {} - } - } - ) + fun createNewUser(username: String): User { + return runCatching { + val contributionYears = contributionApi.getAllContributionYears(username) + val contributionCountPerYear = + contributionApi.getContributionCount(username, contributionYears) + userService.createNewUser(username, contributionCountPerYear) + }.getOrElse { + require(it !is RestClientException) { "Cannot create new user from username \"$username\"" } + throw it + } } } diff --git a/src/main/kotlin/org/gitanimals/render/domain/User.kt b/src/main/kotlin/org/gitanimals/render/domain/User.kt index c831a33..8cad6f2 100644 --- a/src/main/kotlin/org/gitanimals/render/domain/User.kt +++ b/src/main/kotlin/org/gitanimals/render/domain/User.kt @@ -1,5 +1,6 @@ package org.gitanimals.render.domain +import com.fasterxml.jackson.annotation.JsonIgnore import jakarta.persistence.* import org.gitanimals.render.core.AggregateRoot import org.gitanimals.render.domain.value.Contribution @@ -50,6 +51,7 @@ class User( personas.forEach { it.user = this } } + @JsonIgnore fun isContributionUpdatedBeforeOneHour(): Boolean { val currentYear = ZonedDateTime.now(ZoneId.of("UTC")).year val currentYearContribution =