From a8e4801384b4578d6e45dbb55cec88a3e09b54b0 Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 6 Jan 2025 22:34:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B8=B8=EB=93=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20Guild=20=EC=9D=91=EB=8B=B5=EC=9D=84=20?= =?UTF-8?q?=EB=82=B4=EB=A0=A4=EC=A3=BC=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt | 9 +++++---- .../org/gitanimals/guild/controller/GuildController.kt | 2 +- .../kotlin/org/gitanimals/guild/domain/GuildService.kt | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt b/src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt index d29d831..a15b25e 100644 --- a/src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt +++ b/src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt @@ -1,6 +1,7 @@ package org.gitanimals.guild.app import org.gitanimals.guild.app.request.CreateGuildRequest +import org.gitanimals.guild.domain.Guild import org.gitanimals.guild.domain.GuildService import org.gitanimals.guild.domain.request.CreateLeaderRequest import org.rooftop.netx.api.Orchestrator @@ -19,17 +20,17 @@ class CreateGuildFacade( orchestratorFactory: OrchestratorFactory, ) { - private lateinit var createGuildOrchestrator: Orchestrator + private lateinit var createGuildOrchestrator: Orchestrator fun createGuild( token: String, createGuildRequest: CreateGuildRequest, - ) { - createGuildOrchestrator.sagaSync( + ): Guild { + return createGuildOrchestrator.sagaSync( request = createGuildRequest, context = mapOf("token" to token, IDEMPOTENCY_KEY to UUID.randomUUID().toString()), timeoutMillis = 1.minutes.inWholeMilliseconds, - ).decodeResultOrThrow(Unit::class) + ).decodeResultOrThrow(Guild::class) } init { diff --git a/src/main/kotlin/org/gitanimals/guild/controller/GuildController.kt b/src/main/kotlin/org/gitanimals/guild/controller/GuildController.kt index 54575e3..fb0e0ec 100644 --- a/src/main/kotlin/org/gitanimals/guild/controller/GuildController.kt +++ b/src/main/kotlin/org/gitanimals/guild/controller/GuildController.kt @@ -36,7 +36,7 @@ class GuildController( fun createGuild( @RequestHeader(HttpHeaders.AUTHORIZATION) token: String, @RequestBody createGuildRequest: CreateGuildRequest, - ) = createGuildFacade.createGuild(token, createGuildRequest) + ) = GuildResponse.from(createGuildFacade.createGuild(token, createGuildRequest)) @ResponseStatus(HttpStatus.OK) @PostMapping("/guilds/{guildId}") diff --git a/src/main/kotlin/org/gitanimals/guild/domain/GuildService.kt b/src/main/kotlin/org/gitanimals/guild/domain/GuildService.kt index cfb83e0..de66357 100644 --- a/src/main/kotlin/org/gitanimals/guild/domain/GuildService.kt +++ b/src/main/kotlin/org/gitanimals/guild/domain/GuildService.kt @@ -27,7 +27,7 @@ class GuildService( farmType: FieldType, autoJoin: Boolean, createLeaderRequest: CreateLeaderRequest, - ) { + ): Guild { require(guildRepository.existsByTitle(title).not()) { "Cannot create guild cause duplicated guild already exists." } @@ -43,7 +43,7 @@ class GuildService( autoJoin = autoJoin, ) - guildRepository.save(newGuild) + return guildRepository.save(newGuild) } @Transactional