Skip to content

Commit

Permalink
feat(#91-change-getUser-request-type): change getUser request type
Browse files Browse the repository at this point in the history
  • Loading branch information
y9Kap committed Mar 4, 2024
1 parent 3dc562e commit 7bc763e
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,21 @@ internal class UsersEngine(
) {
private val baseUrl = baseUrl / "users"

private fun toBody() = GetUserBody(null)

suspend fun getMe(request: GetMeRequest): GetMeRequest.Response {
val url = baseUrl / "get"
val body = toBody()
val response = httpClient.post(url.string) {
val response = httpClient.get(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
}.bodyAsSuccess<UserDetailsSerializable>()
return GetMeRequest.Response(response.type() as SelfUserDetails)
}

@Serializable
private data class GetUserBody(val id: UserIdSerializable?)
private fun GetUserRequest.toBody() = GetUserBody(userId?.serializable())

suspend fun getUser(request: GetUserRequest): GetUserRequest.Response {
val url = baseUrl / "get"
val body = request.toBody()
val response = httpClient.post(url.string) {
val response = httpClient.get(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
parameter("id", request.userId)
}.bodyAsSuccess<UserDetailsSerializable>()
return GetUserRequest.Response(response.type())
}
Expand Down

0 comments on commit 7bc763e

Please sign in to comment.