From 3c47b57fe65c76748e18a1e4f96dc144a89d4d0c Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Thu, 19 Oct 2023 17:22:52 +0300 Subject: [PATCH] fix: rename validate username to username available --- .../app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 2 +- .../sdk/engine/ktor/requests/users/UsersEngine.kt | 7 +++---- ...UsernameRequest.kt => UsernameAvailableRequest.kt} | 4 ++-- .../app/meetacy/sdk/users/AuthorizedUsersApi.kt | 6 ++---- .../app/meetacy/sdk/users/RegularUserRepository.kt | 6 ++---- .../app/meetacy/sdk/users/SelfUserRepository.kt | 6 ++---- .../kotlin/app/meetacy/sdk/users/UsersApi.kt | 11 +++-------- 7 files changed, 15 insertions(+), 27 deletions(-) rename api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/{ValidateUsernameRequest.kt => UsernameAvailableRequest.kt} (62%) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt index 89c62b8f..62e89fa8 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt @@ -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 diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt index 436b71d6..aa47c2d4 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt @@ -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 @@ -85,7 +85,6 @@ internal class UsersEngine( text = jsonObject.toString(), contentType = ContentType.Application.Json ) - ) }.body() @@ -96,7 +95,7 @@ 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 @@ -104,6 +103,6 @@ internal class UsersEngine( apiVersion = request.apiVersion.int.toString() ) - return ValidateUsernameRequest.Response(username = Username(response.username)) + return UsernameAvailableRequest.Response(username = Username(response.username)) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ValidateUsernameRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt similarity index 62% rename from api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ValidateUsernameRequest.kt rename to api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt index 067bba70..a54626f4 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ValidateUsernameRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt @@ -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 { +) : MeetacyRequest { public data class Response(val username: Username) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUsersApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUsersApi.kt index 1350b67d..20087ceb 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUsersApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUsersApi.kt @@ -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) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/users/RegularUserRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/users/RegularUserRepository.kt index d9399f28..464aef29 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/users/RegularUserRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/users/RegularUserRepository.kt @@ -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) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/users/SelfUserRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/users/SelfUserRepository.kt index 5e660102..e1958d69 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/users/SelfUserRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/users/SelfUserRepository.kt @@ -51,9 +51,7 @@ public class SelfUserRepository( avatarId: Optional = 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) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/users/UsersApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/users/UsersApi.kt index b1bb356b..8bccc2af 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/users/UsersApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/users/UsersApi.kt @@ -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 @@ -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 } }