Skip to content

Commit

Permalink
release: 0.4.0 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Apr 29, 2024
2 parents fd231cf + 0d581f9 commit 13683f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/org/gitanimals/render/app/UserFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ class UserFacade(

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

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

return userService.getPersona(user.id.toLong(), personaId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class PersonaController(
return UserResponse.from(userService.getUserByName(username))
}

@GetMapping("/personas/{persona-id}")
fun getPersonaById(
@RequestHeader(HttpHeaders.AUTHORIZATION) token: String,
@PathVariable("persona-id") personaId: Long,
): PersonaResponse {
val persona = userFacade.getPersona(token, personaId)

return PersonaResponse(persona.id, persona.type, persona.level)
}

@PatchMapping("/personas")
@ResponseStatus(HttpStatus.OK)
fun changePersona(
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class UserService(
return user.deletePersona(personaId)
}

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

private fun getUserById(id: Long) = (userRepository.findByIdOrNull(id)
?: throw IllegalArgumentException("Cannot find exists user by id \"$id\""))
}

0 comments on commit 13683f2

Please sign in to comment.