Skip to content

Commit 13683f2

Browse files
authored
release: 0.4.0 (#45)
2 parents fd231cf + 0d581f9 commit 13683f2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/main/kotlin/org/gitanimals/render/app/UserFacade.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ class UserFacade(
2828

2929
return userService.deletePersona(user.id.toLong(), personaId)
3030
}
31+
32+
fun getPersona(token: String, personaId: Long): PersonaResponse {
33+
val user = identityApi.getUserByToken(token)
34+
35+
return userService.getPersona(user.id.toLong(), personaId)
36+
}
3137
}

src/main/kotlin/org/gitanimals/render/controller/PersonaController.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class PersonaController(
2222
return UserResponse.from(userService.getUserByName(username))
2323
}
2424

25+
@GetMapping("/personas/{persona-id}")
26+
fun getPersonaById(
27+
@RequestHeader(HttpHeaders.AUTHORIZATION) token: String,
28+
@PathVariable("persona-id") personaId: Long,
29+
): PersonaResponse {
30+
val persona = userFacade.getPersona(token, personaId)
31+
32+
return PersonaResponse(persona.id, persona.type, persona.level)
33+
}
34+
2535
@PatchMapping("/personas")
2636
@ResponseStatus(HttpStatus.OK)
2737
fun changePersona(

src/main/kotlin/org/gitanimals/render/domain/UserService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class UserService(
9494
return user.deletePersona(personaId)
9595
}
9696

97+
fun getPersona(id: Long, personaId: Long): PersonaResponse {
98+
return getUserById(id).personas
99+
.find { it.id == personaId }
100+
?.let { PersonaResponse.from(it) }
101+
?: throw IllegalArgumentException("Cannot find matched persona \"$personaId\" by user \"$id\"")
102+
}
103+
97104
private fun getUserById(id: Long) = (userRepository.findByIdOrNull(id)
98105
?: throw IllegalArgumentException("Cannot find exists user by id \"$id\""))
99106
}

0 commit comments

Comments
 (0)