Skip to content

Commit

Permalink
refactor: 길드 생성시 Guild 응답을 내려주도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Jan 6, 2025
1 parent 903d89f commit a8e4801
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,17 +20,17 @@ class CreateGuildFacade(
orchestratorFactory: OrchestratorFactory,
) {

private lateinit var createGuildOrchestrator: Orchestrator<CreateGuildRequest, Unit>
private lateinit var createGuildOrchestrator: Orchestrator<CreateGuildRequest, Guild>

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/gitanimals/guild/domain/GuildService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand All @@ -43,7 +43,7 @@ class GuildService(
autoJoin = autoJoin,
)

guildRepository.save(newGuild)
return guildRepository.save(newGuild)
}

@Transactional
Expand Down

0 comments on commit a8e4801

Please sign in to comment.