Skip to content

Commit

Permalink
release: 0.4.7 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored May 11, 2024
2 parents 8b70488 + 4dce8eb commit 5f7819d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/org/gitanimals/render/app/UserFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class UserFacade(
fun changePersona(token: String, personChangeRequest: PersonaChangeRequest) {
val user = identityApi.getUserByToken(token)

userService.changePersona(user.id.toLong(), personChangeRequest)
userService.changePersona(user.username, personChangeRequest)
}

fun addPersona(token: String, idempotencyKey: String, personaType: String): PersonaResponse {
val user = identityApi.getUserByToken(token)

return userService.addPersona(user.id.toLong(), personaType, idempotencyKey)
return userService.addPersona(user.username, personaType, idempotencyKey)
}

fun deletePersona(token: String, personaId: Long): PersonaResponse {
val user = identityApi.getUserByToken(token)

return userService.deletePersona(user.id.toLong(), personaId)
return userService.deletePersona(user.username, personaId)
}

fun getPersona(token: String, personaId: Long): PersonaResponse {
val user = identityApi.getUserByToken(token)

return userService.getPersona(user.id.toLong(), personaId)
return userService.getPersona(user.username, personaId)
}
}
21 changes: 9 additions & 12 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class UserService(

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100)
@Transactional
fun changePersona(id: Long, personChangeRequest: PersonaChangeRequest) {
val user = getUserById(id)
fun changePersona(name: String, personChangeRequest: PersonaChangeRequest) {
val user = getUserByName(name)

user.changePersonaVisible(
personChangeRequest.personaId.toLong(),
Expand All @@ -72,10 +72,10 @@ class UserService(

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100)
@Transactional
fun addPersona(id: Long, personaType: String, idempotencyKey: String): PersonaResponse {
fun addPersona(name: String, personaType: String, idempotencyKey: String): PersonaResponse {
requireIdempotency("addPersona:$idempotencyKey")

val user = getUserById(id)
val user = getUserByName(name)

return user.addPersona(PersonaType.valueOf(personaType.uppercase()))
}
Expand All @@ -90,19 +90,16 @@ class UserService(

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100)
@Transactional
fun deletePersona(id: Long, personaId: Long): PersonaResponse {
val user = getUserById(id)
fun deletePersona(name: String, personaId: Long): PersonaResponse {
val user = getUserByName(name)

return user.deletePersona(personaId)
}

fun getPersona(id: Long, personaId: Long): PersonaResponse {
return getUserById(id).personas
fun getPersona(name: String, personaId: Long): PersonaResponse {
return getUserByName(name).personas
.find { it.id == personaId }
?.let { PersonaResponse.from(it) }
?: throw IllegalArgumentException("Cannot find matched persona \"$personaId\" by user \"$id\"")
?: throw IllegalArgumentException("Cannot find matched persona \"$personaId\" by user name \"$name\"")
}

private fun getUserById(id: Long) = (userRepository.findByIdOrNull(id)
?: throw IllegalArgumentException("Cannot find exists user by id \"$id\""))
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ internal class UserServiceTest(
describe("deletePersona 메소드는") {
context("userId와 personaId를 받으면,") {
val personaId = user.personas[0].id
val userId = user.id

it("persona를 삭제한다.") {
val response = userService.deletePersona(userId, personaId)
val response = userService.deletePersona(user.name, personaId)
val user = userService.getUserByName(user.name)

user.personas
Expand Down

0 comments on commit 5f7819d

Please sign in to comment.