Skip to content

Commit

Permalink
release: 0.9.0 (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Nov 10, 2024
2 parents 128f30a + a0dafb6 commit 07220b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/org/gitanimals/render/app/UserFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class UserFacade(
return userService.getPersona(user.username, personaId)
}

fun mergePersona(token: String, request: MergePersonaRequest) {
fun mergePersona(token: String, request: MergePersonaRequest): PersonaResponse {
val user = identityApi.getUserByToken(token)

return userService.mergePersona(
user.id.toLong(),
user.username,
request.increasePersonaId.toLong(),
request.deletePersonaId.toLong(),
)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/gitanimals/render/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class User(
.append("</svg>")
.toString()

fun mergePersona(increasePersonaId: Long, deletePersonaId: Long) {
fun mergePersona(increasePersonaId: Long, deletePersonaId: Long): Persona {
require(increasePersonaId != deletePersonaId) {
"increasePersonaId \"$increasePersonaId\", deletePersonaId \"$deletePersonaId\" must be different"
}
Expand All @@ -258,6 +258,8 @@ class User(
increasePersona.level.value += deletePersona.level.value

personas.remove(deletePersona)

return increasePersona
}

companion object {
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ class UserService(

@Transactional
@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 10)
fun mergePersona(id: Long, increasePersonaId: Long, deletePersonaId: Long) {
val user = userRepository.findByIdOrNull(id)
?: throw IllegalArgumentException("Cannot find user by id \"$id\"")
fun mergePersona(
name: String,
increasePersonaId: Long,
deletePersonaId: Long,
): PersonaResponse {
val user = userRepository.findByName(name)
?: throw IllegalArgumentException("Cannot find user by name \"$name\"")

user.mergePersona(increasePersonaId, deletePersonaId)
return PersonaResponse.from(user.mergePersona(increasePersonaId, deletePersonaId))
}

@Transactional
Expand Down

0 comments on commit 07220b3

Please sign in to comment.