Skip to content

Commit

Permalink
release: 0.5.1 (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored May 12, 2024
2 parents 2b62762 + a0fd49f commit f1ae6b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 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 @@ -11,10 +11,10 @@ class UserFacade(
private val identityApi: IdentityApi,
) {

fun changePersona(token: String, personChangeRequest: PersonaChangeRequest) {
fun changePersona(token: String, personChangeRequest: PersonaChangeRequest): PersonaResponse {
val user = identityApi.getUserByToken(token)

userService.changePersona(user.username, personChangeRequest)
return userService.changePersona(user.username, personChangeRequest)
}

fun addPersona(token: String, idempotencyKey: String, personaType: String): PersonaResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ class PersonaController(
fun changePersona(
@RequestHeader(HttpHeaders.AUTHORIZATION) token: String,
@RequestBody personaChangeRequest: PersonaChangeRequest,
) = userFacade.changePersona(token, personaChangeRequest)
): PersonaResponse {
val changedPersona = userFacade.changePersona(token, personaChangeRequest)

return PersonaResponse(
changedPersona.id,
changedPersona.type,
changedPersona.level,
changedPersona.visible,
)
}

@PostMapping("/internals/personas")
fun addPersona(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/gitanimals/render/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class User(
)
}

fun changePersonaVisible(personaId: Long, visible: Boolean) {
fun changePersonaVisible(personaId: Long, visible: Boolean): Persona {
val persona = personas.find { it.id == personaId }
?: throw IllegalArgumentException("Cannot find persona by id \"$personaId\"")

Expand All @@ -94,6 +94,7 @@ class User(
}

persona.visible = visible
return persona
}

fun updateContribution(contribution: Int) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class UserService(

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

user.changePersonaVisible(
val changedPersona = user.changePersonaVisible(
personChangeRequest.personaId.toLong(),
personChangeRequest.visible
)

return PersonaResponse.from(changedPersona)
}

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100)
Expand Down

0 comments on commit f1ae6b1

Please sign in to comment.