Skip to content

Commit

Permalink
fix: rename validate username to username available
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Oct 19, 2023
1 parent 21b5334 commit 3c47b57
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class KtorMeetacyEngine(
is GetMeRequest -> users.getMe(request) as T
is GetUserRequest -> users.getUser(request) as T
is EditUserRequest -> users.editUser(request) as T
is ValidateUsernameRequest -> users.validateUsername(request) as T
is UsernameAvailableRequest -> users.usernameAvailable(request) as T
// meetings
is ListMeetingsHistoryRequest -> meetings.listMeetingsHistory(request) as T
is ListActiveMeetingsRequest -> meetings.listActiveMeetings(request) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import app.meetacy.sdk.engine.ktor.mapToUser
import app.meetacy.sdk.engine.requests.EditUserRequest
import app.meetacy.sdk.engine.requests.GetMeRequest
import app.meetacy.sdk.engine.requests.GetUserRequest
import app.meetacy.sdk.engine.requests.ValidateUsernameRequest
import app.meetacy.sdk.engine.requests.UsernameAvailableRequest
import app.meetacy.sdk.exception.meetacyApiError
import app.meetacy.sdk.types.annotation.UnsafeConstructor
import app.meetacy.sdk.types.optional.ifPresent
Expand Down Expand Up @@ -85,7 +85,6 @@ internal class UsersEngine(
text = jsonObject.toString(),
contentType = ContentType.Application.Json
)

)

}.body<String>()
Expand All @@ -96,14 +95,14 @@ internal class UsersEngine(
}

@OptIn(UnsafeConstructor::class)
suspend fun validateUsername(request: ValidateUsernameRequest): ValidateUsernameRequest.Response {
suspend fun usernameAvailable(request: UsernameAvailableRequest): UsernameAvailableRequest.Response {
val response = base.usersValidatePost(
validateUsernameRequest = GeneratedValidateUsernameRequest(
username = request.username.string
),
apiVersion = request.apiVersion.int.toString()
)

return ValidateUsernameRequest.Response(username = Username(response.username))
return UsernameAvailableRequest.Response(username = Username(response.username))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package app.meetacy.sdk.engine.requests

import app.meetacy.sdk.types.user.Username

public data class ValidateUsernameRequest(
public data class UsernameAvailableRequest(
val username: Username
) : MeetacyRequest<ValidateUsernameRequest.Response> {
) : MeetacyRequest<UsernameAvailableRequest.Response> {
public data class Response(val username: Username)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public class AuthorizedUsersApi(private val api: AuthorizedMeetacyApi) {
)
}

public suspend fun validateUsername(
username: String
): Username {
return base.validateUsername(username)
public suspend fun usernameAvailable(username: Username): Username {
return base.usernameAvailable(username)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public class RegularUserRepository(
api.friends.delete(token, data.id)
}

public suspend fun validateUsername(
username: String
): Username {
return api.users.validateUsername(username)
public suspend fun usernameAvailable(username: Username): Username {
return api.users.usernameAvailable(username)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public class SelfUserRepository(
avatarId: Optional<FileId?> = Optional.Undefined
): SelfUserRepository = api.users.edit(token, nickname, username, avatarId)

public suspend fun validateUsername(
username: String
): Username {
return api.users.validateUsername(username)
public suspend fun usernameAvailable(username: Username): Username {
return api.users.usernameAvailable(username)
}
}
11 changes: 3 additions & 8 deletions api/src/commonMain/kotlin/app/meetacy/sdk/users/UsersApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package app.meetacy.sdk.users
import app.meetacy.sdk.MeetacyApi
import app.meetacy.sdk.engine.requests.EditUserRequest
import app.meetacy.sdk.engine.requests.GetUserRequest
import app.meetacy.sdk.engine.requests.ValidateUsernameRequest
import app.meetacy.sdk.types.annotation.UnsafeConstructor
import app.meetacy.sdk.engine.requests.UsernameAvailableRequest
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.file.FileId
import app.meetacy.sdk.types.optional.Optional
Expand Down Expand Up @@ -49,12 +48,8 @@ public class UsersApi(private val api: MeetacyApi) {
)
}

@OptIn(UnsafeConstructor::class)
public suspend fun validateUsername(
username: String
): Username {
val result = api.engine.execute(ValidateUsernameRequest(username = Username(username)))

public suspend fun usernameAvailable(username: Username): Username {
val result = api.engine.execute(UsernameAvailableRequest(username))
return result.username
}
}

0 comments on commit 3c47b57

Please sign in to comment.