From f08f485f3df9a4d4f32b7529c95284cfe9787748 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 25 Oct 2023 16:46:13 +0300 Subject: [PATCH 01/56] WIP: feat: started adding search endpoint --- api/api-ktor/build.gradle.kts | 1 + .../sdk/engine/ktor/HttpRequestBuilder.kt | 14 +++ .../sdk/engine/ktor/KtorMeetacyEngine.kt | 5 +- .../app/meetacy/sdk/engine/ktor/Mappers.kt | 104 ------------------ .../engine/ktor/requests/auth/AuthEngine.kt | 34 +++--- .../requests/extencion/RequestBodyPost.kt | 45 -------- .../ktor/requests/friends/FriendsEngine.kt | 20 ++-- .../requests/invitations/InvitationsEngine.kt | 18 +-- .../ktor/requests/meetings/MeetingsEngine.kt | 42 +++---- .../notifications/NotificationsEngine.kt | 12 +- .../ktor/requests/search/SearchEngine.kt | 20 ++++ .../ktor/requests/updates/UpdatesEngine.kt | 2 +- .../engine/ktor/requests/users/UsersEngine.kt | 89 ++++++++------- .../sdk/engine/ktor/response/Response.kt | 30 +++-- .../models/CreateInvitationResponse.kt | 15 --- .../response/models/CreateMeetingResponse.kt | 15 --- .../response/models/EditMeetingResponse.kt | 15 --- .../ktor/response/models/EditUserResponse.kt | 21 ---- .../models/GenerateIdentityResponse.kt | 21 ---- .../ktor/response/models/GetUserRequest.kt | 18 --- .../ktor/response/models/GetUserResponse.kt | 15 --- .../engine/ktor/response/models/Invitation.kt | 30 ----- .../response/models/ListFriendsResponse.kt | 21 ---- .../models/ListFriendsResponseResult.kt | 21 ---- .../models/ListMapMeetingsResponse.kt | 21 ---- .../models/ListMeetingParticipantsResponse.kt | 15 --- .../ListMeetingParticipantsResponseResult.kt | 21 ---- .../response/models/ListMeetingsResponse.kt | 21 ---- .../models/ListMeetingsResponseResult.kt | 22 ---- .../models/ListNotificationsResponse.kt | 21 ---- .../models/ListNotificationsResponseResult.kt | 21 ---- .../engine/ktor/response/models/Location.kt | 21 ---- .../engine/ktor/response/models/Meeting.kt | 55 --------- .../ktor/response/models/Notification.kt | 48 -------- .../response/models/StatusTrueResponse.kt | 18 --- .../sdk/engine/ktor/response/models/User.kt | 34 ------ .../models/ValidateUsernameRequest.kt | 18 --- .../sdk/engine/requests/MeetacyRequest.kt | 1 - .../sdk/engine/requests/RequestRepository.kt | 11 -- .../sdk/engine/requests/SearchRequest.kt | 13 +++ settings.gradle.kts | 1 + types/serializable/build.gradle.kts | 10 ++ .../serializable/email/EmailSerializable.kt | 15 +++ .../serializable/file/FileIdSerializable.kt | 12 ++ .../optional/OptionalSerializable.kt | 57 ++++++++++ .../user/RelationshipSerializable.kt | 31 ++++++ .../serializable/user/UserIdSerializable.kt | 15 +++ .../serializable/user/UserSerializable.kt | 50 +++++++++ .../serializable/user/UsernameSerializable.kt | 15 +++ .../app/meetacy/sdk/types/address/Address.kt | 8 ++ .../app/meetacy/sdk/types/place/Place.kt | 9 ++ .../meetacy/sdk/types/search/SearchItem.kt | 11 ++ 52 files changed, 415 insertions(+), 808 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/HttpRequestBuilder.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/extencion/RequestBodyPost.kt create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateInvitationResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateMeetingResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditMeetingResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditUserResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GenerateIdentityResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserRequest.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Invitation.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponseResult.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMapMeetingsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponseResult.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponseResult.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponseResult.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Location.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Meeting.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Notification.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/StatusTrueResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/User.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ValidateUsernameRequest.kt delete mode 100644 api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/RequestRepository.kt create mode 100644 api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/SearchRequest.kt create mode 100644 types/serializable/build.gradle.kts create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/email/EmailSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/file/FileIdSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/optional/OptionalSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/RelationshipSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserIdSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UsernameSerializable.kt create mode 100644 types/src/commonMain/kotlin/app/meetacy/sdk/types/address/Address.kt create mode 100644 types/src/commonMain/kotlin/app/meetacy/sdk/types/place/Place.kt create mode 100644 types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt diff --git a/api/api-ktor/build.gradle.kts b/api/api-ktor/build.gradle.kts index 3fc21dd5..5b09f734 100644 --- a/api/api-ktor/build.gradle.kts +++ b/api/api-ktor/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { commonMainImplementation(libs.rsocketKtorClient) commonMainApi(projects.api) + commonMainImplementation(projects.types.serializable) jvmTestImplementation(libs.ktorClientCio) } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/HttpRequestBuilder.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/HttpRequestBuilder.kt new file mode 100644 index 00000000..5adabf66 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/HttpRequestBuilder.kt @@ -0,0 +1,14 @@ +package app.meetacy.sdk.engine.ktor + +import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.version.ApiVersion +import io.ktor.client.request.* +import io.ktor.http.* + +public fun HttpRequestBuilder.apiVersion(apiVersion: ApiVersion) { + header("Api-Version", apiVersion.int) +} + +public fun HttpRequestBuilder.token(token: Token) { + header(HttpHeaders.Authorization, token.string) +} 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 c831e2c0..e62efccf 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 @@ -8,6 +8,7 @@ import app.meetacy.sdk.engine.ktor.requests.friends.FriendsEngine import app.meetacy.sdk.engine.ktor.requests.invitations.InvitationsEngine import app.meetacy.sdk.engine.ktor.requests.meetings.MeetingsEngine import app.meetacy.sdk.engine.ktor.requests.notifications.NotificationsEngine +import app.meetacy.sdk.engine.ktor.requests.search.SearchEngine import app.meetacy.sdk.engine.ktor.requests.updates.UpdatesEngine import app.meetacy.sdk.engine.ktor.requests.users.UsersEngine import app.meetacy.sdk.engine.ktor.response.ServerResponse @@ -51,6 +52,7 @@ public class KtorMeetacyEngine( private val files = FilesEngine(baseUrl, this.httpClient) private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json) private val notifications = NotificationsEngine(baseUrl, this.httpClient, this.json) + private val search = SearchEngine(baseUrl, this.httpClient) private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json) override fun getFileUrl( @@ -93,12 +95,13 @@ public class KtorMeetacyEngine( // notifications is ReadNotificationRequest -> notifications.read(request) as T is ListNotificationsRequest -> notifications.list(request) as T + // search + is SearchRequest -> search.search(request) as T // updates is EmitUpdatesRequest -> updates.stream(request) as T // not yet supported is LinkEmailRequest -> notSupported() is ConfirmEmailRequest -> notSupported() - is TokenProviderEmpty -> notSupported() } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt deleted file mode 100644 index 27958966..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt +++ /dev/null @@ -1,104 +0,0 @@ -@file:OptIn(UnsafeConstructor::class) - -package app.meetacy.sdk.engine.ktor - -import app.meetacy.sdk.types.annotation.UnsafeConstructor -import app.meetacy.sdk.types.datetime.Date -import app.meetacy.sdk.types.email.Email -import app.meetacy.sdk.types.file.FileId -import app.meetacy.sdk.types.invitation.AcceptationState -import app.meetacy.sdk.types.invitation.Invitation -import app.meetacy.sdk.types.invitation.InvitationId -import app.meetacy.sdk.types.location.Location -import app.meetacy.sdk.types.meeting.Meeting -import app.meetacy.sdk.types.meeting.MeetingId -import app.meetacy.sdk.types.notification.Notification -import app.meetacy.sdk.types.notification.NotificationId -import app.meetacy.sdk.types.user.* -import app.meetacy.sdk.engine.ktor.response.models.Invitation as ModelInvitation -import app.meetacy.sdk.engine.ktor.response.models.Location as ModelLocation -import app.meetacy.sdk.engine.ktor.response.models.Meeting as ModelMeeting -import app.meetacy.sdk.engine.ktor.response.models.Notification as ModelNotification -import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser - -internal fun ModelUser.mapToSelfUser(): SelfUser = mapToUser() as SelfUser -internal fun ModelUser.mapToRegularUser(): RegularUser = mapToUser() as RegularUser - -@OptIn(UnsafeConstructor::class) -internal fun ModelUser.mapToUser(): User = if (isSelf) { - SelfUser( - id = UserId(id), - nickname = nickname, - email = email?.let(::Email), - emailVerified = emailVerified ?: error("Self user must always return emailVerified parameter"), - username = username?.let(::Username), - avatarId = avatarId?.let(::FileId) - ) -} else { - RegularUser( - id = UserId(id), - nickname = nickname, - avatarId = avatarId?.let(::FileId), - username = username?.let(::Username), - relationship = relationship?.mapToRelationship() ?: error("Regular user should always return relationship parameter") - ) -} - -internal fun ModelInvitation.toInvitation(): Invitation = Invitation( - id = identity.let(::InvitationId), - meeting = meeting.mapToMeeting(), - invitedUser = invitedUser.mapToUser(), - inviterUser = inviterUser.mapToUser(), - isAccepted = when (isAccepted) { - null -> AcceptationState.Waiting - true -> AcceptationState.Accepted - false -> AcceptationState.Declined - } -) - -internal fun String.mapToRelationship(): Relationship? = when(this) { - "none" -> Relationship.None - "subscription" -> Relationship.Subscription - "subscriber" -> Relationship.Subscriber - "friend" -> Relationship.Friend - else -> null -} - -internal fun ModelMeeting.mapToMeeting(): Meeting = Meeting( - id = MeetingId(id), - creator = creator.mapToUser(), - date = Date(date), - location = Location( - location.latitude, - location.longitude - ), - title = title, - description = description, - participantsCount = participantsCount, - isParticipating = isParticipating, - previewParticipants = previewParticipants.map(ModelUser::mapToUser), - avatarId = avatarId?.let(::FileId), - visibility = when (visibility) { - ModelMeeting.Visibility.PUBLIC -> Meeting.Visibility.Public - ModelMeeting.Visibility.PRIVATE -> Meeting.Visibility.Private - } -) - -internal fun ModelLocation.mapToLocation(): Location = - Location(latitude, longitude) - -internal fun ModelNotification.mapToNotification(): Notification = when (this.type) { - app.meetacy.sdk.engine.ktor.response.models.Notification.Type.SUBSCRIPTION -> Notification.Subscription( - id = NotificationId(id), - isNew = isNew, - date = Date(date), - subscriber = subscriber!!.mapToRegularUser() - ) - app.meetacy.sdk.engine.ktor.response.models.Notification.Type.MEETING_INVITATION -> Notification.Invitation( - id = NotificationId(id), - isNew = isNew, - date = Date(date), - meeting = meeting!!.mapToMeeting(), - inviter = inviter!!.mapToRegularUser() - ) -} \ No newline at end of file diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/auth/AuthEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/auth/AuthEngine.kt index 81c973aa..31ac52e8 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/auth/AuthEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/auth/AuthEngine.kt @@ -2,33 +2,33 @@ package app.meetacy.sdk.engine.ktor.requests.auth -import app.meetacy.sdk.engine.ktor.requests.extencion.postWithoutToken -import app.meetacy.sdk.engine.ktor.response.models.GenerateIdentityResponse +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.requests.GenerateAuthRequest import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.url.Url import io.ktor.client.* -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put +import io.ktor.client.request.* +import kotlinx.serialization.Serializable internal class AuthEngine( private val baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { + @Serializable + private data class GenerateAuthBody(val nickname: String) + suspend fun generate(request: GenerateAuthRequest): GenerateAuthRequest.Response { val url = baseUrl / "auth" / "generate" - - val jsonObject = buildJsonObject { - put("nickname", request.nickname) - } - - val string = postWithoutToken(url.string, jsonObject, httpClient, request) - - val token = json.decodeFromString(string).result - - return GenerateAuthRequest.Response(token = Token(token)) + val body = GenerateAuthBody(request.nickname) + val response = httpClient + .post(url.string) { + apiVersion(request.apiVersion) + setBody(body) + } + .bodyAsSuccess() + val result = Token(response) + return GenerateAuthRequest.Response(result) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/extencion/RequestBodyPost.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/extencion/RequestBodyPost.kt deleted file mode 100644 index e4a449c9..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/extencion/RequestBodyPost.kt +++ /dev/null @@ -1,45 +0,0 @@ -package app.meetacy.sdk.engine.ktor.requests.extencion - -import app.meetacy.sdk.engine.requests.MeetacyRequestWithToken -import app.meetacy.sdk.engine.requests.TokenProviderEmpty -import io.ktor.client.* -import io.ktor.client.call.* -import io.ktor.client.request.* -import io.ktor.http.* -import io.ktor.http.content.* -import kotlinx.serialization.json.JsonObject - -public suspend inline fun > post( - urlString: String, - jsonObject: JsonObject, - httpClient: HttpClient, - request: R -): String = - httpClient.post(urlString) { - setBody( - TextContent( - text = jsonObject.toString(), - contentType = ContentType.Application.Json - ) - ) - header("Authorization", request.token.string) - header("Api-Version", request.apiVersion.int.toString()) - }.body() - - -public suspend inline fun > postWithoutToken( - url: String, - jsonObject: JsonObject, - httpClient: HttpClient, - request: R -): String { - return httpClient.post(url) { - setBody( - TextContent( - text = jsonObject.toString(), - contentType = ContentType.Application.Json - ) - ) - header("Api-Version", request.apiVersion.int.toString()) - }.body() -} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index e6d72351..34e0ed76 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -7,10 +7,10 @@ import app.meetacy.sdk.engine.ktor.mapToLocation import app.meetacy.sdk.engine.ktor.mapToRegularUser import app.meetacy.sdk.engine.ktor.mapToUser import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.response.models.ListFriendsResponse -import app.meetacy.sdk.engine.ktor.response.models.Location as ModelLocation -import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse -import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser +import app.meetacy.sdk.engine.ktor.models.ListFriendsResponse +import app.meetacy.sdk.engine.ktor.models.Location as ModelLocation +import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.models.User as ModelUser import app.meetacy.sdk.engine.requests.AddFriendRequest import app.meetacy.sdk.engine.requests.DeleteFriendRequest import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest @@ -43,7 +43,7 @@ internal class FriendsEngine( ) { private val baseUrl = baseUrl / "friends" - suspend fun add(request: AddFriendRequest): StatusTrueResponse { + suspend fun add(request: AddFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "add" val jsonObject = buildJsonObject { @@ -52,10 +52,10 @@ internal class FriendsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } - suspend fun delete(request: DeleteFriendRequest): StatusTrueResponse { + suspend fun delete(request: DeleteFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "delete" val jsonObject = buildJsonObject { @@ -64,20 +64,20 @@ internal class FriendsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } suspend fun list(request: ListFriendsRequest): ListFriendsRequest.Response { val url = baseUrl / "list" val jsonObject = buildJsonObject { - put("amount", request.amount.int.toString()) + put("amount", request.amount.int) put("pagingId", request.pagingId?.string) } val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = Json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt index 6da14d01..0e8ec410 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt @@ -1,8 +1,8 @@ package app.meetacy.sdk.engine.ktor.requests.invitations import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.response.models.CreateInvitationResponse -import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.models.CreateInvitationResponse +import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse import app.meetacy.sdk.engine.ktor.toInvitation import app.meetacy.sdk.engine.requests.AcceptInvitationRequest import app.meetacy.sdk.engine.requests.CancelInvitationRequest @@ -32,14 +32,14 @@ internal class InvitationsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result return CreateInvitationRequest.Response(response.toInvitation()) } suspend fun accept( request: AcceptInvitationRequest - ): StatusTrueResponse { + ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "accept" val jsonObject = buildJsonObject { @@ -48,12 +48,12 @@ internal class InvitationsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } suspend fun deny( request: DenyInvitationRequest - ): StatusTrueResponse { + ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "deny" val jsonObject = buildJsonObject { @@ -62,12 +62,12 @@ internal class InvitationsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } suspend fun cancel( request: CancelInvitationRequest - ): StatusTrueResponse { + ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "cancel" val jsonObject = buildJsonObject { @@ -76,7 +76,7 @@ internal class InvitationsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 2152b7f0..29b5279c 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -4,12 +4,12 @@ import app.meetacy.sdk.engine.ktor.mapToMeeting import app.meetacy.sdk.engine.ktor.mapToUser import app.meetacy.sdk.engine.ktor.requests.extencion.post import app.meetacy.sdk.engine.ktor.response.models.* -import app.meetacy.sdk.engine.ktor.response.models.CreateMeetingResponse -import app.meetacy.sdk.engine.ktor.response.models.EditMeetingResponse -import app.meetacy.sdk.engine.ktor.response.models.ListMapMeetingsResponse -import app.meetacy.sdk.engine.ktor.response.models.ListMeetingParticipantsResponse -import app.meetacy.sdk.engine.ktor.response.models.ListMeetingsResponse -import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser +import app.meetacy.sdk.engine.ktor.models.CreateMeetingResponse +import app.meetacy.sdk.engine.ktor.models.EditMeetingResponse +import app.meetacy.sdk.engine.ktor.models.ListMapMeetingsResponse +import app.meetacy.sdk.engine.ktor.models.ListMeetingParticipantsResponse +import app.meetacy.sdk.engine.ktor.models.ListMeetingsResponse +import app.meetacy.sdk.engine.ktor.models.User as ModelUser import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.engine.requests.CreateMeetingRequest import app.meetacy.sdk.engine.requests.EditMeetingRequest @@ -27,7 +27,7 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import kotlinx.serialization.json.putJsonObject -import app.meetacy.sdk.engine.ktor.response.models.Meeting as ModelMeeting +import app.meetacy.sdk.engine.ktor.models.Meeting as ModelMeeting internal class MeetingsEngine( baseUrl: Url, @@ -41,13 +41,13 @@ internal class MeetingsEngine( val url = baseUrl / "history" / "list" val jsonObject = buildJsonObject { - put("amount", amount.int.toString()) + put("amount", amount.int) put("pagingId", pagingId?.string) } val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), @@ -63,7 +63,7 @@ internal class MeetingsEngine( val url = baseUrl / "history" / "active" val jsonObject = buildJsonObject { - put("amount", amount.int.toString()) + put("amount", amount.int) put("pagingId", pagingId?.string) } @@ -75,10 +75,10 @@ internal class MeetingsEngine( ) ) header("Authorization", request.token.string) - header("Api-Version", request.apiVersion.int.toString()) + header("Api-Version", request.apiVersion.int) }.body() - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), @@ -94,13 +94,13 @@ internal class MeetingsEngine( val url = baseUrl / "history" / "past" val jsonObject = buildJsonObject { - put("amount", amount.int.toString()) + put("amount", amount.int) put("pagingId", pagingId?.string) } val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), @@ -123,7 +123,7 @@ internal class MeetingsEngine( } val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val data = response.map(ModelMeeting::mapToMeeting) @@ -149,7 +149,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val meeting = json.decodeFromString(string).result + val meeting = json.decodeFromString(string).result return CreateMeetingRequest.Response(meeting.mapToMeeting()) } @@ -185,7 +185,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val meeting = json.decodeFromString(string).result + val meeting = json.decodeFromString(string).result return EditMeetingRequest.Response(meeting.mapToMeeting()) } @@ -203,7 +203,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( data = response.data.map(ModelUser::mapToUser), @@ -213,7 +213,7 @@ internal class MeetingsEngine( return ListMeetingParticipantsRequest.Response(paging) } - suspend fun participateMeeting(request: ParticipateMeetingRequest): StatusTrueResponse { + suspend fun participateMeeting(request: ParticipateMeetingRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { val url = baseUrl / "participate" val jsonObject = buildJsonObject { @@ -222,7 +222,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - return Json.decodeFromString(string) + return Json.decodeFromString(string) } suspend fun getMeeting(request: GetMeetingRequest): GetMeetingRequest.Response { @@ -234,7 +234,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val meeting = response.mapToMeeting() diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index c1364e64..29c90517 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -2,8 +2,8 @@ package app.meetacy.sdk.engine.ktor.requests.notifications import app.meetacy.sdk.engine.ktor.mapToNotification import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.response.models.ListNotificationsResponse -import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.models.ListNotificationsResponse +import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse import app.meetacy.sdk.engine.requests.ListNotificationsRequest import app.meetacy.sdk.engine.requests.ReadNotificationRequest import app.meetacy.sdk.types.paging.PagingId @@ -27,13 +27,13 @@ internal class NotificationsEngine( val url = baseUrl / "list" val jsonObject = buildJsonObject { - put("amount", amount.int.toString()) + put("amount", amount.int) put("pagingId", pagingId?.string) } val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( data = response.data.map { it.mapToNotification() }, @@ -43,7 +43,7 @@ internal class NotificationsEngine( ListNotificationsRequest.Response(paging) } - suspend fun read(request: ReadNotificationRequest): StatusTrueResponse = with (request) { + suspend fun read(request: ReadNotificationRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse = with (request) { val url = baseUrl / "read" val jsonObject = buildJsonObject { @@ -52,6 +52,6 @@ internal class NotificationsEngine( val string = post(url.string, jsonObject, httpClient, request) - return json.decodeFromString(string) + return json.decodeFromString(string) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt new file mode 100644 index 00000000..87f3c223 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -0,0 +1,20 @@ +package app.meetacy.sdk.engine.ktor.requests.search + +import app.meetacy.sdk.engine.requests.SearchRequest +import app.meetacy.sdk.types.url.Url +import io.ktor.client.* +import io.ktor.client.request.* +import kotlinx.serialization.json.Json + +internal class SearchEngine( + baseUrl: Url, + private val httpClient: HttpClient +) { + val baseUrl: Url = baseUrl / "search" + + suspend fun search(request: SearchRequest): SearchRequest.Response { + httpClient.get(baseUrl.string) { + + } + } +} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt index 8b7eb3fe..6a79349c 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt @@ -3,7 +3,7 @@ package app.meetacy.sdk.engine.ktor.requests.updates import app.meetacy.sdk.engine.ktor.handleRSocketExceptions import app.meetacy.sdk.engine.ktor.mapToNotification import app.meetacy.sdk.engine.requests.EmitUpdatesRequest -import app.meetacy.sdk.engine.ktor.response.models.Notification as ModelNotification +import app.meetacy.sdk.engine.ktor.models.Notification as ModelNotification import app.meetacy.sdk.types.update.Update import app.meetacy.sdk.types.update.UpdateId import app.meetacy.sdk.types.url.Url 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 51369c84..fd5e9d49 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 @@ -1,27 +1,39 @@ package app.meetacy.sdk.engine.ktor.requests.users +import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.mapToSelfUser import app.meetacy.sdk.engine.ktor.mapToUser import app.meetacy.sdk.engine.ktor.requests.extencion.post import app.meetacy.sdk.engine.ktor.requests.extencion.postWithoutToken -import app.meetacy.sdk.engine.ktor.response.models.EditUserResponse -import app.meetacy.sdk.engine.ktor.response.models.GetUserResponse -import app.meetacy.sdk.engine.ktor.response.models.ValidateUsernameRequest +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token 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.UsernameAvailableRequest import app.meetacy.sdk.exception.meetacyApiError import app.meetacy.sdk.types.annotation.UnsafeConstructor +import app.meetacy.sdk.types.file.FileId import app.meetacy.sdk.types.optional.ifPresent +import app.meetacy.sdk.types.optional.map +import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.serializable +import app.meetacy.sdk.types.serializable.optional.OptionalSerializable +import app.meetacy.sdk.types.serializable.optional.serializable +import app.meetacy.sdk.types.serializable.user.* import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.SelfUser +import app.meetacy.sdk.types.user.User import app.meetacy.sdk.types.user.Username import io.ktor.client.* +import io.ktor.client.request.* +import io.ktor.http.* +import io.ktor.http.HttpHeaders.Authorization +import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -import app.meetacy.sdk.engine.ktor.response.models.GetUserRequest as ModelGetUserRequest +import app.meetacy.sdk.engine.ktor.models.GetUserRequest as ModelGetUserRequest internal class UsersEngine( baseUrl: Url, @@ -39,7 +51,7 @@ internal class UsersEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string) + val response = json.decodeFromString(string) return GetMeRequest.Response( (response.result?.mapToUser() ?: meetacyApiError("'result' should present")) @@ -47,44 +59,45 @@ internal class UsersEngine( ) } - suspend fun getUser(request: GetUserRequest): GetUserRequest.Response { - val url = baseUrl / "get" + @Serializable + private data class GetUserBody(val id: UserIdSerializable) - val jsonObject = buildJsonObject { - put("id", ModelGetUserRequest( - request.userId.string - ).id) - } + private fun GetUserRequest.toBody() = GetUserBody(userId.serializable()) - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string) - - return GetUserRequest.Response( - response.result?.mapToUser() ?: meetacyApiError("'result' should present") - ) + suspend fun getUser(request: GetUserRequest): GetUserRequest.Response { + val url = baseUrl / "get" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() + return GetUserRequest.Response(response.type()) } - suspend fun editUser(request: EditUserRequest): EditUserRequest.Response = with(request) { - val url = baseUrl / "edit" - - val jsonObject = buildJsonObject { - nickname.ifPresent { nickname -> - put("nickname", nickname) - } - avatarId.ifPresent { avatarId -> - put("avatarId", avatarId?.string) - } - username.ifPresent { username -> - put("username", username?.string) - } - } - - val string = post(url.string, jsonObject, httpClient, request) + @Serializable + private data class EditUserBody( + val nickname: OptionalSerializable, + val avatarId: OptionalSerializable, + val username: OptionalSerializable + ) - val user = Json.decodeFromString(string).result + private fun EditUserRequest.toBody() = EditUserBody( + nickname = nickname.serializable(), + avatarId = avatarId.map { it?.serializable() }.serializable(), + username = username.map { it?.serializable() }.serializable() + ) - return EditUserRequest.Response(user = user.mapToSelfUser()) + suspend fun editUser(request: EditUserRequest): EditUserRequest.Response { + val url = baseUrl / "edit" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() + val result = response.type() as SelfUser + return EditUserRequest.Response(result) } @OptIn(UnsafeConstructor::class) @@ -97,7 +110,7 @@ internal class UsersEngine( val string = postWithoutToken(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).username + val response = json.decodeFromString(string).username return UsernameAvailableRequest.Response(username = Username(response)) } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt index d0d8cfa9..48e5034d 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt @@ -1,5 +1,7 @@ package app.meetacy.sdk.engine.ktor.response +import io.ktor.client.call.* +import io.ktor.client.statement.* import io.rsocket.kotlin.payload.Payload import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer @@ -9,16 +11,7 @@ import kotlinx.serialization.builtins.nullable import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.Json - -@Serializable -internal data class ServerResponseData( - val status: Boolean, - val data: T? = null, - val errorCode: Int? = null, - val errorMessage: String? = null -) - -internal typealias EmptyServerResponse = ServerResponse +import kotlin.reflect.KClass @Serializable(with = ServerResponse.Serializer::class) internal sealed interface ServerResponse { @@ -33,8 +26,7 @@ internal sealed interface ServerResponse { @Suppress("UNCHECKED_CAST") class Serializer(subSerializer: KSerializer) : KSerializer> { - private val baseSerializer = ServerResponseData.serializer(subSerializer) - + private val baseSerializer = Data.serializer(subSerializer) override val descriptor = baseSerializer.descriptor override fun deserialize(decoder: Decoder): ServerResponse { @@ -47,7 +39,7 @@ internal sealed interface ServerResponse { } override fun serialize(encoder: Encoder, value: ServerResponse) { - val data = ServerResponseData( + val data = Data( status = value is Success, data = (value as? Success)?.data, errorCode = (value as? Error)?.errorCode, @@ -56,6 +48,13 @@ internal sealed interface ServerResponse { baseSerializer.serialize(encoder, data) } + @Serializable + private data class Data( + val status: Boolean, + val data: T? = null, + val errorCode: Int? = null, + val errorMessage: String? = null + ) } } @@ -68,7 +67,6 @@ internal fun Payload.decodeToServerResponse( ) } -@OptIn(ExperimentalSerializationApi::class) -internal fun Payload.decodeToEmptyServerResponse(): EmptyServerResponse { - return decodeToServerResponse(NothingSerializer().nullable) +internal suspend inline fun HttpResponse.bodyAsSuccess(): T { + return body>().data } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateInvitationResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateInvitationResponse.kt deleted file mode 100644 index 3933e69b..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateInvitationResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class CreateInvitationResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: Invitation - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateMeetingResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateMeetingResponse.kt deleted file mode 100644 index fcd83743..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/CreateMeetingResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class CreateMeetingResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: Meeting - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditMeetingResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditMeetingResponse.kt deleted file mode 100644 index 34bb868a..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditMeetingResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class EditMeetingResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: Meeting - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditUserResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditUserResponse.kt deleted file mode 100644 index 360df1d2..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/EditUserResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class EditUserResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: User - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GenerateIdentityResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GenerateIdentityResponse.kt deleted file mode 100644 index 7de593fa..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GenerateIdentityResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class GenerateIdentityResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: String - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserRequest.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserRequest.kt deleted file mode 100644 index 7c267280..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserRequest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class GetUserRequest ( - - @SerialName("id") - val id: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserResponse.kt deleted file mode 100644 index 68bdb005..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/GetUserResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class GetUserResponse ( - - @SerialName("status") - val status: Boolean? = null, - - @SerialName("result") - val result: User? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Invitation.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Invitation.kt deleted file mode 100644 index 68a2a8ba..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Invitation.kt +++ /dev/null @@ -1,30 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class Invitation ( - - @SerialName("identity") - val identity: String, - - @SerialName("invitedUser") - val invitedUser: User, - - @SerialName("inviterUser") - val inviterUser: User, - - @SerialName("meeting") - val meeting: Meeting, - - @SerialName("isAccepted") - val isAccepted: Boolean? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponse.kt deleted file mode 100644 index 9e429afa..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListFriendsResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: ListFriendsResponseResult - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponseResult.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponseResult.kt deleted file mode 100644 index 2550beb9..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListFriendsResponseResult.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListFriendsResponseResult ( - - @SerialName("data") - val data: List, - - @SerialName("nextPagingId") - val nextPagingId: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMapMeetingsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMapMeetingsResponse.kt deleted file mode 100644 index ee5d150d..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMapMeetingsResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListMapMeetingsResponse ( - - @SerialName("result") - val result: List, - - @SerialName("status") - val status: Boolean? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponse.kt deleted file mode 100644 index ae8bd289..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListMeetingParticipantsResponse ( - - @SerialName("status") - val status: Boolean, - - @SerialName("result") - val result: ListMeetingParticipantsResponseResult - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponseResult.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponseResult.kt deleted file mode 100644 index 8d4cb62c..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingParticipantsResponseResult.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListMeetingParticipantsResponseResult ( - - @SerialName("data") - val data: List, - - @SerialName("nextPagingId") - val nextPagingId: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponse.kt deleted file mode 100644 index 90fd0cda..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListMeetingsResponse ( - - @SerialName("result") - val result: ListMeetingsResponseResult, - - @SerialName("status") - val status: Boolean? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponseResult.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponseResult.kt deleted file mode 100644 index 5520069d..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListMeetingsResponseResult.kt +++ /dev/null @@ -1,22 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListMeetingsResponseResult ( - - @SerialName("data") - val data: List, - - @SerialName("nextPagingId") - val nextPagingId: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponse.kt deleted file mode 100644 index 5565b2f3..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponse.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListNotificationsResponse ( - - @SerialName("result") - val result: ListNotificationsResponseResult, - - @SerialName("status") - val status: Boolean? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponseResult.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponseResult.kt deleted file mode 100644 index aa24236f..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ListNotificationsResponseResult.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ListNotificationsResponseResult ( - - @SerialName("data") - val data: List, - - @SerialName("nextPagingId") - val nextPagingId: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Location.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Location.kt deleted file mode 100644 index 9bdc4350..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Location.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class Location ( - - @SerialName("latitude") - val latitude: Double, - - @SerialName("longitude") - val longitude: Double - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Meeting.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Meeting.kt deleted file mode 100644 index 734a2098..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Meeting.kt +++ /dev/null @@ -1,55 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class Meeting ( - - @SerialName("id") - val id: String, - - @SerialName("creator") - val creator: User, - - @SerialName("date") - val date: String, - - @SerialName("location") - val location: Location, - - @SerialName("title") - val title: String, - - @SerialName("participantsCount") - val participantsCount: Int, - - @SerialName("previewParticipants") - val previewParticipants: List, - - @SerialName("isParticipating") - val isParticipating: Boolean, - - @SerialName("visibility") - val visibility: Visibility, - - @SerialName("description") - val description: String? = null, - - @SerialName("avatarId") - val avatarId: String? = null - -) { - @Serializable - enum class Visibility { - - @SerialName("public") - PUBLIC, - - @SerialName("private") - PRIVATE; - - } - -} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Notification.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Notification.kt deleted file mode 100644 index f52228e3..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/Notification.kt +++ /dev/null @@ -1,48 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class Notification ( - - @SerialName("type") - val type: Type, - - @SerialName("id") - val id: String, - - @SerialName("isNew") - val isNew: Boolean, - - @SerialName("date") - val date: String, - - @SerialName("subscriber") - val subscriber: User? = null, - - @SerialName("meeting") - val meeting: Meeting? = null, - - @SerialName("inviter") - val inviter: User? = null - -) { - @Serializable - enum class Type { - - @SerialName("subscription") - SUBSCRIPTION, - - @SerialName("meeting_invitation") - MEETING_INVITATION; - - } - -} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/StatusTrueResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/StatusTrueResponse.kt deleted file mode 100644 index 13ae1396..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/StatusTrueResponse.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class StatusTrueResponse ( - - @SerialName("status") - val status: Boolean - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/User.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/User.kt deleted file mode 100644 index b5cd823e..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/User.kt +++ /dev/null @@ -1,34 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerialName - -@Serializable -internal data class User ( - - @SerialName("isSelf") - val isSelf: Boolean, - - @SerialName("id") - val id: String, - - @SerialName("nickname") - val nickname: String, - - @SerialName("username") - val username: String? = null, - - @SerialName("email") - val email: String? = null, - - @SerialName("emailVerified") - val emailVerified: Boolean? = null, - - @SerialName("avatarId") - val avatarId: String? = null, - /* Relationship field can be one of four types - subscription, subscriber, friend and none. In case if isSelf == true, relationship field is null */ - - @SerialName("relationship") - val relationship: String? = null - -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ValidateUsernameRequest.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ValidateUsernameRequest.kt deleted file mode 100644 index da1d9d0b..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/models/ValidateUsernameRequest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response.models - -import kotlinx.serialization.Serializable - - - - - - -import kotlinx.serialization.SerialName - -@Serializable -internal data class ValidateUsernameRequest ( - - @SerialName("username") - val username: String - -) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/MeetacyRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/MeetacyRequest.kt index 337c94ef..c5d7340c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/MeetacyRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/MeetacyRequest.kt @@ -7,4 +7,3 @@ public sealed interface MeetacyRequest { } public typealias SimpleMeetacyRequest = MeetacyRequest -public typealias SimpleMeetacyRequestWithToken = MeetacyRequestWithToken diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/RequestRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/RequestRepository.kt deleted file mode 100644 index fc5c032d..00000000 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/RequestRepository.kt +++ /dev/null @@ -1,11 +0,0 @@ -package app.meetacy.sdk.engine.requests - -import app.meetacy.sdk.types.auth.Token - -public sealed interface MeetacyRequestWithToken : MeetacyRequest { - public val token: Token -} - -public interface TokenProviderEmpty : MeetacyRequest - - diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/SearchRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/SearchRequest.kt new file mode 100644 index 00000000..a5833fc5 --- /dev/null +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/SearchRequest.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.requests + +import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.location.Location +import app.meetacy.sdk.types.search.SearchItem + +public data class SearchRequest( + val token: Token, + val location: Location, + val prompt: String +) : MeetacyRequest { + public data class Response(val items: List) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 9480f5d6..ba79fbe7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,6 +20,7 @@ includeBuild("build-logic") include( ":api", ":types", + ":types:serializable", ":api:api-ktor", ":kotlinx-datetime", ":io", diff --git a/types/serializable/build.gradle.kts b/types/serializable/build.gradle.kts new file mode 100644 index 00000000..badf97b8 --- /dev/null +++ b/types/serializable/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("kmp-library-convention") +} + +version = libs.versions.meetacySdk.get() + +dependencies { + commonMainImplementation(projects.types) + commonMainImplementation(libs.kotlinxSerialization) +} diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/email/EmailSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/email/EmailSerializable.kt new file mode 100644 index 00000000..b73e5718 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/email/EmailSerializable.kt @@ -0,0 +1,15 @@ +@file:OptIn(UnsafeConstructor::class) + +package app.meetacy.sdk.types.serializable.email + +import app.meetacy.sdk.types.annotation.UnsafeConstructor +import app.meetacy.sdk.types.email.Email +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class EmailSerializable(public val string: String) + +public fun EmailSerializable.type(): Email = Email(string) +public fun Email.serializable(): EmailSerializable = EmailSerializable(string) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/file/FileIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/file/FileIdSerializable.kt new file mode 100644 index 00000000..052596c5 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/file/FileIdSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.file + +import app.meetacy.sdk.types.file.FileId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class FileIdSerializable(public val string: String) + +public fun FileIdSerializable.type(): FileId = FileId(string) +public fun FileId.serializable(): FileIdSerializable = FileIdSerializable(string) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/optional/OptionalSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/optional/OptionalSerializable.kt new file mode 100644 index 00000000..8fe7955b --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/optional/OptionalSerializable.kt @@ -0,0 +1,57 @@ +@file:Suppress("OPT_IN_OVERRIDE") + +package app.meetacy.sdk.types.serializable.optional + +import app.meetacy.sdk.types.optional.Optional +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Optional.Undefined is never being encoded in JSON + */ +@Serializable(with = OptionalSerializable.Serializer::class) +public sealed interface OptionalSerializable { + public val value: T? get() = null + public data class Present(override val value: T) : OptionalSerializable + public data object Undefined : OptionalSerializable + + public class Serializer( + private val subSerializer: KSerializer + ) : KSerializer> { + + override val descriptor: SerialDescriptor = object : SerialDescriptor by subSerializer.descriptor { + override val serialName = "OptionalSerializer" + override val isNullable = true + } + + override fun deserialize(decoder: Decoder): OptionalSerializable { + val value = decoder.decodeSerializableValue(subSerializer) + return Present(value) + } + + override fun serialize(encoder: Encoder, value: OptionalSerializable) { + if (value !is Present) { + error( + message = "Only 'Present' values can be encoded, " + + "please consider to use 'Undefined' as default " + + "value in order to prevent it from encoding" + ) + } + + encoder.encodeSerializableValue(subSerializer, value.value) + } + } +} + +public fun OptionalSerializable.type(): Optional = when (this) { + is OptionalSerializable.Present -> Optional.Present(value) + is OptionalSerializable.Undefined -> Optional.Undefined +} + +public fun Optional.serializable(): OptionalSerializable = when (this) { + is Optional.Present -> OptionalSerializable.Present(value) + is Optional.Undefined -> OptionalSerializable.Undefined +} diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/RelationshipSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/RelationshipSerializable.kt new file mode 100644 index 00000000..a70e3ab2 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/RelationshipSerializable.kt @@ -0,0 +1,31 @@ +package app.meetacy.sdk.types.serializable.user + +import app.meetacy.sdk.types.user.Relationship +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public enum class RelationshipSerializable { + @SerialName("none") + None, + @SerialName("subscription") + Subscription, + @SerialName("subscriber") + Subscriber, + @SerialName("friend") + Friend +} + +public fun RelationshipSerializable.type(): Relationship = when (this) { + RelationshipSerializable.None -> Relationship.None + RelationshipSerializable.Subscription -> Relationship.Subscription + RelationshipSerializable.Subscriber -> Relationship.Subscriber + RelationshipSerializable.Friend -> Relationship.Friend +} + +public fun Relationship.serializable(): RelationshipSerializable = when (this) { + Relationship.Friend -> RelationshipSerializable.None + Relationship.None -> RelationshipSerializable.Subscription + Relationship.Subscriber -> RelationshipSerializable.Subscriber + Relationship.Subscription -> RelationshipSerializable.Friend +} diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserIdSerializable.kt new file mode 100644 index 00000000..85e068aa --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserIdSerializable.kt @@ -0,0 +1,15 @@ +@file:OptIn(UnsafeConstructor::class) + +package app.meetacy.sdk.types.serializable.user + +import app.meetacy.sdk.types.annotation.UnsafeConstructor +import app.meetacy.sdk.types.user.UserId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class UserIdSerializable(public val string: String) + +public fun UserIdSerializable.type(): UserId = UserId(string) +public fun UserId.serializable(): UserIdSerializable = UserIdSerializable(string) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt new file mode 100644 index 00000000..158c8367 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt @@ -0,0 +1,50 @@ +package app.meetacy.sdk.types.serializable.user + +import app.meetacy.sdk.types.serializable.email.EmailSerializable +import app.meetacy.sdk.types.serializable.email.type +import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.type +import app.meetacy.sdk.types.user.RegularUser +import app.meetacy.sdk.types.user.SelfUser +import app.meetacy.sdk.types.user.User +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public data class UserSerializable( + @SerialName("id") + public val id: UserIdSerializable, + @SerialName("nickname") + public val nickname: String, + @SerialName("avatar_id") + public val avatarId: FileIdSerializable?, + @SerialName("is_self") + public val isSelf: Boolean, + @SerialName("username") + public val username: UsernameSerializable?, + @SerialName("relationship") + public val relationship: RelationshipSerializable? = null, + @SerialName("email") + public val email: EmailSerializable? = null, + @SerialName("email_verified") + public val emailVerified: Boolean? = null +) + +public fun UserSerializable.type(): User = if (isSelf) { + SelfUser( + id = id.type(), + email = email?.type(), + nickname = nickname, + emailVerified = emailVerified!!, + username = username?.type(), + avatarId = avatarId?.type() + ) +} else { + RegularUser( + id = id.type(), + nickname = nickname, + username = username?.type(), + avatarId = avatarId?.type(), + relationship = relationship!!.type() + ) +} diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UsernameSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UsernameSerializable.kt new file mode 100644 index 00000000..a3526bd0 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UsernameSerializable.kt @@ -0,0 +1,15 @@ +@file:OptIn(UnsafeConstructor::class) + +package app.meetacy.sdk.types.serializable.user + +import app.meetacy.sdk.types.annotation.UnsafeConstructor +import app.meetacy.sdk.types.user.Username +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class UsernameSerializable(public val string: String) + +public fun UsernameSerializable.type(): Username = Username(string) +public fun Username.serializable(): UsernameSerializable = UsernameSerializable(string) diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/address/Address.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/address/Address.kt new file mode 100644 index 00000000..ed7ec615 --- /dev/null +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/address/Address.kt @@ -0,0 +1,8 @@ +package app.meetacy.sdk.types.address + +public data class Address( + val country: String, + val city: String, + val street: String, + val placeName: String? +) diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/place/Place.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/place/Place.kt new file mode 100644 index 00000000..5df79229 --- /dev/null +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/place/Place.kt @@ -0,0 +1,9 @@ +package app.meetacy.sdk.types.place + +import app.meetacy.sdk.types.address.Address +import app.meetacy.sdk.types.location.Location + +public data class Place( + val address: Address, + val location: Location +) diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt new file mode 100644 index 00000000..8f45fa8c --- /dev/null +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt @@ -0,0 +1,11 @@ +package app.meetacy.sdk.types.search + +import app.meetacy.sdk.types.meeting.Meeting as MeetingView +import app.meetacy.sdk.types.place.Place as PlaceView +import app.meetacy.sdk.types.user.User as UserView + +public sealed interface SearchItem { + public class Meeting(public val meeting: MeetingView) : SearchItem + public class User(public val user: UserView) : SearchItem + public class Place(public val place: PlaceView) : SearchItem +} From ae4cc3cf566bd84c585ba55a33e6f7c03f354ac7 Mon Sep 17 00:00:00 2001 From: y9kap Date: Fri, 27 Oct 2023 22:19:45 +0300 Subject: [PATCH 02/56] WIP(#76-support-search): friends fix in progress --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 6 +- .../ktor/requests/friends/FriendsEngine.kt | 45 ++++++------- .../ktor/requests/search/SearchEngine.kt | 5 +- .../engine/ktor/requests/users/UsersEngine.kt | 67 +++++++------------ .../engine/ktor/response/SimpleResponse.kt | 12 ++++ .../sdk/engine/requests/AddFriendRequest.kt | 4 +- .../engine/requests/GenerateAuthRequest.kt | 2 +- .../sdk/engine/requests/GetMeRequest.kt | 4 +- .../sdk/engine/requests/GetUserRequest.kt | 6 +- .../serializable/user/UserSerializable.kt | 4 +- 10 files changed, 74 insertions(+), 81 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt 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 e62efccf..61778a48 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 @@ -45,9 +45,9 @@ public class KtorMeetacyEngine( install(RSocketSupport) } - private val auth = AuthEngine(baseUrl, this.httpClient, this.json) - private val users = UsersEngine(baseUrl, this.httpClient, this.json) - private val friends = FriendsEngine(baseUrl, this.httpClient, this.json) + private val auth = AuthEngine(baseUrl, this.httpClient) + private val users = UsersEngine(baseUrl, this.httpClient) + private val friends = FriendsEngine(baseUrl, this.httpClient) private val meetings = MeetingsEngine(baseUrl, this.httpClient, this.json) private val files = FilesEngine(baseUrl, this.httpClient) private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 34e0ed76..9f385392 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -2,28 +2,23 @@ package app.meetacy.sdk.engine.ktor.requests.friends -import app.meetacy.sdk.engine.ktor.handleRSocketExceptions -import app.meetacy.sdk.engine.ktor.mapToLocation -import app.meetacy.sdk.engine.ktor.mapToRegularUser -import app.meetacy.sdk.engine.ktor.mapToUser -import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.models.ListFriendsResponse -import app.meetacy.sdk.engine.ktor.models.Location as ModelLocation -import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse -import app.meetacy.sdk.engine.ktor.models.User as ModelUser -import app.meetacy.sdk.engine.requests.AddFriendRequest -import app.meetacy.sdk.engine.requests.DeleteFriendRequest -import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest -import app.meetacy.sdk.engine.requests.ListFriendsRequest +import app.meetacy.sdk.engine.ktor.* +import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse +import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.user.UserIdSerializable +import app.meetacy.sdk.types.serializable.user.serializable import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.RegularUser import app.meetacy.sdk.types.user.UserLocationSnapshot import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import io.ktor.client.statement.* import io.rsocket.kotlin.ktor.client.rSocket import io.rsocket.kotlin.payload.Payload import io.rsocket.kotlin.payload.buildPayload @@ -38,21 +33,23 @@ import kotlinx.serialization.json.put internal class FriendsEngine( baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { private val baseUrl = baseUrl / "friends" - suspend fun add(request: AddFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { - val url = baseUrl / "add" - - val jsonObject = buildJsonObject { - put("friendId", request.friendId.string) - } + @Serializable + private data class AddFriendBody(val friendId: UserIdSerializable) + private fun AddFriendRequest.toBody() = AddFriendBody(friendId.serializable()) - val string = post(url.string, jsonObject, httpClient, request) - - return json.decodeFromString(string) + suspend fun add(request: AddFriendRequest): StatusTrueResponse { + val url = baseUrl / "add" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.body() + return response } suspend fun delete(request: DeleteFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt index 87f3c223..88b2e1f0 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -4,7 +4,6 @@ import app.meetacy.sdk.engine.requests.SearchRequest import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* -import kotlinx.serialization.json.Json internal class SearchEngine( baseUrl: Url, @@ -12,9 +11,9 @@ internal class SearchEngine( ) { val baseUrl: Url = baseUrl / "search" - suspend fun search(request: SearchRequest): SearchRequest.Response { + suspend fun search(request: SearchRequest){ httpClient.get(baseUrl.string) { - + request.location } } } 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 fd5e9d49..e24ce0cb 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 @@ -1,20 +1,13 @@ package app.meetacy.sdk.engine.ktor.requests.users import app.meetacy.sdk.engine.ktor.apiVersion -import app.meetacy.sdk.engine.ktor.mapToSelfUser -import app.meetacy.sdk.engine.ktor.mapToUser -import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.requests.extencion.postWithoutToken import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token 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.UsernameAvailableRequest -import app.meetacy.sdk.exception.meetacyApiError import app.meetacy.sdk.types.annotation.UnsafeConstructor -import app.meetacy.sdk.types.file.FileId -import app.meetacy.sdk.types.optional.ifPresent import app.meetacy.sdk.types.optional.map import app.meetacy.sdk.types.serializable.file.FileIdSerializable import app.meetacy.sdk.types.serializable.file.serializable @@ -23,46 +16,33 @@ import app.meetacy.sdk.types.serializable.optional.serializable import app.meetacy.sdk.types.serializable.user.* import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.SelfUser -import app.meetacy.sdk.types.user.User -import app.meetacy.sdk.types.user.Username import io.ktor.client.* import io.ktor.client.request.* -import io.ktor.http.* -import io.ktor.http.HttpHeaders.Authorization import kotlinx.serialization.Serializable -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import app.meetacy.sdk.engine.ktor.models.GetUserRequest as ModelGetUserRequest internal class UsersEngine( baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { private val baseUrl = baseUrl / "users" + private fun toBody() = GetUserBody(null) + suspend fun getMe(request: GetMeRequest): GetMeRequest.Response { val url = baseUrl / "get" - - val jsonObject = buildJsonObject { - put("id", ModelGetUserRequest().id) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string) - - return GetMeRequest.Response( - (response.result?.mapToUser() ?: meetacyApiError("'result' should present")) - as? SelfUser ?: meetacyApiError("Resulted user is not SelfUser") - ) + val body = toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() + return GetMeRequest.Response(response.type() as SelfUser) } @Serializable - private data class GetUserBody(val id: UserIdSerializable) + private data class GetUserBody(val id: UserIdSerializable?) - private fun GetUserRequest.toBody() = GetUserBody(userId.serializable()) + private fun GetUserRequest.toBody() = GetUserBody(userId?.serializable()) suspend fun getUser(request: GetUserRequest): GetUserRequest.Response { val url = baseUrl / "get" @@ -100,18 +80,23 @@ internal class UsersEngine( return EditUserRequest.Response(result) } - @OptIn(UnsafeConstructor::class) - suspend fun usernameAvailable(request: UsernameAvailableRequest): UsernameAvailableRequest.Response { - val url = baseUrl / "username" / "available" + @Serializable + private data class UsernameAvailableBody(val username: UsernameSerializable?) - val jsonObject = buildJsonObject { - put("username", request.username.string) - } + private fun UsernameAvailableRequest.toBody() = UsernameAvailableBody( + username = username.serializable() + ) - val string = postWithoutToken(url.string, jsonObject, httpClient, request) - val response = json.decodeFromString(string).username + @OptIn(UnsafeConstructor::class) + suspend fun usernameAvailable(request: UsernameAvailableRequest): UsernameAvailableRequest.Response { + val url = baseUrl / "username" / "available" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + setBody(body) + }.bodyAsSuccess() - return UsernameAvailableRequest.Response(username = Username(response)) + return UsernameAvailableRequest.Response(response.type()) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt new file mode 100644 index 00000000..d1f964a7 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.engine.ktor.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class StatusTrueResponse ( + + @SerialName("status") + val status: Boolean + +) \ No newline at end of file diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AddFriendRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AddFriendRequest.kt index e2e78de4..69703126 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AddFriendRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AddFriendRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.user.UserId public data class AddFriendRequest( - override val token: Token, + val token: Token, val friendId: UserId -) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +) : SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GenerateAuthRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GenerateAuthRequest.kt index 85794d28..8759e9be 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GenerateAuthRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GenerateAuthRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token public data class GenerateAuthRequest( val nickname: String -) : MeetacyRequest, TokenProviderEmpty { +) : MeetacyRequest{ public data class Response(val token: Token) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt index cc11c405..25ea81c9 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt @@ -4,7 +4,7 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.user.SelfUser public data class GetMeRequest( - override val token: Token -): MeetacyRequest, MeetacyRequestWithToken { + val token: Token +): MeetacyRequest{ public data class Response(val me: SelfUser) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt index 9ab53e3a..469533a0 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt @@ -5,9 +5,9 @@ import app.meetacy.sdk.types.user.User import app.meetacy.sdk.types.user.UserId public data class GetUserRequest( - override val token: Token, - val userId: UserId -) : MeetacyRequest, MeetacyRequestWithToken { + val token: Token, + val userId: UserId? +) : MeetacyRequest { public data class Response( val user: User ) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt index 158c8367..ecc6419d 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt @@ -35,7 +35,7 @@ public fun UserSerializable.type(): User = if (isSelf) { id = id.type(), email = email?.type(), nickname = nickname, - emailVerified = emailVerified!!, + emailVerified = emailVerified ?: error("Self user must always return emailVerified parameter"), username = username?.type(), avatarId = avatarId?.type() ) @@ -45,6 +45,6 @@ public fun UserSerializable.type(): User = if (isSelf) { nickname = nickname, username = username?.type(), avatarId = avatarId?.type(), - relationship = relationship!!.type() + relationship = relationship?.type() ?: error("Regular user should always return relationship parameter") ) } From b3dbdc7abb0222ac0bdb71d13ed51a00efb20fc5 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 28 Oct 2023 01:06:55 +0300 Subject: [PATCH 03/56] WIP(#79-support-search): friends was fixed --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 2 +- .../ktor/requests/friends/FriendsEngine.kt | 75 ++++++++++++------- .../ktor/response/ListFriendsResponse.kt | 13 ++++ .../engine/requests/DeleteFriendRequest.kt | 4 +- .../sdk/engine/requests/ListFriendsRequest.kt | 4 +- .../serializable/amount/AmountSerializable.kt | 15 ++++ .../location/LocationSerializable.kt | 16 ++++ .../pagingId/PagingIdSerializable.kt | 13 ++++ .../app/meetacy/sdk/types/paging/PagingId.kt | 3 +- 9 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/amount/AmountSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/location/LocationSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt 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 61778a48..1bc7bdb7 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 @@ -47,7 +47,7 @@ public class KtorMeetacyEngine( private val auth = AuthEngine(baseUrl, this.httpClient) private val users = UsersEngine(baseUrl, this.httpClient) - private val friends = FriendsEngine(baseUrl, this.httpClient) + private val friends = FriendsEngine(baseUrl, this.httpClient, this.json) private val meetings = MeetingsEngine(baseUrl, this.httpClient, this.json) private val files = FilesEngine(baseUrl, this.httpClient) private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 9f385392..74934b03 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -2,23 +2,36 @@ package app.meetacy.sdk.engine.ktor.requests.friends -import app.meetacy.sdk.engine.ktor.* +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.handleRSocketExceptions +import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse -import app.meetacy.sdk.engine.requests.* +import app.meetacy.sdk.engine.ktor.token +import app.meetacy.sdk.engine.requests.AddFriendRequest +import app.meetacy.sdk.engine.requests.DeleteFriendRequest +import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest +import app.meetacy.sdk.engine.requests.ListFriendsRequest import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.amount.AmountSerializable +import app.meetacy.sdk.types.serializable.amount.serializable +import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.type +import app.meetacy.sdk.types.serializable.pagingId.PagingIdSerializable +import app.meetacy.sdk.types.serializable.pagingId.serializable import app.meetacy.sdk.types.serializable.user.UserIdSerializable +import app.meetacy.sdk.types.serializable.user.UserSerializable import app.meetacy.sdk.types.serializable.user.serializable +import app.meetacy.sdk.types.serializable.user.type import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.RegularUser import app.meetacy.sdk.types.user.UserLocationSnapshot import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* -import io.ktor.client.statement.* import io.rsocket.kotlin.ktor.client.rSocket import io.rsocket.kotlin.payload.Payload import io.rsocket.kotlin.payload.buildPayload @@ -33,7 +46,8 @@ import kotlinx.serialization.json.put internal class FriendsEngine( baseUrl: Url, - private val httpClient: HttpClient + private val httpClient: HttpClient, + val json: Json ) { private val baseUrl = baseUrl / "friends" @@ -52,33 +66,40 @@ internal class FriendsEngine( return response } - suspend fun delete(request: DeleteFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { - val url = baseUrl / "delete" - - val jsonObject = buildJsonObject { - put("friendId", request.friendId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) + @Serializable + private data class DeleteFriendBody(val friendId: UserIdSerializable) + private fun DeleteFriendRequest.toBody() = DeleteFriendBody(friendId.serializable()) - return json.decodeFromString(string) + suspend fun delete(request: DeleteFriendRequest): StatusTrueResponse { + val url = baseUrl / "delete" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.body() + return response } + @Serializable + private data class ListFriendsBody( + val amount: AmountSerializable, + val pagingId: PagingIdSerializable? + ) + private fun ListFriendsRequest.toBody() = ListFriendsBody(amount.serializable(), pagingId?.serializable() ) + suspend fun list(request: ListFriendsRequest): ListFriendsRequest.Response { val url = baseUrl / "list" - - val jsonObject = buildJsonObject { - put("amount", request.amount.int) - put("pagingId", request.pagingId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = Json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.body() val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map { user -> user.mapToRegularUser() } + data = response.data.map { user -> user.type() as RegularUser } ) return ListFriendsRequest.Response(paging) @@ -128,8 +149,8 @@ private fun Location.encodeToPayload(): Payload = buildPayload { @Serializable private data class ModelUserLocationSnapshotSerializable( - val user: ModelUser, - val location: ModelLocation, + val user: UserSerializable, + val location: LocationSerializable, val capturedAt: String ) @@ -137,8 +158,8 @@ private fun Payload.decodeToUserLocationSnapshot(json: Json): UserLocationSnapsh val deserialized = json.decodeFromString(data.readText()) return UserLocationSnapshot( - user = deserialized.user.mapToUser() as RegularUser, - location = deserialized.location.mapToLocation(), + user = deserialized.user.type() as RegularUser, + location = deserialized.location.type(), capturedAt = DateTime(deserialized.capturedAt) ) } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt new file mode 100644 index 00000000..9e23de4b --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.ktor.response + +import app.meetacy.sdk.types.serializable.user.UserSerializable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class ListFriendsResponse ( + @SerialName("data") + val data: List, + @SerialName("nextPagingId") + val nextPagingId: String? = null +) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DeleteFriendRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DeleteFriendRequest.kt index 29e12636..8d75b320 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DeleteFriendRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DeleteFriendRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.user.UserId public data class DeleteFriendRequest( - override val token: Token, + val token: Token, val friendId: UserId -) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken \ No newline at end of file +) : SimpleMeetacyRequest \ No newline at end of file diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListFriendsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListFriendsRequest.kt index fd640302..15c3b383 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListFriendsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListFriendsRequest.kt @@ -7,9 +7,9 @@ import app.meetacy.sdk.types.paging.PagingResponse import app.meetacy.sdk.types.user.RegularUser public data class ListFriendsRequest( - override val token: Token, + val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/amount/AmountSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/amount/AmountSerializable.kt new file mode 100644 index 00000000..77ee21de --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/amount/AmountSerializable.kt @@ -0,0 +1,15 @@ +@file:OptIn(UnsafeConstructor::class) + +package app.meetacy.sdk.types.serializable.amount + +import app.meetacy.sdk.types.amount.Amount +import app.meetacy.sdk.types.annotation.UnsafeConstructor +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class AmountSerializable(public val int: Int) + +public fun AmountSerializable.type(): Amount = Amount(int) +public fun Amount.serializable(): AmountSerializable = AmountSerializable(int) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/location/LocationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/location/LocationSerializable.kt new file mode 100644 index 00000000..66fce530 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/location/LocationSerializable.kt @@ -0,0 +1,16 @@ +package app.meetacy.sdk.types.serializable.location + +import app.meetacy.sdk.types.location.Location +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public data class LocationSerializable( + @SerialName("latitude") + val latitude: Double, + @SerialName("longitude") + val longitude: Double +) + +public fun LocationSerializable.type(): Location = Location(latitude, longitude) +public fun Location.serializable(): LocationSerializable = LocationSerializable(latitude, longitude) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt new file mode 100644 index 00000000..28d1dcf5 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.types.serializable.pagingId + +import app.meetacy.sdk.types.paging.PagingId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class PagingIdSerializable(public val string: String) + +public fun PagingIdSerializable.type(): PagingId = PagingId(string) + +public fun PagingId.serializable(): PagingIdSerializable = PagingIdSerializable(string) \ No newline at end of file diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/paging/PagingId.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/paging/PagingId.kt index a203508f..0ce7f0d8 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/paging/PagingId.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/paging/PagingId.kt @@ -1,6 +1,7 @@ package app.meetacy.sdk.types.paging +import app.meetacy.sdk.types.annotation.UnsafeConstructor import kotlin.jvm.JvmInline @JvmInline -public value class PagingId(public val string: String) +public value class PagingId @UnsafeConstructor constructor(public val string: String) From d99e44fec1dcda425f03bf46312004769bdb1dce Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sun, 29 Oct 2023 12:30:16 +0300 Subject: [PATCH 04/56] WIP(#79-support-search): invitation engine was refactored --- .../ktor/requests/friends/FriendsEngine.kt | 12 +- .../requests/invitations/InvitationsEngine.kt | 114 ++++++++++-------- .../ktor/response/CreateInvitationResponse.kt | 13 ++ .../requests/AcceptInvitationRequest.kt | 4 +- .../requests/CancelInvitationRequest.kt | 4 +- .../requests/CreateInvitationRequest.kt | 4 +- .../engine/requests/CreateMeetingRequest.kt | 4 +- .../engine/requests/DenyInvitationRequest.kt | 4 +- .../sdk/engine/requests/EditMeetingRequest.kt | 4 +- .../sdk/engine/requests/EditUserRequest.kt | 4 +- .../sdk/engine/requests/GetMeetingRequest.kt | 4 +- .../requests/ListActiveMeetingsRequest.kt | 5 +- .../ListMeetingParticipantsRequest.kt | 5 +- .../requests/ListMeetingsHistoryRequest.kt | 4 +- .../engine/requests/ListMeetingsMapRequest.kt | 4 +- .../requests/ListNotificationsRequest.kt | 4 +- .../requests/ListPastMeetingsRequest.kt | 5 +- .../requests/ParticipateMeetingRequest.kt | 4 +- .../requests/ReadNotificationRequest.kt | 4 +- .../requests/UsernameAvailableRequest.kt | 2 +- .../serializable/datetime/DateSerializable.kt | 12 ++ .../serializable/invitation/InvitationId.kt | 12 ++ .../invitation/InvitationSerializable.kt | 30 +++++ .../meeting/MeetingIdSerializable.kt | 12 ++ .../meeting/MeetingSerializable.kt | 56 +++++++++ .../PagingIdSerializable.kt | 2 +- .../app/meetacy/sdk/types/meeting/Meeting.kt | 3 +- 27 files changed, 242 insertions(+), 93 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationId.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingIdSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt rename types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/{pagingId => paging}/PagingIdSerializable.kt (87%) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 74934b03..86ba9269 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -6,6 +6,7 @@ import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.handleRSocketExceptions import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.AddFriendRequest import app.meetacy.sdk.engine.requests.DeleteFriendRequest @@ -20,8 +21,8 @@ import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.location.LocationSerializable import app.meetacy.sdk.types.serializable.location.type -import app.meetacy.sdk.types.serializable.pagingId.PagingIdSerializable -import app.meetacy.sdk.types.serializable.pagingId.serializable +import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable +import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.serializable.user.UserIdSerializable import app.meetacy.sdk.types.serializable.user.UserSerializable import app.meetacy.sdk.types.serializable.user.serializable @@ -30,7 +31,6 @@ import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.RegularUser import app.meetacy.sdk.types.user.UserLocationSnapshot import io.ktor.client.* -import io.ktor.client.call.* import io.ktor.client.request.* import io.rsocket.kotlin.ktor.client.rSocket import io.rsocket.kotlin.payload.Payload @@ -62,7 +62,7 @@ internal class FriendsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.body() + }.bodyAsSuccess() return response } @@ -77,7 +77,7 @@ internal class FriendsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.body() + }.bodyAsSuccess() return response } @@ -95,7 +95,7 @@ internal class FriendsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.body() + }.bodyAsSuccess() val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt index 0e8ec410..a91c172b 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt @@ -1,82 +1,100 @@ package app.meetacy.sdk.engine.ktor.requests.invitations -import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.models.CreateInvitationResponse -import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse -import app.meetacy.sdk.engine.ktor.toInvitation +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.CreateInvitationResponse +import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.AcceptInvitationRequest import app.meetacy.sdk.engine.requests.CancelInvitationRequest import app.meetacy.sdk.engine.requests.CreateInvitationRequest import app.meetacy.sdk.engine.requests.DenyInvitationRequest +import app.meetacy.sdk.types.serializable.invitation.InvitationIdSerializable +import app.meetacy.sdk.types.serializable.invitation.serializable +import app.meetacy.sdk.types.serializable.invitation.type +import app.meetacy.sdk.types.serializable.meeting.MeetingIdSerializable +import app.meetacy.sdk.types.serializable.meeting.serializable +import app.meetacy.sdk.types.serializable.user.UserIdSerializable +import app.meetacy.sdk.types.serializable.user.serializable import app.meetacy.sdk.types.url.Url import io.ktor.client.* -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put +import io.ktor.client.request.* +import kotlinx.serialization.Serializable internal class InvitationsEngine( baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { private val baseUrl = baseUrl / "invitations" + + @Serializable + private data class CreateInvitationBody( + val meetingId: MeetingIdSerializable, + val userId: UserIdSerializable + ) + private fun CreateInvitationRequest.toBody() = CreateInvitationBody( + meetingId.serializable(), + userId.serializable() + ) + suspend fun create( request: CreateInvitationRequest ): CreateInvitationRequest.Response { val url = baseUrl / "create" - - val jsonObject = buildJsonObject { - put("meetingId", request.meetingId.string) - put("userId", request.userId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result - - return CreateInvitationRequest.Response(response.toInvitation()) + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess().result + return CreateInvitationRequest.Response(response.type()) } + @Serializable + private data class AcceptInvitationBody(val invitationId: InvitationIdSerializable) + private fun AcceptInvitationRequest.toBody() = AcceptInvitationBody(invitationId.serializable()) + suspend fun accept( request: AcceptInvitationRequest - ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { + ): StatusTrueResponse { val url = baseUrl / "accept" - - val jsonObject = buildJsonObject { - put("invitationId", request.invitationId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - return json.decodeFromString(string) + val body = request.toBody() + return httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() } + @Serializable + private data class DenyInvitationBody(val invitationId: InvitationIdSerializable) + private fun DenyInvitationRequest.toBody() = DenyInvitationBody(invitationId.serializable()) + suspend fun deny( request: DenyInvitationRequest - ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { + ): StatusTrueResponse { val url = baseUrl / "deny" - - val jsonObject = buildJsonObject { - put("invitationId", request.invitationId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - return json.decodeFromString(string) + val body = request.toBody() + return httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() } + @Serializable + private data class CancelInvitationBody(val invitationId: InvitationIdSerializable) + private fun CancelInvitationRequest.toBody() = CancelInvitationBody(invitationId.serializable()) + suspend fun cancel( request: CancelInvitationRequest - ): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { + ): StatusTrueResponse { val url = baseUrl / "cancel" - - val jsonObject = buildJsonObject { - put("invitationId", request.invitationId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - return json.decodeFromString(string) + val body = request.toBody() + return httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() } - } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt new file mode 100644 index 00000000..46a20100 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.ktor.response + +import app.meetacy.sdk.types.serializable.invitation.InvitationSerializable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class CreateInvitationResponse ( + @SerialName("status") + val status: Boolean, + @SerialName("result") + val result: InvitationSerializable +) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt index 59933cf6..8b436028 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class AcceptInvitationRequest( - public override val token: Token, + public val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +): SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt index 064f9c3e..49a0ab05 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class CancelInvitationRequest( - public override val token: Token, + public val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +): SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt index d78f6b6c..08e2fbc5 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt @@ -6,9 +6,9 @@ import app.meetacy.sdk.types.meeting.MeetingId import app.meetacy.sdk.types.user.UserId public data class CreateInvitationRequest( - override val token: Token, + val token: Token, val userId: UserId, val meetingId: MeetingId -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val invitation: Invitation) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt index ca8130ec..2e199b24 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt @@ -7,13 +7,13 @@ import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.meeting.Meeting public class CreateMeetingRequest( - public override val token: Token, + public val token: Token, public val title: String, public val date: Date, public val location: Location, public val description: String?, public val visibility: Meeting.Visibility, public val fileId: FileId? = null -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val meeting: Meeting) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt index edc0897c..eb48c074 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class DenyInvitationRequest( - public override val token: Token, + public val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +): SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 28cef4bc..7bf66f50 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -9,7 +9,7 @@ import app.meetacy.sdk.types.meeting.MeetingId import app.meetacy.sdk.types.optional.Optional public data class EditMeetingRequest( - public override val token: Token, + public val token: Token, public val meetingId: MeetingId, public val title: Optional, public val description: Optional, @@ -17,6 +17,6 @@ public data class EditMeetingRequest( public val date: Optional, public val avatarId: Optional, public val visibility: Optional -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val meeting: Meeting) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditUserRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditUserRequest.kt index 7d4401ba..c0e4ec88 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditUserRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditUserRequest.kt @@ -7,10 +7,10 @@ import app.meetacy.sdk.types.user.SelfUser import app.meetacy.sdk.types.user.Username public data class EditUserRequest( - override val token: Token, + val token: Token, val nickname: Optional, val username: Optional, val avatarId: Optional -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val user: SelfUser) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeetingRequest.kt index 57175ea5..1d329e2d 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeetingRequest.kt @@ -5,8 +5,8 @@ import app.meetacy.sdk.types.meeting.Meeting import app.meetacy.sdk.types.meeting.MeetingId public data class GetMeetingRequest( - override val token: Token, + val token: Token, val meetingId: MeetingId -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val meeting: Meeting) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListActiveMeetingsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListActiveMeetingsRequest.kt index 2b3725c1..d8010f1d 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListActiveMeetingsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListActiveMeetingsRequest.kt @@ -7,10 +7,9 @@ import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse public data class ListActiveMeetingsRequest( - override val token: Token, + val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, - MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingParticipantsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingParticipantsRequest.kt index c8e062da..dcb7c284 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingParticipantsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingParticipantsRequest.kt @@ -8,11 +8,10 @@ import app.meetacy.sdk.types.paging.PagingResponse import app.meetacy.sdk.types.user.User public data class ListMeetingParticipantsRequest( - override val token: Token, + val token: Token, val meetingId: MeetingId, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, - MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsHistoryRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsHistoryRequest.kt index ab4b3f22..85ac33fb 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsHistoryRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsHistoryRequest.kt @@ -7,9 +7,9 @@ import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse public data class ListMeetingsHistoryRequest( - override val token: Token, + val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsMapRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsMapRequest.kt index b0c82a38..35449a8e 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsMapRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListMeetingsMapRequest.kt @@ -5,8 +5,8 @@ import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.meeting.Meeting public data class ListMeetingsMapRequest( - override val token: Token, + val token: Token, val location: Location -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val meetings: List) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt index cb8f8026..b04163fb 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt @@ -7,9 +7,9 @@ import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse public data class ListNotificationsRequest( - override val token: Token, + val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListPastMeetingsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListPastMeetingsRequest.kt index 9d25cbe0..8ec527b3 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListPastMeetingsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListPastMeetingsRequest.kt @@ -7,10 +7,9 @@ import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse public data class ListPastMeetingsRequest( - override val token: Token, + val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest, - MeetacyRequestWithToken { +) : MeetacyRequest { public data class Response(val paging: PagingResponse) } \ No newline at end of file diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ParticipateMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ParticipateMeetingRequest.kt index 2ae95354..cf1f0fb8 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ParticipateMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ParticipateMeetingRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.meeting.MeetingId public data class ParticipateMeetingRequest( - override val token: Token, + val token: Token, val meetingId: MeetingId -) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +) : SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt index 6115b412..b7d677d8 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.notification.NotificationId public data class ReadNotificationRequest( - override val token: Token, + val token: Token, val lastNotificationId: NotificationId -) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken +) : SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt index e62d01b9..a54626f4 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.user.Username public data class UsernameAvailableRequest( val username: Username -) : MeetacyRequest, TokenProviderEmpty { +) : MeetacyRequest { public data class Response(val username: Username) } diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateSerializable.kt new file mode 100644 index 00000000..6ece08eb --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.datetime + +import app.meetacy.sdk.types.datetime.Date +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class DateSerializable(public val iso8601: String) + +public fun DateSerializable.type(): Date = Date.parse(iso8601) +public fun Date.serializable(): DateSerializable = DateSerializable(iso8601) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationId.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationId.kt new file mode 100644 index 00000000..bc78678f --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationId.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.invitation + +import app.meetacy.sdk.types.invitation.InvitationId +import kotlin.jvm.JvmInline +import kotlinx.serialization.Serializable + +@Serializable +@JvmInline +public value class InvitationIdSerializable(public val string: String) + +public fun InvitationIdSerializable.type(): InvitationId = InvitationId(string) +public fun InvitationId.serializable(): InvitationIdSerializable = InvitationIdSerializable(string) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt new file mode 100644 index 00000000..90eb4d0b --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt @@ -0,0 +1,30 @@ +package app.meetacy.sdk.types.serializable.invitation + +import app.meetacy.sdk.types.invitation.AcceptationState +import app.meetacy.sdk.types.invitation.Invitation +import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable +import app.meetacy.sdk.types.serializable.meeting.type +import app.meetacy.sdk.types.serializable.user.UserSerializable +import app.meetacy.sdk.types.serializable.user.type +import kotlinx.serialization.Serializable + +@Serializable +public data class InvitationSerializable( + val identity: InvitationIdSerializable, + val invitedUser: UserSerializable, + val inviterUser: UserSerializable, + val meeting: MeetingSerializable, + val isAccepted: Boolean? +) + +public fun InvitationSerializable.type(): Invitation = Invitation( + id = identity.type(), + meeting = meeting.type(), + invitedUser = invitedUser.type(), + inviterUser = inviterUser.type(), + isAccepted = when (isAccepted) { + null -> AcceptationState.Waiting + true -> AcceptationState.Accepted + false -> AcceptationState.Declined + } +) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingIdSerializable.kt new file mode 100644 index 00000000..20892d18 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingIdSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.meeting + +import app.meetacy.sdk.types.meeting.MeetingId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class MeetingIdSerializable(public val string: String) + +public fun MeetingIdSerializable.type(): MeetingId = MeetingId(string) +public fun MeetingId.serializable(): MeetingIdSerializable = MeetingIdSerializable(string) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt new file mode 100644 index 00000000..2eda6c26 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -0,0 +1,56 @@ +package app.meetacy.sdk.types.serializable.meeting + +import app.meetacy.sdk.types.meeting.Meeting +import app.meetacy.sdk.types.serializable.datetime.DateSerializable +import app.meetacy.sdk.types.serializable.datetime.type +import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.type +import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.type +import app.meetacy.sdk.types.serializable.user.UserSerializable +import app.meetacy.sdk.types.serializable.user.type +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public data class MeetingSerializable( + val id: MeetingIdSerializable, + val creator: UserSerializable, + val date: DateSerializable, + val location: LocationSerializable, + val title: String?, + val description: String?, + val participantsCount: Int, + val previewParticipants: List, + val isParticipating: Boolean, + val avatarIdentity: FileIdSerializable?, + val visibility: Visibility +) { + @Serializable + public enum class Visibility { + @SerialName("public") + Public, + @SerialName("private") + Private + } +} + +public fun MeetingSerializable.type(): Meeting = Meeting( + id = id.type(), + creator = creator.type(), + date = date.type(), + location = location.type(), + title = title, + description = description, + participantsCount = participantsCount, + previewParticipants = previewParticipants.map { it.type() }, + isParticipating = isParticipating, + avatarId = avatarIdentity?.type(), + visibility = visibility.type() +) + +public fun MeetingSerializable.Visibility.type(): Meeting.Visibility = when (this) { + MeetingSerializable.Visibility.Public -> Meeting.Visibility.Public + MeetingSerializable.Visibility.Private -> Meeting.Visibility.Private +} + diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt similarity index 87% rename from types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt rename to types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt index 28d1dcf5..b7d56e3f 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/pagingId/PagingIdSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt @@ -1,4 +1,4 @@ -package app.meetacy.sdk.types.serializable.pagingId +package app.meetacy.sdk.types.serializable.paging import app.meetacy.sdk.types.paging.PagingId import kotlinx.serialization.Serializable diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt index 3fb2d894..a21d3da2 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt @@ -1,7 +1,6 @@ package app.meetacy.sdk.types.meeting import app.meetacy.sdk.types.datetime.Date -import app.meetacy.sdk.types.datetime.DateOrTime import app.meetacy.sdk.types.file.FileId import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.user.User @@ -16,7 +15,7 @@ public data class Meeting( val creator: User, val date: Date, val location: Location, - val title: String, + val title: String?, val description: String?, val participantsCount: Int, val previewParticipants: List, From 541f268c58ef6caef333e035cd293d03ebfcd60b Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sun, 29 Oct 2023 16:59:06 +0300 Subject: [PATCH 05/56] WIP(#79-support-search): meeting engine was refactored --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 4 +- .../ktor/requests/meetings/MeetingsEngine.kt | 288 ++++++++++-------- .../ListMeetingParticipantsResponse.kt | 13 + .../ktor/response/ListMeetingsResponse.kt | 13 + .../engine/requests/CreateMeetingRequest.kt | 2 +- .../meeting/MeetingSerializable.kt | 5 + 6 files changed, 195 insertions(+), 130 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt 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 1bc7bdb7..b2ca2e00 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 @@ -48,9 +48,9 @@ public class KtorMeetacyEngine( private val auth = AuthEngine(baseUrl, this.httpClient) private val users = UsersEngine(baseUrl, this.httpClient) private val friends = FriendsEngine(baseUrl, this.httpClient, this.json) - private val meetings = MeetingsEngine(baseUrl, this.httpClient, this.json) + private val meetings = MeetingsEngine(baseUrl, this.httpClient) private val files = FilesEngine(baseUrl, this.httpClient) - private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json) + private val invitations = InvitationsEngine(baseUrl, this.httpClient) private val notifications = NotificationsEngine(baseUrl, this.httpClient, this.json) private val search = SearchEngine(baseUrl, this.httpClient) private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 29b5279c..e7ed64bf 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -1,157 +1,174 @@ package app.meetacy.sdk.engine.ktor.requests.meetings -import app.meetacy.sdk.engine.ktor.mapToMeeting -import app.meetacy.sdk.engine.ktor.mapToUser -import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.response.models.* -import app.meetacy.sdk.engine.ktor.models.CreateMeetingResponse -import app.meetacy.sdk.engine.ktor.models.EditMeetingResponse -import app.meetacy.sdk.engine.ktor.models.ListMapMeetingsResponse -import app.meetacy.sdk.engine.ktor.models.ListMeetingParticipantsResponse -import app.meetacy.sdk.engine.ktor.models.ListMeetingsResponse -import app.meetacy.sdk.engine.ktor.models.User as ModelUser +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.ListMeetingParticipantsResponse +import app.meetacy.sdk.engine.ktor.response.ListMeetingsResponse +import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.* -import app.meetacy.sdk.engine.requests.CreateMeetingRequest -import app.meetacy.sdk.engine.requests.EditMeetingRequest -import app.meetacy.sdk.engine.requests.ListMeetingParticipantsRequest import app.meetacy.sdk.types.optional.ifPresent import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.amount.AmountSerializable +import app.meetacy.sdk.types.serializable.amount.serializable +import app.meetacy.sdk.types.serializable.datetime.DateSerializable +import app.meetacy.sdk.types.serializable.datetime.serializable +import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.serializable +import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.serializable +import app.meetacy.sdk.types.serializable.meeting.MeetingIdSerializable +import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable +import app.meetacy.sdk.types.serializable.meeting.serializable +import app.meetacy.sdk.types.serializable.meeting.type +import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable +import app.meetacy.sdk.types.serializable.paging.serializable +import app.meetacy.sdk.types.serializable.user.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* -import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.content.* import io.ktor.http.* -import kotlinx.serialization.json.Json +import kotlinx.serialization.Serializable import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import kotlinx.serialization.json.putJsonObject -import app.meetacy.sdk.engine.ktor.models.Meeting as ModelMeeting internal class MeetingsEngine( baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { private val baseUrl = baseUrl / "meetings" + + @Serializable + private data class ListMeetingsPagingBody( + val amount: AmountSerializable, + val pagingId: PagingIdSerializable? + ) + private fun ListMeetingsHistoryRequest.toBody() = ListMeetingsPagingBody( + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listMeetingsHistory( request: ListMeetingsHistoryRequest - ): ListMeetingsHistoryRequest.Response = with(request) { + ): ListMeetingsHistoryRequest.Response { val url = baseUrl / "history" / "list" - - val jsonObject = buildJsonObject { - put("amount", amount.int) - put("pagingId", pagingId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(ModelMeeting::mapToMeeting) + data = response.data.map { meeting -> meeting.type() } ) - return ListMeetingsHistoryRequest.Response(paging) } + private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody( + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listActiveMeetings( request: ListActiveMeetingsRequest - ): ListActiveMeetingsRequest.Response = with(request) { + ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" - - val jsonObject = buildJsonObject { - put("amount", amount.int) - put("pagingId", pagingId?.string) - } - - val string = httpClient.get(url.string) { - setBody( - TextContent( - text = jsonObject.toString(), - contentType = ContentType.Application.Json - ) - ) - header("Authorization", request.token.string) - header("Api-Version", request.apiVersion.int) - }.body() - - val response = json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(ModelMeeting::mapToMeeting) + data = response.data.map { meeting -> meeting.type() } ) return ListActiveMeetingsRequest.Response(paging) } + private fun ListPastMeetingsRequest.toBody() = ListMeetingsPagingBody( + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listPastMeetings( request: ListPastMeetingsRequest - ): ListPastMeetingsRequest.Response = with(request) { + ): ListPastMeetingsRequest.Response { val url = baseUrl / "history" / "past" - - val jsonObject = buildJsonObject { - put("amount", amount.int) - put("pagingId", pagingId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(ModelMeeting::mapToMeeting) + data = response.data.map { meeting -> meeting.type() } ) return ListPastMeetingsRequest.Response(paging) } + @Serializable + private data class ListMeetingsMapBody( + val latitude: Double, + val longitude: Double + ) + private fun ListMeetingsMapRequest.toBody() = ListMeetingsMapBody(location.latitude, location.longitude) + suspend fun listMeetingsMap( request: ListMeetingsMapRequest - ): ListMeetingsMapRequest.Response = with (request) { + ): ListMeetingsMapRequest.Response { val url = baseUrl / "map" / "list" + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess>() - val jsonObject = buildJsonObject { - putJsonObject("location") { - put("latitude", location.latitude) - put("longitude", location.longitude) - } - } - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result - - val data = response.map(ModelMeeting::mapToMeeting) + val data = response.map { it.type() } return ListMeetingsMapRequest.Response(data) } + @Serializable + private data class CreateMeetingBody( + val title: String?, + val date: DateSerializable, + val location: LocationSerializable, + val description: String?, + val visibility: MeetingSerializable.Visibility, + val fileId: FileIdSerializable? + ) + private fun CreateMeetingRequest.toBody() = CreateMeetingBody( + title, + date.serializable(), + location.serializable(), + description, + visibility.serializable(), + fileId?.serializable() + ) + suspend fun createMeeting( request: CreateMeetingRequest ): CreateMeetingRequest.Response = with(request) { val url = baseUrl / "create" - - val jsonObject = buildJsonObject { - put("title", title) - put("description", description) - put("date", date.iso8601) - putJsonObject("location") { - put("latitude", location.latitude) - put("longitude", location.longitude) - } - put("visibility", visibility.name.lowercase()) - put("avatarId", fileId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val meeting = json.decodeFromString(string).result - - return CreateMeetingRequest.Response(meeting.mapToMeeting()) + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() + return CreateMeetingRequest.Response(response.type()) } suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { @@ -183,61 +200,78 @@ internal class MeetingsEngine( } } - val string = post(url.string, jsonObject, httpClient, request) - - val meeting = json.decodeFromString(string).result + val response = httpClient.post(url.string) { + setBody( + TextContent( + text = jsonObject.toString(), + contentType = ContentType.Application.Json + ) + ) + header("Authorization", request.token.string) + header("Api-Version", request.apiVersion.int.toString()) + }.bodyAsSuccess() - return EditMeetingRequest.Response(meeting.mapToMeeting()) + return EditMeetingRequest.Response(response.type()) } + @Serializable + private data class ListMeetingParticipantsBody( + val meetingId: MeetingIdSerializable, + val amount: AmountSerializable, + val pagingId: PagingIdSerializable? + ) + private fun ListMeetingParticipantsRequest.toBody() = ListMeetingParticipantsBody( + meetingId.serializable(), + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listMeetingParticipants( request: ListMeetingParticipantsRequest ): ListMeetingParticipantsRequest.Response { val url = baseUrl / "participants" / "list" - - val jsonObject = buildJsonObject { - put("meetingId", request.meetingId.string) - put("amount", request.amount.int) - put("pagingId", request.pagingId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() val paging = PagingResponse( - data = response.data.map(ModelUser::mapToUser), + data = response.data.map { it.type() }, nextPagingId = response.nextPagingId?.let(::PagingId) ) return ListMeetingParticipantsRequest.Response(paging) } - suspend fun participateMeeting(request: ParticipateMeetingRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse { - val url = baseUrl / "participate" + @Serializable + private data class ParticipateMeetingBody(val meetingId: MeetingIdSerializable) + private fun ParticipateMeetingRequest.toBody() = ParticipateMeetingBody(meetingId.serializable()) - val jsonObject = buildJsonObject { - put("meetingId", request.meetingId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - return Json.decodeFromString(string) + suspend fun participateMeeting(request: ParticipateMeetingRequest): StatusTrueResponse { + val url = baseUrl / "participate" + val body = request.toBody() + return httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() } + @Serializable + private data class GetMeetingBody(val meetingId: MeetingIdSerializable) + private fun GetMeetingRequest.toBody() = GetMeetingBody(meetingId.serializable()) + suspend fun getMeeting(request: GetMeetingRequest): GetMeetingRequest.Response { val url = baseUrl / "get" - - val jsonObject = buildJsonObject { - put("meetingId", request.meetingId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result - - val meeting = response.mapToMeeting() - - return GetMeetingRequest.Response(meeting) + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() + + return GetMeetingRequest.Response(response.type()) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt new file mode 100644 index 00000000..363d52ef --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.ktor.response + +import app.meetacy.sdk.types.serializable.user.UserSerializable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class ListMeetingParticipantsResponse ( + @SerialName("data") + val data: List, + @SerialName("nextPagingId") + val nextPagingId: String? = null +) \ No newline at end of file diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt new file mode 100644 index 00000000..ff2aadd3 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.ktor.response + +import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class ListMeetingsResponse ( + @SerialName("data") + val data: List, + @SerialName("nextPagingId") + val nextPagingId: String? = null +) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt index 2e199b24..0834fe62 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateMeetingRequest.kt @@ -8,7 +8,7 @@ import app.meetacy.sdk.types.meeting.Meeting public class CreateMeetingRequest( public val token: Token, - public val title: String, + public val title: String?, public val date: Date, public val location: Location, public val description: String?, diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 2eda6c26..4f8727e7 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -54,3 +54,8 @@ public fun MeetingSerializable.Visibility.type(): Meeting.Visibility = when (thi MeetingSerializable.Visibility.Private -> Meeting.Visibility.Private } +public fun Meeting.Visibility.serializable(): MeetingSerializable.Visibility = when (this) { + Meeting.Visibility.Public -> MeetingSerializable.Visibility.Public + Meeting.Visibility.Private -> MeetingSerializable.Visibility.Private +} + From 2c7405945f8d269352db6b01dda3c1c5aaa58a07 Mon Sep 17 00:00:00 2001 From: y9kap Date: Mon, 30 Oct 2023 18:16:20 +0300 Subject: [PATCH 06/56] WIP(#76-support-search): added DateTime in progress --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 2 +- .../notifications/NotificationsEngine.kt | 60 ++++++++++--------- .../ktor/response/ListNotificationResponse.kt | 13 ++++ .../datetime/DateOrTimeSerializable.kt | 12 ++++ .../datetime/DateTimeSerializable.kt | 12 ++++ .../NotificationIdSerializable.kt | 12 ++++ .../notification/NotificationSerializable.kt | 54 +++++++++++++++++ 7 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationIdSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt 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 b2ca2e00..f4073332 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 @@ -51,7 +51,7 @@ public class KtorMeetacyEngine( private val meetings = MeetingsEngine(baseUrl, this.httpClient) private val files = FilesEngine(baseUrl, this.httpClient) private val invitations = InvitationsEngine(baseUrl, this.httpClient) - private val notifications = NotificationsEngine(baseUrl, this.httpClient, this.json) + private val notifications = NotificationsEngine(baseUrl, this.httpClient) private val search = SearchEngine(baseUrl, this.httpClient) private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index 29c90517..6eeb9aaf 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -1,57 +1,59 @@ package app.meetacy.sdk.engine.ktor.requests.notifications -import app.meetacy.sdk.engine.ktor.mapToNotification -import app.meetacy.sdk.engine.ktor.requests.extencion.post -import app.meetacy.sdk.engine.ktor.models.ListNotificationsResponse -import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.ListMeetingsResponse +import app.meetacy.sdk.engine.ktor.response.ListNotificationsResponse +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token +import app.meetacy.sdk.engine.requests.CancelInvitationRequest import app.meetacy.sdk.engine.requests.ListNotificationsRequest import app.meetacy.sdk.engine.requests.ReadNotificationRequest import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.amount.AmountSerializable +import app.meetacy.sdk.types.serializable.amount.serializable +import app.meetacy.sdk.types.serializable.invitation.InvitationIdSerializable +import app.meetacy.sdk.types.serializable.invitation.serializable +import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable +import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.url.Url import io.ktor.client.* -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put +import io.ktor.client.request.* +import kotlinx.serialization.Serializable internal class NotificationsEngine( baseUrl: Url, - private val httpClient: HttpClient, - private val json: Json + private val httpClient: HttpClient ) { private val baseUrl = baseUrl / "notifications" + @Serializable + private data class ListNotificationsBody( + val amount: AmountSerializable, + val pagingId: PagingIdSerializable? + ) + private fun ListNotificationsRequest.toBody() = ListNotificationsBody(amount.serializable(), pagingId?.serializable()) + suspend fun list( request: ListNotificationsRequest - ): ListNotificationsRequest.Response = with (request) { + ): ListNotificationsRequest.Response { val url = baseUrl / "list" - - val jsonObject = buildJsonObject { - put("amount", amount.int) - put("pagingId", pagingId?.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - val response = json.decodeFromString(string).result + val body = request.toBody() + val response = httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() val paging = PagingResponse( - data = response.data.map { it.mapToNotification() }, + data = response.data.map { it }, nextPagingId = response.nextPagingId?.let(::PagingId) ) - ListNotificationsRequest.Response(paging) + return ListNotificationsRequest.Response(paging) } suspend fun read(request: ReadNotificationRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse = with (request) { val url = baseUrl / "read" - - val jsonObject = buildJsonObject { - put("lastNotificationId", request.lastNotificationId.string) - } - - val string = post(url.string, jsonObject, httpClient, request) - - return json.decodeFromString(string) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt new file mode 100644 index 00000000..f2792c30 --- /dev/null +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt @@ -0,0 +1,13 @@ +package app.meetacy.sdk.engine.ktor.response + +import app.meetacy.sdk.types.serializable.notification.NotificationSerializable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class ListNotificationsResponse ( + @SerialName("data") + val data: List, + @SerialName("nextPagingId") + val nextPagingId: String? = null +) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt new file mode 100644 index 00000000..707a36a3 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.datetime + +import app.meetacy.sdk.types.datetime.DateOrTime +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class DateOrTimeSerializable(public val string: String) + +public fun DateOrTimeSerializable.type(): DateOrTime = DateOrTime.parse(string) +public fun DateOrTime.serializable(): DateOrTimeSerializable = DateOrTimeSerializable(iso8601) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt new file mode 100644 index 00000000..030d5c17 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.datetime + +import app.meetacy.sdk.types.datetime.DateTime +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +public value class DateTimeSerializable(public val iso8601: String) + +public fun DateTimeSerializable.type(): DateTime = DateTime.parse(iso8601) +public fun DateTime.serializable(): DateTimeSerializable = DateTimeSerializable(iso8601) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationIdSerializable.kt new file mode 100644 index 00000000..5e6623e5 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationIdSerializable.kt @@ -0,0 +1,12 @@ +package app.meetacy.sdk.types.serializable.notification + +import app.meetacy.sdk.types.notification.NotificationId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + + +@Serializable +@JvmInline +public value class NotificationIdSerializable(public val string: String) +public fun NotificationIdSerializable.type(): NotificationId = NotificationId(string) +public fun NotificationId.serializable(): NotificationIdSerializable = NotificationIdSerializable(string) \ No newline at end of file diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt new file mode 100644 index 00000000..5d8ab610 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt @@ -0,0 +1,54 @@ +package app.meetacy.sdk.types.serializable.notification + +import app.meetacy.sdk.types.notification.Notification +import app.meetacy.sdk.types.serializable.datetime.DateTimeSerializable +import app.meetacy.sdk.types.serializable.datetime.type +import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable +import app.meetacy.sdk.types.serializable.meeting.type +import app.meetacy.sdk.types.serializable.user.UserSerializable +import app.meetacy.sdk.types.serializable.user.type +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public sealed class NotificationSerializable { + public abstract val id: NotificationIdSerializable + public abstract val isNew: Boolean + public abstract val date: DateTimeSerializable + + @SerialName("subscription") + @Serializable + public class Subscription( + override val isNew: Boolean, + override val id: NotificationIdSerializable, + override val date: DateTimeSerializable, + public val subscriber: UserSerializable, + ) : NotificationSerializable() + + @SerialName("meeting_invitation") + @Serializable + public class Invitation( + override val id: NotificationIdSerializable, + override val isNew: Boolean, + override val date: DateTimeSerializable, + public val meeting: MeetingSerializable, + public val inviter: UserSerializable, + ) : NotificationSerializable() +} + +public fun NotificationSerializable.type(): Notification = + when (this) { + is NotificationSerializable.Invitation -> Notification.Invitation( + id = id.type(), + isNew = isNew, + meeting = meeting.type(), + date = date.type(), + inviter = inviter.type() + ) + is NotificationSerializable.Subscription -> Notification.Subscription( + id = id.serializable(), + isNew = isNew, + subscriber = subscriber.mapToEndpoint(), + date = date.serializable() + ) + } \ No newline at end of file From 5b51dde6442027ca1cfce269d666fbebd137abc7 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 19:42:11 +0300 Subject: [PATCH 07/56] feat(#79-support-search): added support search --- .../ktor/requests/meetings/MeetingsEngine.kt | 69 ++++++++----------- .../notifications/NotificationsEngine.kt | 22 ++++-- .../ktor/requests/search/SearchEngine.kt | 24 +++++-- .../ktor/requests/updates/UpdatesEngine.kt | 8 +-- .../AuthorizedNotificationRepository.kt | 8 +-- .../notifications/NotificationRepository.kt | 4 +- .../address/AddressSerializable.kt | 26 +++++++ .../datetime/DateOrTimeSerializable.kt | 2 +- .../datetime/DateTimeSerializable.kt | 2 +- .../meeting/MeetingSerializable.kt | 18 +++++ .../notification/NotificationSerializable.kt | 11 +-- .../serializable/place/PlaceSerializable.kt | 19 +++++ .../search/SearchItemSerializable.kt | 32 +++++++++ .../serializable/user/UserSerializable.kt | 10 +++ .../sdk/types/notification/Notification.kt | 9 ++- 15 files changed, 189 insertions(+), 75 deletions(-) create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/address/AddressSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/place/PlaceSerializable.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index e7ed64bf..f4caa5c0 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -7,7 +7,7 @@ import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.* -import app.meetacy.sdk.types.optional.ifPresent +import app.meetacy.sdk.types.optional.map import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse import app.meetacy.sdk.types.serializable.amount.AmountSerializable @@ -22,18 +22,15 @@ import app.meetacy.sdk.types.serializable.meeting.MeetingIdSerializable import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable import app.meetacy.sdk.types.serializable.meeting.serializable import app.meetacy.sdk.types.serializable.meeting.type +import app.meetacy.sdk.types.serializable.optional.OptionalSerializable +import app.meetacy.sdk.types.serializable.optional.serializable import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.serializable.user.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* -import io.ktor.content.* -import io.ktor.http.* import kotlinx.serialization.Serializable -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import kotlinx.serialization.json.putJsonObject internal class MeetingsEngine( baseUrl: Url, @@ -171,44 +168,34 @@ internal class MeetingsEngine( return CreateMeetingRequest.Response(response.type()) } - suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { - val url = baseUrl / "edit" + @Serializable + private data class EditMeetingBody( + val meetingId: MeetingIdSerializable, + val title: OptionalSerializable, + val description: OptionalSerializable, + val location: OptionalSerializable, + val date: OptionalSerializable, + val avatarId: OptionalSerializable, + val visibility: OptionalSerializable + ) - val jsonObject = buildJsonObject { - put("meetingId", meetingId.string) - - title.ifPresent { title -> - put("title", title) - } - description.ifPresent { description -> - put("description", description) - } - location.ifPresent { location -> - putJsonObject("location") { - put("latitude", location.latitude) - put("longitude", location.longitude) - } - } - date.ifPresent { date -> - put("date", date.iso8601) - } - avatarId.ifPresent { avatarId -> - put("avatarId", avatarId?.string) - } - visibility.ifPresent { visibility -> - put("visibility", visibility.name.lowercase()) - } - } + private fun EditMeetingRequest.toBody() = EditMeetingBody( + meetingId.serializable(), + title.serializable(), + description.serializable(), + location.map { it.serializable() }.serializable(), + date.map { it.serializable() }.serializable(), + avatarId.map { it?.serializable() }.serializable(), + visibility.map { it.serializable() }.serializable() + ) + suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { + val url = baseUrl / "edit" + val body = request.toBody() val response = httpClient.post(url.string) { - setBody( - TextContent( - text = jsonObject.toString(), - contentType = ContentType.Application.Json - ) - ) - header("Authorization", request.token.string) - header("Api-Version", request.apiVersion.int.toString()) + apiVersion(request.apiVersion) + token(request.token) + setBody(body) }.bodyAsSuccess() return EditMeetingRequest.Response(response.type()) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index 6eeb9aaf..19d726a9 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -1,19 +1,19 @@ package app.meetacy.sdk.engine.ktor.requests.notifications import app.meetacy.sdk.engine.ktor.apiVersion -import app.meetacy.sdk.engine.ktor.response.ListMeetingsResponse import app.meetacy.sdk.engine.ktor.response.ListNotificationsResponse +import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token -import app.meetacy.sdk.engine.requests.CancelInvitationRequest import app.meetacy.sdk.engine.requests.ListNotificationsRequest import app.meetacy.sdk.engine.requests.ReadNotificationRequest import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable -import app.meetacy.sdk.types.serializable.invitation.InvitationIdSerializable -import app.meetacy.sdk.types.serializable.invitation.serializable +import app.meetacy.sdk.types.serializable.notification.NotificationIdSerializable +import app.meetacy.sdk.types.serializable.notification.serializable +import app.meetacy.sdk.types.serializable.notification.type import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.url.Url @@ -46,14 +46,24 @@ internal class NotificationsEngine( }.bodyAsSuccess() val paging = PagingResponse( - data = response.data.map { it }, + data = response.data.map { it.type() }, nextPagingId = response.nextPagingId?.let(::PagingId) ) return ListNotificationsRequest.Response(paging) } - suspend fun read(request: ReadNotificationRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse = with (request) { + @Serializable + private data class ReadNotificationBody(val lastNotificationId: NotificationIdSerializable) + private fun ReadNotificationRequest.toBody() = ReadNotificationBody(lastNotificationId.serializable()) + + suspend fun read(request: ReadNotificationRequest): StatusTrueResponse { val url = baseUrl / "read" + val body = request.toBody() + return httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess() } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt index 88b2e1f0..1c8e580b 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -1,9 +1,17 @@ package app.meetacy.sdk.engine.ktor.requests.search +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.SearchRequest +import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.serializable +import app.meetacy.sdk.types.serializable.search.SearchItemSerializable +import app.meetacy.sdk.types.serializable.search.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* +import kotlinx.serialization.Serializable internal class SearchEngine( baseUrl: Url, @@ -11,9 +19,17 @@ internal class SearchEngine( ) { val baseUrl: Url = baseUrl / "search" - suspend fun search(request: SearchRequest){ - httpClient.get(baseUrl.string) { - request.location - } + @Serializable + private data class SearchBody(val location: LocationSerializable, val promt: String) + private fun SearchRequest.toBody() = SearchBody(location.serializable(), prompt) + + suspend fun search(request: SearchRequest): SearchRequest.Response { + val body = request.toBody() + val response = httpClient.get(baseUrl.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.bodyAsSuccess>() + return SearchRequest.Response(response.map { it.type() }) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt index 6a79349c..aa2df3b7 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt @@ -1,9 +1,9 @@ package app.meetacy.sdk.engine.ktor.requests.updates import app.meetacy.sdk.engine.ktor.handleRSocketExceptions -import app.meetacy.sdk.engine.ktor.mapToNotification import app.meetacy.sdk.engine.requests.EmitUpdatesRequest -import app.meetacy.sdk.engine.ktor.models.Notification as ModelNotification +import app.meetacy.sdk.types.serializable.notification.NotificationSerializable +import app.meetacy.sdk.types.serializable.notification.type import app.meetacy.sdk.types.update.Update import app.meetacy.sdk.types.update.UpdateId import app.meetacy.sdk.types.url.Url @@ -64,7 +64,7 @@ private sealed interface UpdateSerializable { @Serializable data class Notification( override val id: String, - val notification: ModelNotification + val notification: NotificationSerializable ) : UpdateSerializable } @@ -74,7 +74,7 @@ private fun Payload.decodeToUpdate(json: Json): Update { ) { is UpdateSerializable.Notification -> Update.Notification( id = UpdateId(deserialized.id), - notification = deserialized.notification.mapToNotification() + notification = deserialized.notification.type() ) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/AuthorizedNotificationRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/AuthorizedNotificationRepository.kt index 7cf7ffb1..48665b24 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/AuthorizedNotificationRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/AuthorizedNotificationRepository.kt @@ -3,14 +3,10 @@ package app.meetacy.sdk.notifications import app.meetacy.sdk.AuthorizedMeetacyApi import app.meetacy.sdk.meetings.AuthorizedMeetingRepository import app.meetacy.sdk.types.auth.Token -import app.meetacy.sdk.types.datetime.Date -import app.meetacy.sdk.types.meeting.Meeting +import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.notification.Notification import app.meetacy.sdk.types.notification.NotificationId -import app.meetacy.sdk.types.user.User import app.meetacy.sdk.users.AuthorizedRegularUserRepository -import app.meetacy.sdk.users.RegularUserRepository -import app.meetacy.sdk.users.UserRepository public sealed class AuthorizedNotificationRepository { protected abstract val api: AuthorizedMeetacyApi @@ -21,7 +17,7 @@ public sealed class AuthorizedNotificationRepository { public val id: NotificationId get() = data.id public val isNew: Boolean get() = data.isNew - public val date: Date get() = data.date + public val date: DateTime get() = data.date public suspend fun read() { api.notifications.read(id) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/NotificationRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/NotificationRepository.kt index 6d11ed05..1b1e3b4f 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/NotificationRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/notifications/NotificationRepository.kt @@ -3,7 +3,7 @@ package app.meetacy.sdk.notifications import app.meetacy.sdk.MeetacyApi import app.meetacy.sdk.meetings.MeetingRepository import app.meetacy.sdk.types.auth.Token -import app.meetacy.sdk.types.datetime.Date +import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.notification.Notification import app.meetacy.sdk.types.notification.NotificationId import app.meetacy.sdk.users.RegularUserRepository @@ -19,7 +19,7 @@ public sealed class NotificationRepository { public val id: NotificationId get() = data.id public val isNew: Boolean get() = data.isNew - public val date: Date get() = data.date + public val date: DateTime get() = data.date public suspend fun read(token: Token) { api.notifications.read(token, id) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/address/AddressSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/address/AddressSerializable.kt new file mode 100644 index 00000000..f36f3e65 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/address/AddressSerializable.kt @@ -0,0 +1,26 @@ +package app.meetacy.sdk.types.serializable.address + +import app.meetacy.sdk.types.address.Address +import kotlinx.serialization.Serializable + +@Serializable +public data class AddressSerializable( + val country: String, + val city: String, + val street: String, + val placeName: String? +) + +public fun AddressSerializable.type(): Address = Address( + country, + city, + street, + placeName +) + +public fun Address.serializable(): AddressSerializable = AddressSerializable( + country, + city, + street, + placeName +) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt index 707a36a3..403f1072 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateOrTimeSerializable.kt @@ -9,4 +9,4 @@ import kotlin.jvm.JvmInline public value class DateOrTimeSerializable(public val string: String) public fun DateOrTimeSerializable.type(): DateOrTime = DateOrTime.parse(string) -public fun DateOrTime.serializable(): DateOrTimeSerializable = DateOrTimeSerializable(iso8601) \ No newline at end of file +public fun DateOrTime.serializable(): DateOrTimeSerializable = DateOrTimeSerializable(iso8601) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt index 030d5c17..380afa42 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/datetime/DateTimeSerializable.kt @@ -9,4 +9,4 @@ import kotlin.jvm.JvmInline public value class DateTimeSerializable(public val iso8601: String) public fun DateTimeSerializable.type(): DateTime = DateTime.parse(iso8601) -public fun DateTime.serializable(): DateTimeSerializable = DateTimeSerializable(iso8601) \ No newline at end of file +public fun DateTime.serializable(): DateTimeSerializable = DateTimeSerializable(iso8601) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 4f8727e7..3c49b127 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -2,12 +2,16 @@ package app.meetacy.sdk.types.serializable.meeting import app.meetacy.sdk.types.meeting.Meeting import app.meetacy.sdk.types.serializable.datetime.DateSerializable +import app.meetacy.sdk.types.serializable.datetime.serializable import app.meetacy.sdk.types.serializable.datetime.type import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.serializable import app.meetacy.sdk.types.serializable.file.type import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.serializable import app.meetacy.sdk.types.serializable.location.type import app.meetacy.sdk.types.serializable.user.UserSerializable +import app.meetacy.sdk.types.serializable.user.serializable import app.meetacy.sdk.types.serializable.user.type import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -59,3 +63,17 @@ public fun Meeting.Visibility.serializable(): MeetingSerializable.Visibility = w Meeting.Visibility.Private -> MeetingSerializable.Visibility.Private } +public fun Meeting.serializable(): MeetingSerializable = MeetingSerializable( + id = id.serializable(), + creator = creator.serializable(), + date = date.serializable(), + location = location.serializable(), + title = title, + description = description, + participantsCount = participantsCount, + previewParticipants = previewParticipants.map { it.serializable() }, + isParticipating = isParticipating, + avatarIdentity = avatarId?.serializable(), + visibility = visibility.serializable() +) + diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt index 5d8ab610..e4bc2070 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt @@ -7,6 +7,7 @@ import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable import app.meetacy.sdk.types.serializable.meeting.type import app.meetacy.sdk.types.serializable.user.UserSerializable import app.meetacy.sdk.types.serializable.user.type +import app.meetacy.sdk.types.user.RegularUser import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -43,12 +44,12 @@ public fun NotificationSerializable.type(): Notification = isNew = isNew, meeting = meeting.type(), date = date.type(), - inviter = inviter.type() + inviter = inviter.type() as RegularUser ) is NotificationSerializable.Subscription -> Notification.Subscription( - id = id.serializable(), + id = id.type(), isNew = isNew, - subscriber = subscriber.mapToEndpoint(), - date = date.serializable() + subscriber = subscriber.type() as RegularUser, + date = date.type() ) - } \ No newline at end of file + } diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/place/PlaceSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/place/PlaceSerializable.kt new file mode 100644 index 00000000..8cf5ab76 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/place/PlaceSerializable.kt @@ -0,0 +1,19 @@ +package app.meetacy.sdk.types.serializable.place + +import app.meetacy.sdk.types.place.Place +import app.meetacy.sdk.types.serializable.address.AddressSerializable +import app.meetacy.sdk.types.serializable.address.serializable +import app.meetacy.sdk.types.serializable.address.type +import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.serializable +import app.meetacy.sdk.types.serializable.location.type +import kotlinx.serialization.Serializable + +@Serializable +public data class PlaceSerializable( + val address: AddressSerializable, + val location: LocationSerializable +) + +public fun PlaceSerializable.type(): Place = Place(address.type(), location.type()) +public fun Place.serializable(): PlaceSerializable = PlaceSerializable(address.serializable(), location.serializable()) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt new file mode 100644 index 00000000..14183c1e --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt @@ -0,0 +1,32 @@ +package app.meetacy.sdk.types.serializable.search + +import app.meetacy.sdk.types.search.SearchItem +import app.meetacy.sdk.types.serializable.meeting.serializable +import app.meetacy.sdk.types.serializable.meeting.type +import app.meetacy.sdk.types.serializable.place.serializable +import app.meetacy.sdk.types.serializable.place.type +import app.meetacy.sdk.types.serializable.user.serializable +import app.meetacy.sdk.types.serializable.user.type +import kotlinx.serialization.Serializable +import app.meetacy.sdk.types.serializable.place.PlaceSerializable as PlaceViewSerializable +import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable as MeetingViewSerializable +import app.meetacy.sdk.types.serializable.user.UserSerializable as UserViewSerializable + +@Serializable +public sealed interface SearchItemSerializable { + public class Meeting(public val meeting: MeetingViewSerializable) : SearchItemSerializable + public class User(public val user: UserViewSerializable) : SearchItemSerializable + public class Place(public val place: PlaceViewSerializable) : SearchItemSerializable +} + +public fun SearchItem.serializable(): SearchItemSerializable = when (this) { + is SearchItem.Meeting -> SearchItemSerializable.Meeting(meeting.serializable()) + is SearchItem.Place -> SearchItemSerializable.Place(place.serializable()) + is SearchItem.User -> SearchItemSerializable.User(user.serializable()) +} + +public fun SearchItemSerializable.type(): SearchItem = when (this) { + is SearchItemSerializable.Meeting -> SearchItem.Meeting(meeting.type()) + is SearchItemSerializable.Place -> SearchItem.Place(place.type()) + is SearchItemSerializable.User -> SearchItem.User(user.type()) +} diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt index ecc6419d..a5b7079d 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt @@ -3,6 +3,7 @@ package app.meetacy.sdk.types.serializable.user import app.meetacy.sdk.types.serializable.email.EmailSerializable import app.meetacy.sdk.types.serializable.email.type import app.meetacy.sdk.types.serializable.file.FileIdSerializable +import app.meetacy.sdk.types.serializable.file.serializable import app.meetacy.sdk.types.serializable.file.type import app.meetacy.sdk.types.user.RegularUser import app.meetacy.sdk.types.user.SelfUser @@ -48,3 +49,12 @@ public fun UserSerializable.type(): User = if (isSelf) { relationship = relationship?.type() ?: error("Regular user should always return relationship parameter") ) } + +public fun User.serializable(): UserSerializable = UserSerializable( + isSelf = isSelf, + relationship = relationship?.serializable(), + id = id.serializable(), + nickname = nickname, + username = username?.serializable(), + avatarId = avatarId?.serializable() +) diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/notification/Notification.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/notification/Notification.kt index 99c4636b..bf02c277 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/notification/Notification.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/notification/Notification.kt @@ -1,26 +1,25 @@ package app.meetacy.sdk.types.notification -import app.meetacy.sdk.types.datetime.Date +import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.meeting.Meeting import app.meetacy.sdk.types.user.RegularUser -import app.meetacy.sdk.types.user.User public sealed interface Notification { public val id: NotificationId public val isNew: Boolean - public val date: Date + public val date: DateTime public data class Subscription( override val id: NotificationId, override val isNew: Boolean, - override val date: Date, + override val date: DateTime, public val subscriber: RegularUser, ) : Notification public data class Invitation( override val id: NotificationId, override val isNew: Boolean, - override val date: Date, + override val date: DateTime, public val meeting: Meeting, public val inviter: RegularUser ) : Notification From 858fbc3e763900d98e49457b32444bc3ca2368b7 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 19:50:19 +0300 Subject: [PATCH 08/56] fix(#79-support-search): change nullability for type title in meeting --- .../app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt | 5 ++--- .../kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index 466ec9bc..d7724c80 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -3,10 +3,9 @@ package app.meetacy.sdk.meetings import app.meetacy.sdk.AuthorizedMeetacyApi import app.meetacy.sdk.files.FileRepository import app.meetacy.sdk.meetings.participants.AuthorizedMeetingParticipantsRepository -import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.datetime.Date -import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.file.FileId +import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.meeting.Meeting import app.meetacy.sdk.types.meeting.MeetingId import app.meetacy.sdk.types.optional.Optional @@ -22,7 +21,7 @@ public class AuthorizedMeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String get() = data.title + public val title: String? get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 6f48c2fe..61cdc512 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -5,9 +5,8 @@ import app.meetacy.sdk.files.FileRepository import app.meetacy.sdk.meetings.participants.MeetingParticipantsRepository import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.datetime.Date -import app.meetacy.sdk.types.location.Location -import app.meetacy.sdk.types.datetime.DateOrTime import app.meetacy.sdk.types.file.FileId +import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.meeting.Meeting import app.meetacy.sdk.types.meeting.MeetingId import app.meetacy.sdk.types.optional.Optional @@ -25,7 +24,7 @@ public class MeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String get() = data.title + public val title: String? get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants From 71c08f81cc46061f51f5ec6f027444e78c4fe5c6 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 19:59:53 +0300 Subject: [PATCH 09/56] fix(#79-support-search): change upload response body --- .../engine/ktor/requests/files/FilesEngine.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt index 16b72061..64298f33 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt @@ -1,6 +1,8 @@ package app.meetacy.sdk.engine.ktor.requests.files -import app.meetacy.sdk.engine.ktor.response.models.GenerateIdentityResponse +import app.meetacy.sdk.engine.ktor.apiVersion +import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess +import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.GetFileRequest import app.meetacy.sdk.engine.requests.UploadFileRequest import app.meetacy.sdk.files.DownloadableFile @@ -18,7 +20,6 @@ import io.ktor.client.statement.* import io.ktor.http.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.coroutineScope -import kotlinx.serialization.json.Json internal class FilesEngine( private val baseUrl: Url, @@ -57,7 +58,7 @@ internal class FilesEngine( suspend fun upload(request: UploadFileRequest): UploadFileRequest.Response = coroutineScope { val url = baseUrl / "files" / "upload" - val string = httpClient.submitFormWithBinaryData( + val response = httpClient.submitFormWithBinaryData( url = url.string, formData = formData { append( @@ -73,14 +74,11 @@ internal class FilesEngine( ) } ) { - header("Api-Version", request.apiVersion.int) - header("Authorization", request.token.string) - }.bodyAsText() - - val response = Json.decodeFromString(string) - - val fileId = FileId(response.result) + apiVersion(request.apiVersion) + token(request.token) + }.bodyAsSuccess() + val fileId = FileId(response) UploadFileRequest.Response(fileId) } } From b8482c09b2ecda75a283a392f6e9f7c2af8a9212 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 20:14:22 +0300 Subject: [PATCH 10/56] fix(#79-support-search): add default request for content type --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 5 +++++ .../meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) 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 f4073332..3caa46ec 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 @@ -23,6 +23,8 @@ import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.websocket.* +import io.ktor.client.request.* +import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -43,6 +45,9 @@ public class KtorMeetacyEngine( install(WebSockets) install(RSocketSupport) + defaultRequest { + header(HttpHeaders.ContentType, ContentType.Application.Json.contentType) + } } private val auth = AuthEngine(baseUrl, this.httpClient) 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 e24ce0cb..08b00a3e 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 @@ -7,7 +7,6 @@ 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.UsernameAvailableRequest -import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.optional.map import app.meetacy.sdk.types.serializable.file.FileIdSerializable import app.meetacy.sdk.types.serializable.file.serializable @@ -88,7 +87,6 @@ internal class UsersEngine( ) - @OptIn(UnsafeConstructor::class) suspend fun usernameAvailable(request: UsernameAvailableRequest): UsernameAvailableRequest.Response { val url = baseUrl / "username" / "available" val body = request.toBody() From ca438ece1119678de34fdde3e27c2ac5487ad2d7 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 20:29:40 +0300 Subject: [PATCH 11/56] fix(#79-support-search): remove default request for content type --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 5 ----- 1 file changed, 5 deletions(-) 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 3caa46ec..f4073332 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 @@ -23,8 +23,6 @@ import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.websocket.* -import io.ktor.client.request.* -import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -45,9 +43,6 @@ public class KtorMeetacyEngine( install(WebSockets) install(RSocketSupport) - defaultRequest { - header(HttpHeaders.ContentType, ContentType.Application.Json.contentType) - } } private val auth = AuthEngine(baseUrl, this.httpClient) From 38b4494ac0726f012306e30941b2d3910bb33066 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 22:03:04 +0300 Subject: [PATCH 12/56] fix(#79-support-search): add content-negotiation --- api/api-ktor/build.gradle.kts | 1 + .../app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/api-ktor/build.gradle.kts b/api/api-ktor/build.gradle.kts index 5b09f734..e4a35a28 100644 --- a/api/api-ktor/build.gradle.kts +++ b/api/api-ktor/build.gradle.kts @@ -11,6 +11,7 @@ dependencies { commonMainImplementation(libs.ktorClientLogging) commonMainImplementation(libs.ktorClientWebSockets) commonMainImplementation(libs.rsocketKtorClient) + commonMainImplementation(libs.ktorClientContentNegotiation) commonMainApi(projects.api) commonMainImplementation(projects.types.serializable) 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 f4073332..22ef33de 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 @@ -22,6 +22,7 @@ import app.meetacy.sdk.types.url.parametersOf import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.plugins.* +import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport @@ -39,8 +40,13 @@ public class KtorMeetacyEngine( } private val httpClient = httpClient.config { - expectSuccess = true + install(ContentNegotiation) { + Json(json) { + ignoreUnknownKeys = true + } + } + expectSuccess = true install(WebSockets) install(RSocketSupport) } From 2655a8ad2338d45dfec040cfc6ea628912f97b52 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 22:10:49 +0300 Subject: [PATCH 13/56] fix(#79-support-search): add content-type default header --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 22ef33de..dbe3ae90 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 @@ -24,6 +24,8 @@ import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* +import io.ktor.client.request.* +import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -45,7 +47,9 @@ public class KtorMeetacyEngine( ignoreUnknownKeys = true } } - + defaultRequest { + header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + } expectSuccess = true install(WebSockets) install(RSocketSupport) From 4f166e397cdec3988bb5a036a21a8c1eaab2440a Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 23:40:30 +0300 Subject: [PATCH 14/56] fix(#79-support-search): change name of success --- .../app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 7 ++++--- .../app/meetacy/sdk/engine/ktor/response/Response.kt | 12 ++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) 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 dbe3ae90..4c035978 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 @@ -42,6 +42,10 @@ public class KtorMeetacyEngine( } private val httpClient = httpClient.config { + + expectSuccess = true + install(WebSockets) + install(RSocketSupport) install(ContentNegotiation) { Json(json) { ignoreUnknownKeys = true @@ -50,9 +54,6 @@ public class KtorMeetacyEngine( defaultRequest { header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) } - expectSuccess = true - install(WebSockets) - install(RSocketSupport) } private val auth = AuthEngine(baseUrl, this.httpClient) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt index 48e5034d..bcc6a05a 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt @@ -3,15 +3,11 @@ package app.meetacy.sdk.engine.ktor.response import io.ktor.client.call.* import io.ktor.client.statement.* import io.rsocket.kotlin.payload.Payload -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -import kotlinx.serialization.builtins.NothingSerializer -import kotlinx.serialization.builtins.nullable import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.Json -import kotlin.reflect.KClass @Serializable(with = ServerResponse.Serializer::class) internal sealed interface ServerResponse { @@ -22,7 +18,7 @@ internal sealed interface ServerResponse { ) : ServerResponse @Serializable - data class Success(val data: T) : ServerResponse + data class Success(val result: T) : ServerResponse @Suppress("UNCHECKED_CAST") class Serializer(subSerializer: KSerializer) : KSerializer> { @@ -41,7 +37,7 @@ internal sealed interface ServerResponse { override fun serialize(encoder: Encoder, value: ServerResponse) { val data = Data( status = value is Success, - data = (value as? Success)?.data, + data = (value as? Success)?.result, errorCode = (value as? Error)?.errorCode, errorMessage = (value as? Error)?.errorMessage ) @@ -67,6 +63,6 @@ internal fun Payload.decodeToServerResponse( ) } -internal suspend inline fun HttpResponse.bodyAsSuccess(): T { - return body>().data +internal suspend inline fun HttpResponse.bodyAsSuccess(): T { + return body>().result } From 9af2d569ff4e0b496ffb64e89ea3b02abfa582ce Mon Sep 17 00:00:00 2001 From: y9Kap Date: Mon, 30 Oct 2023 23:55:56 +0300 Subject: [PATCH 15/56] fix(#79-support-search): fuckery serial name --- .../serializable/notification/NotificationSerializable.kt | 2 -- .../meetacy/sdk/types/serializable/user/UserSerializable.kt | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt index e4bc2070..c84b2568 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt @@ -17,7 +17,6 @@ public sealed class NotificationSerializable { public abstract val isNew: Boolean public abstract val date: DateTimeSerializable - @SerialName("subscription") @Serializable public class Subscription( override val isNew: Boolean, @@ -26,7 +25,6 @@ public sealed class NotificationSerializable { public val subscriber: UserSerializable, ) : NotificationSerializable() - @SerialName("meeting_invitation") @Serializable public class Invitation( override val id: NotificationIdSerializable, diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt index a5b7079d..c7531ac4 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt @@ -17,9 +17,9 @@ public data class UserSerializable( public val id: UserIdSerializable, @SerialName("nickname") public val nickname: String, - @SerialName("avatar_id") + @SerialName("avatarId") public val avatarId: FileIdSerializable?, - @SerialName("is_self") + @SerialName("isSelf") public val isSelf: Boolean, @SerialName("username") public val username: UsernameSerializable?, @@ -27,7 +27,7 @@ public data class UserSerializable( public val relationship: RelationshipSerializable? = null, @SerialName("email") public val email: EmailSerializable? = null, - @SerialName("email_verified") + @SerialName("emailVerified") public val emailVerified: Boolean? = null ) From a58088c87ccc46a85f3b12c59c552c8ce2797beb Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 00:12:27 +0300 Subject: [PATCH 16/56] fix(#79-support-search): fuckery nullability --- .../meetacy/sdk/types/serializable/user/UserSerializable.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt index c7531ac4..13eb8ba3 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/user/UserSerializable.kt @@ -18,11 +18,11 @@ public data class UserSerializable( @SerialName("nickname") public val nickname: String, @SerialName("avatarId") - public val avatarId: FileIdSerializable?, + public val avatarId: FileIdSerializable? = null, @SerialName("isSelf") public val isSelf: Boolean, @SerialName("username") - public val username: UsernameSerializable?, + public val username: UsernameSerializable? = null, @SerialName("relationship") public val relationship: RelationshipSerializable? = null, @SerialName("email") From 25a7bbbfa8ea7c0da0b6c758cecbe5ae6a134adb Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 00:35:39 +0300 Subject: [PATCH 17/56] fix(#79-support-search): fuckery is all --- .../ktor/requests/friends/FriendsEngine.kt | 5 +-- .../requests/invitations/InvitationsEngine.kt | 7 +++-- .../ktor/requests/meetings/MeetingsEngine.kt | 31 ++++++++++--------- .../notifications/NotificationsEngine.kt | 3 +- .../engine/ktor/requests/users/UsersEngine.kt | 6 ++-- .../sdk/engine/requests/EditMeetingRequest.kt | 12 +++---- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 86ba9269..5c3b0220 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -31,6 +31,7 @@ import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.RegularUser import app.meetacy.sdk.types.user.UserLocationSnapshot import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.request.* import io.rsocket.kotlin.ktor.client.rSocket import io.rsocket.kotlin.payload.Payload @@ -62,7 +63,7 @@ internal class FriendsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() return response } @@ -77,7 +78,7 @@ internal class FriendsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() return response } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt index a91c172b..8a35656b 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt @@ -18,6 +18,7 @@ import app.meetacy.sdk.types.serializable.user.UserIdSerializable import app.meetacy.sdk.types.serializable.user.serializable import app.meetacy.sdk.types.url.Url import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.request.* import kotlinx.serialization.Serializable @@ -63,7 +64,7 @@ internal class InvitationsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() } @Serializable @@ -79,7 +80,7 @@ internal class InvitationsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() } @Serializable @@ -95,6 +96,6 @@ internal class InvitationsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index f4caa5c0..c81c2e78 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -29,6 +29,7 @@ import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.serializable.user.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.request.* import kotlinx.serialization.Serializable @@ -140,17 +141,17 @@ internal class MeetingsEngine( @Serializable private data class CreateMeetingBody( val title: String?, + val description: String?, val date: DateSerializable, val location: LocationSerializable, - val description: String?, val visibility: MeetingSerializable.Visibility, - val fileId: FileIdSerializable? + val avatarId: FileIdSerializable? ) private fun CreateMeetingRequest.toBody() = CreateMeetingBody( title, + description, date.serializable(), location.serializable(), - description, visibility.serializable(), fileId?.serializable() ) @@ -171,22 +172,22 @@ internal class MeetingsEngine( @Serializable private data class EditMeetingBody( val meetingId: MeetingIdSerializable, - val title: OptionalSerializable, - val description: OptionalSerializable, - val location: OptionalSerializable, - val date: OptionalSerializable, - val avatarId: OptionalSerializable, - val visibility: OptionalSerializable + val title: String?, + val description: String?, + val location: LocationSerializable?, + val date: DateSerializable?, + val avatarId: OptionalSerializable = OptionalSerializable.Undefined, + val visibility: MeetingSerializable.Visibility? ) private fun EditMeetingRequest.toBody() = EditMeetingBody( meetingId.serializable(), - title.serializable(), - description.serializable(), - location.map { it.serializable() }.serializable(), - date.map { it.serializable() }.serializable(), + title, + description, + location?.serializable(), + date?.serializable(), avatarId.map { it?.serializable() }.serializable(), - visibility.map { it.serializable() }.serializable() + visibility?.serializable() ) suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { @@ -243,7 +244,7 @@ internal class MeetingsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() } @Serializable diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index 19d726a9..b0a533e1 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -18,6 +18,7 @@ import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.url.Url import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.request.* import kotlinx.serialization.Serializable @@ -64,6 +65,6 @@ internal class NotificationsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.body() } } 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 08b00a3e..b6daca70 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 @@ -56,9 +56,9 @@ internal class UsersEngine( @Serializable private data class EditUserBody( - val nickname: OptionalSerializable, - val avatarId: OptionalSerializable, - val username: OptionalSerializable + val nickname: OptionalSerializable = OptionalSerializable.Undefined, + val avatarId: OptionalSerializable = OptionalSerializable.Undefined, + val username: OptionalSerializable = OptionalSerializable.Undefined ) private fun EditUserRequest.toBody() = EditUserBody( diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 7bf66f50..986c4bb4 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -11,12 +11,12 @@ import app.meetacy.sdk.types.optional.Optional public data class EditMeetingRequest( public val token: Token, public val meetingId: MeetingId, - public val title: Optional, - public val description: Optional, - public val location: Optional, - public val date: Optional, - public val avatarId: Optional, - public val visibility: Optional + public val avatarId: Optional = Optional.Undefined, + public val title: String?, + public val description: String?, + public val location: Location?, + public val date: Date?, + public val visibility: Meeting.Visibility? ) : MeetacyRequest { public data class Response(val meeting: Meeting) } From 5032130acd8e32f504175bf1a98e413ffd7864b8 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 00:52:46 +0300 Subject: [PATCH 18/56] fix(#79-support-search): Quintus natus --- .../meetings/AuthorizedMeetingRepository.kt | 20 ++++++------- .../sdk/meetings/AuthorizedMeetingsApi.kt | 20 ++++++------- .../meetacy/sdk/meetings/MeetingRepository.kt | 28 +++++++++---------- .../app/meetacy/sdk/meetings/MeetingsApi.kt | 20 ++++++------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index d7724c80..1434e82f 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -40,21 +40,21 @@ public class AuthorizedMeetingRepository( avatarId: FileId?, visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edited( - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edited( - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): AuthorizedMeetingRepository { return api.meetings.edit( meetingId = data.id, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index 2994d44b..43ad2356 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -55,22 +55,22 @@ public class AuthorizedMeetingsApi( visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( meetingId = meetingId, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility ) public suspend fun edit( meetingId: MeetingId, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): AuthorizedMeetingRepository { val meeting = api.base.meetings.edit( token = api.token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 61cdc512..fa54dfb6 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -36,30 +36,30 @@ public class MeetingRepository( public suspend fun edited( token: Token, - title: String, - date: Date, - location: Location, + title: String?, + date: Date?, + location: Location?, description: String?, avatarId: FileId?, - visibility: Meeting.Visibility + visibility: Meeting.Visibility? ): MeetingRepository = edited( token = token, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edited( token: Token, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): MeetingRepository { return api.meetings.edit( token = token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index 19018b2a..b7478b09 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -62,23 +62,23 @@ public class MeetingsApi(private val api: MeetacyApi) { ): MeetingRepository = edit( token = token, meetingId = meetingId, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edit( token: Token, meetingId: MeetingId, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): MeetingRepository { val meeting = api.engine.execute( EditMeetingRequest( From acb0a8e9f8ec31ff8b1726087e6b85cd9c627e74 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 00:52:46 +0300 Subject: [PATCH 19/56] fix(#79-support-search): Quintus natus --- .../meetings/AuthorizedMeetingRepository.kt | 32 +++++++++---------- .../sdk/meetings/AuthorizedMeetingsApi.kt | 22 ++++++------- .../meetacy/sdk/meetings/MeetingRepository.kt | 28 ++++++++-------- .../app/meetacy/sdk/meetings/MeetingsApi.kt | 22 ++++++------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index d7724c80..6bb8f03e 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -33,28 +33,28 @@ public class AuthorizedMeetingRepository( AuthorizedMeetingParticipantsRepository(data.id, api) public suspend fun edited( - title: String, - date: Date, - location: Location, - description: String?, - avatarId: FileId?, - visibility: Meeting.Visibility + title: String? = null, + date: Date? = null, + location: Location? = null, + description: String? = null, + avatarId: FileId? = null, + visibility: Meeting.Visibility? = null ): AuthorizedMeetingRepository = edited( - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edited( - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): AuthorizedMeetingRepository { return api.meetings.edit( meetingId = data.id, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index 2994d44b..13482c8a 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -25,7 +25,7 @@ public class AuthorizedMeetingsApi( public val participants: AuthorizedMeetingParticipantsApi = AuthorizedMeetingParticipantsApi(api) public suspend fun create( - title: String, + title: String?, date: Date, location: Location, description: String? = null, @@ -55,22 +55,22 @@ public class AuthorizedMeetingsApi( visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( meetingId = meetingId, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility ) public suspend fun edit( meetingId: MeetingId, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): AuthorizedMeetingRepository { val meeting = api.base.meetings.edit( token = api.token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 61cdc512..fa54dfb6 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -36,30 +36,30 @@ public class MeetingRepository( public suspend fun edited( token: Token, - title: String, - date: Date, - location: Location, + title: String?, + date: Date?, + location: Location?, description: String?, avatarId: FileId?, - visibility: Meeting.Visibility + visibility: Meeting.Visibility? ): MeetingRepository = edited( token = token, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edited( token: Token, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): MeetingRepository { return api.meetings.edit( token = token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index 19018b2a..ba047249 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -28,7 +28,7 @@ public class MeetingsApi(private val api: MeetacyApi) { public suspend fun create( token: Token, - title: String, + title: String?, date: Date, location: Location, description: String? = null, @@ -62,23 +62,23 @@ public class MeetingsApi(private val api: MeetacyApi) { ): MeetingRepository = edit( token = token, meetingId = meetingId, - title = Optional.Present(title), - date = Optional.Present(date), - location = Optional.Present(location), - description = Optional.Present(description), + title = title, + date = date, + location = location, + description = description, avatarId = Optional.Present(avatarId), - visibility = Optional.Present(visibility), + visibility = visibility, ) public suspend fun edit( token: Token, meetingId: MeetingId, - title: Optional = Optional.Undefined, - date: Optional = Optional.Undefined, - location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + title: String?, + date: Date?, + location: Location?, + description: String?, avatarId: Optional = Optional.Undefined, - visibility: Optional = Optional.Undefined + visibility: Meeting.Visibility? ): MeetingRepository { val meeting = api.engine.execute( EditMeetingRequest( From b1c471c0e87ab65a84909c1180afebee9bdcd35b Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 01:47:38 +0300 Subject: [PATCH 20/56] fix(#79-support-search): back serial name in notifications --- .../sdk/types/serializable/meeting/MeetingSerializable.kt | 8 ++++---- .../serializable/notification/NotificationSerializable.kt | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 3c49b127..38073888 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -23,11 +23,11 @@ public data class MeetingSerializable( val date: DateSerializable, val location: LocationSerializable, val title: String?, - val description: String?, + val description: String? = null, val participantsCount: Int, val previewParticipants: List, val isParticipating: Boolean, - val avatarIdentity: FileIdSerializable?, + val avatarId: FileIdSerializable? = null, val visibility: Visibility ) { @Serializable @@ -49,7 +49,7 @@ public fun MeetingSerializable.type(): Meeting = Meeting( participantsCount = participantsCount, previewParticipants = previewParticipants.map { it.type() }, isParticipating = isParticipating, - avatarId = avatarIdentity?.type(), + avatarId = avatarId?.type(), visibility = visibility.type() ) @@ -73,7 +73,7 @@ public fun Meeting.serializable(): MeetingSerializable = MeetingSerializable( participantsCount = participantsCount, previewParticipants = previewParticipants.map { it.serializable() }, isParticipating = isParticipating, - avatarIdentity = avatarId?.serializable(), + avatarId = avatarId?.serializable(), visibility = visibility.serializable() ) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt index c84b2568..e4bc2070 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/notification/NotificationSerializable.kt @@ -17,6 +17,7 @@ public sealed class NotificationSerializable { public abstract val isNew: Boolean public abstract val date: DateTimeSerializable + @SerialName("subscription") @Serializable public class Subscription( override val isNew: Boolean, @@ -25,6 +26,7 @@ public sealed class NotificationSerializable { public val subscriber: UserSerializable, ) : NotificationSerializable() + @SerialName("meeting_invitation") @Serializable public class Invitation( override val id: NotificationIdSerializable, From 2a03203e732123dc7ed57940613d0172a268bb4f Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 02:09:33 +0300 Subject: [PATCH 21/56] fix(#79-support-search): added object location on list meetings map request --- .../ktor/requests/invitations/InvitationsEngine.kt | 4 ++-- .../engine/ktor/requests/meetings/MeetingsEngine.kt | 5 ++--- .../ktor/response/CreateInvitationResponse.kt | 13 ------------- 3 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt index 8a35656b..7c53f7e9 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt @@ -1,7 +1,6 @@ package app.meetacy.sdk.engine.ktor.requests.invitations import app.meetacy.sdk.engine.ktor.apiVersion -import app.meetacy.sdk.engine.ktor.response.CreateInvitationResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token @@ -10,6 +9,7 @@ import app.meetacy.sdk.engine.requests.CancelInvitationRequest import app.meetacy.sdk.engine.requests.CreateInvitationRequest import app.meetacy.sdk.engine.requests.DenyInvitationRequest import app.meetacy.sdk.types.serializable.invitation.InvitationIdSerializable +import app.meetacy.sdk.types.serializable.invitation.InvitationSerializable import app.meetacy.sdk.types.serializable.invitation.serializable import app.meetacy.sdk.types.serializable.invitation.type import app.meetacy.sdk.types.serializable.meeting.MeetingIdSerializable @@ -47,7 +47,7 @@ internal class InvitationsEngine( apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess().result + }.bodyAsSuccess() return CreateInvitationRequest.Response(response.type()) } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index c81c2e78..208ccdb3 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -117,10 +117,9 @@ internal class MeetingsEngine( @Serializable private data class ListMeetingsMapBody( - val latitude: Double, - val longitude: Double + val location: LocationSerializable ) - private fun ListMeetingsMapRequest.toBody() = ListMeetingsMapBody(location.latitude, location.longitude) + private fun ListMeetingsMapRequest.toBody() = ListMeetingsMapBody(location.serializable()) suspend fun listMeetingsMap( request: ListMeetingsMapRequest diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt deleted file mode 100644 index 46a20100..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/CreateInvitationResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response - -import app.meetacy.sdk.types.serializable.invitation.InvitationSerializable -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class CreateInvitationResponse ( - @SerialName("status") - val status: Boolean, - @SerialName("result") - val result: InvitationSerializable -) From 8b393e6253f796c944849764a8f75ff94dbf56c2 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 02:18:49 +0300 Subject: [PATCH 22/56] fix(#79-support-search): some fixes --- .../meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt | 2 +- .../sdk/types/serializable/invitation/InvitationSerializable.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 208ccdb3..2d7733e1 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -77,7 +77,7 @@ internal class MeetingsEngine( ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" val body = request.toBody() - val response = httpClient.post(url.string) { + val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt index 90eb4d0b..5fa533b7 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt @@ -14,7 +14,7 @@ public data class InvitationSerializable( val invitedUser: UserSerializable, val inviterUser: UserSerializable, val meeting: MeetingSerializable, - val isAccepted: Boolean? + val isAccepted: Boolean? = null ) public fun InvitationSerializable.type(): Invitation = Invitation( From a7173c1d5900bd079fbf7e69a5cca1415826d631 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 02:18:49 +0300 Subject: [PATCH 23/56] fix(#79-support-search): some fixes --- .../meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt | 2 +- .../sdk/types/serializable/invitation/InvitationSerializable.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 208ccdb3..2d7733e1 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -77,7 +77,7 @@ internal class MeetingsEngine( ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" val body = request.toBody() - val response = httpClient.post(url.string) { + val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt index 90eb4d0b..5fa533b7 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/invitation/InvitationSerializable.kt @@ -14,7 +14,7 @@ public data class InvitationSerializable( val invitedUser: UserSerializable, val inviterUser: UserSerializable, val meeting: MeetingSerializable, - val isAccepted: Boolean? + val isAccepted: Boolean? = null ) public fun InvitationSerializable.type(): Invitation = Invitation( From d2192055120f141a2c49c9a21b7426340813a44a Mon Sep 17 00:00:00 2001 From: y9Kap Date: Tue, 31 Oct 2023 02:36:50 +0300 Subject: [PATCH 24/56] fix(#79-support-search): clowns push --- .../app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt | 1 - 1 file changed, 1 deletion(-) 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 b6daca70..9c905f4e 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 @@ -40,7 +40,6 @@ internal class UsersEngine( @Serializable private data class GetUserBody(val id: UserIdSerializable?) - private fun GetUserRequest.toBody() = GetUserBody(userId?.serializable()) suspend fun getUser(request: GetUserRequest): GetUserRequest.Response { From 491d3a51354ce7b41155dcce8d566ab62f3b6f11 Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 11:43:28 +0300 Subject: [PATCH 25/56] fix(#76-support-search): remove default request headers --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 5 ----- .../sdk/engine/ktor/requests/friends/FriendsEngine.kt | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) 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 4c035978..ffa9a474 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 @@ -24,8 +24,6 @@ import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* -import io.ktor.client.request.* -import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -51,9 +49,6 @@ public class KtorMeetacyEngine( ignoreUnknownKeys = true } } - defaultRequest { - header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) - } } private val auth = AuthEngine(baseUrl, this.httpClient) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 5c3b0220..9f26a82d 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -48,7 +48,7 @@ import kotlinx.serialization.json.put internal class FriendsEngine( baseUrl: Url, private val httpClient: HttpClient, - val json: Json + private val json: Json ) { private val baseUrl = baseUrl / "friends" @@ -149,14 +149,14 @@ private fun Location.encodeToPayload(): Payload = buildPayload { } @Serializable -private data class ModelUserLocationSnapshotSerializable( +private data class UserLocationSnapshotSerializable( val user: UserSerializable, val location: LocationSerializable, val capturedAt: String ) private fun Payload.decodeToUserLocationSnapshot(json: Json): UserLocationSnapshot { - val deserialized = json.decodeFromString(data.readText()) + val deserialized = json.decodeFromString(data.readText()) return UserLocationSnapshot( user = deserialized.user.type() as RegularUser, From b86817ffc898e273b25bae6ca760c8b108dca126 Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 13:28:50 +0300 Subject: [PATCH 26/56] fix(#76-support-search): fuckery optional again --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 5 ++++ .../sdk/engine/requests/EditMeetingRequest.kt | 12 ++++---- .../sdk/meetings/AuthorizedMeetingsApi.kt | 20 ++++++------- .../meetacy/sdk/meetings/MeetingRepository.kt | 30 +++++++++---------- .../app/meetacy/sdk/meetings/MeetingsApi.kt | 20 ++++++------- .../meeting/MeetingSerializable.kt | 2 +- .../app/meetacy/sdk/types/meeting/Meeting.kt | 2 +- 7 files changed, 48 insertions(+), 43 deletions(-) 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 ffa9a474..4c035978 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 @@ -24,6 +24,8 @@ import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* +import io.ktor.client.request.* +import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -49,6 +51,9 @@ public class KtorMeetacyEngine( ignoreUnknownKeys = true } } + defaultRequest { + header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + } } private val auth = AuthEngine(baseUrl, this.httpClient) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 986c4bb4..7bf66f50 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -11,12 +11,12 @@ import app.meetacy.sdk.types.optional.Optional public data class EditMeetingRequest( public val token: Token, public val meetingId: MeetingId, - public val avatarId: Optional = Optional.Undefined, - public val title: String?, - public val description: String?, - public val location: Location?, - public val date: Date?, - public val visibility: Meeting.Visibility? + public val title: Optional, + public val description: Optional, + public val location: Optional, + public val date: Optional, + public val avatarId: Optional, + public val visibility: Optional ) : MeetacyRequest { public data class Response(val meeting: Meeting) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index 13482c8a..5c37365c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -55,22 +55,22 @@ public class AuthorizedMeetingsApi( visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( meetingId = meetingId, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility + visibility = Optional.Present(visibility), ) public suspend fun edit( meetingId: MeetingId, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { val meeting = api.base.meetings.edit( token = api.token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index fa54dfb6..338aef6c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -24,7 +24,7 @@ public class MeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String? get() = data.title + public val title: String get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants @@ -36,30 +36,30 @@ public class MeetingRepository( public suspend fun edited( token: Token, - title: String?, - date: Date?, - location: Location?, + title: String, + date: Date, + location: Location, description: String?, avatarId: FileId?, - visibility: Meeting.Visibility? + visibility: Meeting.Visibility ): MeetingRepository = edited( token = token, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility, + visibility = Optional.Present(visibility), ) public suspend fun edited( token: Token, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): MeetingRepository { return api.meetings.edit( token = token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index ba047249..d7506c61 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -62,23 +62,23 @@ public class MeetingsApi(private val api: MeetacyApi) { ): MeetingRepository = edit( token = token, meetingId = meetingId, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility, + visibility = Optional.Present(visibility), ) public suspend fun edit( token: Token, meetingId: MeetingId, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): MeetingRepository { val meeting = api.engine.execute( EditMeetingRequest( diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 38073888..5dc2f304 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -22,7 +22,7 @@ public data class MeetingSerializable( val creator: UserSerializable, val date: DateSerializable, val location: LocationSerializable, - val title: String?, + val title: String, val description: String? = null, val participantsCount: Int, val previewParticipants: List, diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt index a21d3da2..7c3426c7 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt @@ -15,7 +15,7 @@ public data class Meeting( val creator: User, val date: Date, val location: Location, - val title: String?, + val title: String, val description: String?, val participantsCount: Int, val previewParticipants: List, From 07be05aa96f0ca224f1379140a21c81171148546 Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 13:28:50 +0300 Subject: [PATCH 27/56] fix(#76-support-search): fuckery optional again --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 5 +++ .../sdk/engine/requests/EditMeetingRequest.kt | 12 +++---- .../meetings/AuthorizedMeetingRepository.kt | 34 +++++++++---------- .../sdk/meetings/AuthorizedMeetingsApi.kt | 20 +++++------ .../meetacy/sdk/meetings/MeetingRepository.kt | 30 ++++++++-------- .../app/meetacy/sdk/meetings/MeetingsApi.kt | 20 +++++------ .../meeting/MeetingSerializable.kt | 2 +- .../app/meetacy/sdk/types/meeting/Meeting.kt | 2 +- 8 files changed, 65 insertions(+), 60 deletions(-) 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 ffa9a474..4c035978 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 @@ -24,6 +24,8 @@ import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* +import io.ktor.client.request.* +import io.ktor.http.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -49,6 +51,9 @@ public class KtorMeetacyEngine( ignoreUnknownKeys = true } } + defaultRequest { + header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + } } private val auth = AuthEngine(baseUrl, this.httpClient) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 986c4bb4..7bf66f50 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -11,12 +11,12 @@ import app.meetacy.sdk.types.optional.Optional public data class EditMeetingRequest( public val token: Token, public val meetingId: MeetingId, - public val avatarId: Optional = Optional.Undefined, - public val title: String?, - public val description: String?, - public val location: Location?, - public val date: Date?, - public val visibility: Meeting.Visibility? + public val title: Optional, + public val description: Optional, + public val location: Optional, + public val date: Optional, + public val avatarId: Optional, + public val visibility: Optional ) : MeetacyRequest { public data class Response(val meeting: Meeting) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index 6bb8f03e..456c330b 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -21,7 +21,7 @@ public class AuthorizedMeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String? get() = data.title + public val title: String get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants @@ -33,28 +33,28 @@ public class AuthorizedMeetingRepository( AuthorizedMeetingParticipantsRepository(data.id, api) public suspend fun edited( - title: String? = null, - date: Date? = null, - location: Location? = null, - description: String? = null, - avatarId: FileId? = null, - visibility: Meeting.Visibility? = null + title: String, + date: Date, + location: Location, + description: String?, + avatarId: FileId?, + visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edited( - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility, + visibility = Optional.Present(visibility), ) public suspend fun edited( - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { return api.meetings.edit( meetingId = data.id, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index 13482c8a..5c37365c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -55,22 +55,22 @@ public class AuthorizedMeetingsApi( visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( meetingId = meetingId, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility + visibility = Optional.Present(visibility), ) public suspend fun edit( meetingId: MeetingId, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { val meeting = api.base.meetings.edit( token = api.token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index fa54dfb6..338aef6c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -24,7 +24,7 @@ public class MeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String? get() = data.title + public val title: String get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants @@ -36,30 +36,30 @@ public class MeetingRepository( public suspend fun edited( token: Token, - title: String?, - date: Date?, - location: Location?, + title: String, + date: Date, + location: Location, description: String?, avatarId: FileId?, - visibility: Meeting.Visibility? + visibility: Meeting.Visibility ): MeetingRepository = edited( token = token, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility, + visibility = Optional.Present(visibility), ) public suspend fun edited( token: Token, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): MeetingRepository { return api.meetings.edit( token = token, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index ba047249..d7506c61 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -62,23 +62,23 @@ public class MeetingsApi(private val api: MeetacyApi) { ): MeetingRepository = edit( token = token, meetingId = meetingId, - title = title, - date = date, - location = location, - description = description, + title = Optional.Present(title), + date = Optional.Present(date), + location = Optional.Present(location), + description = Optional.Present(description), avatarId = Optional.Present(avatarId), - visibility = visibility, + visibility = Optional.Present(visibility), ) public suspend fun edit( token: Token, meetingId: MeetingId, - title: String?, - date: Date?, - location: Location?, - description: String?, + title: Optional = Optional.Undefined, + date: Optional = Optional.Undefined, + location: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, - visibility: Meeting.Visibility? + visibility: Optional = Optional.Undefined ): MeetingRepository { val meeting = api.engine.execute( EditMeetingRequest( diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 38073888..5dc2f304 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -22,7 +22,7 @@ public data class MeetingSerializable( val creator: UserSerializable, val date: DateSerializable, val location: LocationSerializable, - val title: String?, + val title: String, val description: String? = null, val participantsCount: Int, val previewParticipants: List, diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt index a21d3da2..7c3426c7 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt @@ -15,7 +15,7 @@ public data class Meeting( val creator: User, val date: Date, val location: Location, - val title: String?, + val title: String, val description: String?, val participantsCount: Int, val previewParticipants: List, From 2512e66ecd8178076c0225c3ccbbc626829b9570 Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 13:42:04 +0300 Subject: [PATCH 28/56] fix(#76-support-search): restore edit --- .../ktor/requests/meetings/MeetingsEngine.kt | 20 +++++++++---------- .../sdk/engine/requests/EditMeetingRequest.kt | 2 +- .../meetings/AuthorizedMeetingRepository.kt | 4 ++-- .../sdk/meetings/AuthorizedMeetingsApi.kt | 4 ++-- .../meetacy/sdk/meetings/MeetingRepository.kt | 4 ++-- .../app/meetacy/sdk/meetings/MeetingsApi.kt | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 2d7733e1..96a15163 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -171,22 +171,22 @@ internal class MeetingsEngine( @Serializable private data class EditMeetingBody( val meetingId: MeetingIdSerializable, - val title: String?, - val description: String?, - val location: LocationSerializable?, - val date: DateSerializable?, + val title: OptionalSerializable, + val description: OptionalSerializable, + val location: OptionalSerializable, + val date: OptionalSerializable, val avatarId: OptionalSerializable = OptionalSerializable.Undefined, - val visibility: MeetingSerializable.Visibility? + val visibility: OptionalSerializable ) private fun EditMeetingRequest.toBody() = EditMeetingBody( meetingId.serializable(), - title, - description, - location?.serializable(), - date?.serializable(), + title.serializable(), + description.serializable(), + location.map { it.serializable() }.serializable(), + date.map { it.serializable() }.serializable(), avatarId.map { it?.serializable() }.serializable(), - visibility?.serializable() + visibility.map { it.serializable() }.serializable(), ) suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 7bf66f50..229e07ba 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -12,7 +12,7 @@ public data class EditMeetingRequest( public val token: Token, public val meetingId: MeetingId, public val title: Optional, - public val description: Optional, + public val description: Optional, public val location: Optional, public val date: Optional, public val avatarId: Optional, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index 456c330b..1a6b70d8 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -36,7 +36,7 @@ public class AuthorizedMeetingRepository( title: String, date: Date, location: Location, - description: String?, + description: String, avatarId: FileId?, visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edited( @@ -52,7 +52,7 @@ public class AuthorizedMeetingRepository( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index 5c37365c..e38611cd 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -50,7 +50,7 @@ public class AuthorizedMeetingsApi( title: String, date: Date, location: Location, - description: String?, + description: String, avatarId: FileId?, visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( @@ -68,7 +68,7 @@ public class AuthorizedMeetingsApi( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 338aef6c..840dd8c0 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -39,7 +39,7 @@ public class MeetingRepository( title: String, date: Date, location: Location, - description: String?, + description: String, avatarId: FileId?, visibility: Meeting.Visibility ): MeetingRepository = edited( @@ -57,7 +57,7 @@ public class MeetingRepository( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): MeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index d7506c61..7ce912aa 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -56,7 +56,7 @@ public class MeetingsApi(private val api: MeetacyApi) { title: String, date: Date, location: Location, - description: String?, + description: String, avatarId: FileId?, visibility: Meeting.Visibility ): MeetingRepository = edit( @@ -76,7 +76,7 @@ public class MeetingsApi(private val api: MeetacyApi) { title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): MeetingRepository { From 1deeb96da5572b29a27e3cb2e9afe265c8ad406a Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 14:01:00 +0300 Subject: [PATCH 29/56] fix(#76-support-search): restore create and edit --- .../sdk/engine/ktor/requests/meetings/MeetingsEngine.kt | 2 +- .../app/meetacy/sdk/engine/requests/EditMeetingRequest.kt | 2 +- .../app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt | 6 +++--- .../app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt | 4 ++-- .../kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt | 6 +++--- .../kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt | 4 ++-- .../sdk/types/serializable/meeting/MeetingSerializable.kt | 2 +- .../kotlin/app/meetacy/sdk/types/meeting/Meeting.kt | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 96a15163..65afc58a 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -172,7 +172,7 @@ internal class MeetingsEngine( private data class EditMeetingBody( val meetingId: MeetingIdSerializable, val title: OptionalSerializable, - val description: OptionalSerializable, + val description: OptionalSerializable, val location: OptionalSerializable, val date: OptionalSerializable, val avatarId: OptionalSerializable = OptionalSerializable.Undefined, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt index 229e07ba..7bf66f50 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/EditMeetingRequest.kt @@ -12,7 +12,7 @@ public data class EditMeetingRequest( public val token: Token, public val meetingId: MeetingId, public val title: Optional, - public val description: Optional, + public val description: Optional, public val location: Optional, public val date: Optional, public val avatarId: Optional, diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index 1a6b70d8..d7724c80 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -21,7 +21,7 @@ public class AuthorizedMeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String get() = data.title + public val title: String? get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants @@ -36,7 +36,7 @@ public class AuthorizedMeetingRepository( title: String, date: Date, location: Location, - description: String, + description: String?, avatarId: FileId?, visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edited( @@ -52,7 +52,7 @@ public class AuthorizedMeetingRepository( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt index e38611cd..5c37365c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -50,7 +50,7 @@ public class AuthorizedMeetingsApi( title: String, date: Date, location: Location, - description: String, + description: String?, avatarId: FileId?, visibility: Meeting.Visibility ): AuthorizedMeetingRepository = edit( @@ -68,7 +68,7 @@ public class AuthorizedMeetingsApi( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): AuthorizedMeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 840dd8c0..61cdc512 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -24,7 +24,7 @@ public class MeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String get() = data.title + public val title: String? get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants @@ -39,7 +39,7 @@ public class MeetingRepository( title: String, date: Date, location: Location, - description: String, + description: String?, avatarId: FileId?, visibility: Meeting.Visibility ): MeetingRepository = edited( @@ -57,7 +57,7 @@ public class MeetingRepository( title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): MeetingRepository { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt index 7ce912aa..d7506c61 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -56,7 +56,7 @@ public class MeetingsApi(private val api: MeetacyApi) { title: String, date: Date, location: Location, - description: String, + description: String?, avatarId: FileId?, visibility: Meeting.Visibility ): MeetingRepository = edit( @@ -76,7 +76,7 @@ public class MeetingsApi(private val api: MeetacyApi) { title: Optional = Optional.Undefined, date: Optional = Optional.Undefined, location: Optional = Optional.Undefined, - description: Optional = Optional.Undefined, + description: Optional = Optional.Undefined, avatarId: Optional = Optional.Undefined, visibility: Optional = Optional.Undefined ): MeetingRepository { diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 5dc2f304..38073888 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -22,7 +22,7 @@ public data class MeetingSerializable( val creator: UserSerializable, val date: DateSerializable, val location: LocationSerializable, - val title: String, + val title: String?, val description: String? = null, val participantsCount: Int, val previewParticipants: List, diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt index 7c3426c7..a21d3da2 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt @@ -15,7 +15,7 @@ public data class Meeting( val creator: User, val date: Date, val location: Location, - val title: String, + val title: String?, val description: String?, val participantsCount: Int, val previewParticipants: List, From 809318d412bbcdfe698fa9776f771c045c10976c Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 14:10:40 +0300 Subject: [PATCH 30/56] fix(#76-support-search): add default parameter in editmeetingbody --- .../engine/ktor/requests/meetings/MeetingsEngine.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 65afc58a..876701f6 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -171,12 +171,12 @@ internal class MeetingsEngine( @Serializable private data class EditMeetingBody( val meetingId: MeetingIdSerializable, - val title: OptionalSerializable, - val description: OptionalSerializable, - val location: OptionalSerializable, - val date: OptionalSerializable, + val title: OptionalSerializable = OptionalSerializable.Undefined, + val description: OptionalSerializable = OptionalSerializable.Undefined, + val location: OptionalSerializable = OptionalSerializable.Undefined, + val date: OptionalSerializable = OptionalSerializable.Undefined, val avatarId: OptionalSerializable = OptionalSerializable.Undefined, - val visibility: OptionalSerializable + val visibility: OptionalSerializable = OptionalSerializable.Undefined ) private fun EditMeetingRequest.toBody() = EditMeetingBody( From f9341424f10a1ffb45130c36c5b272336e3507b8 Mon Sep 17 00:00:00 2001 From: y9kap Date: Tue, 31 Oct 2023 14:28:49 +0300 Subject: [PATCH 31/56] fix(#76-support-search): remove nullability at title --- .../app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt | 2 +- .../kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt | 2 +- .../sdk/types/serializable/meeting/MeetingSerializable.kt | 2 +- .../commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt index d7724c80..456c330b 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -21,7 +21,7 @@ public class AuthorizedMeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String? get() = data.title + public val title: String get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt index 61cdc512..338aef6c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -24,7 +24,7 @@ public class MeetingRepository( public val creator: User get() = data.creator public val date: Date get() = data.date public val location: Location get() = data.location - public val title: String? get() = data.title + public val title: String get() = data.title public val description: String? get() = data.description public val participantsCount: Int get() = data.participantsCount public val previewParticipants: List get() = data.previewParticipants diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt index 38073888..5dc2f304 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/meeting/MeetingSerializable.kt @@ -22,7 +22,7 @@ public data class MeetingSerializable( val creator: UserSerializable, val date: DateSerializable, val location: LocationSerializable, - val title: String?, + val title: String, val description: String? = null, val participantsCount: Int, val previewParticipants: List, diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt index a21d3da2..7c3426c7 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/meeting/Meeting.kt @@ -15,7 +15,7 @@ public data class Meeting( val creator: User, val date: Date, val location: Location, - val title: String?, + val title: String, val description: String?, val participantsCount: Int, val previewParticipants: List, From 62695b76bc1b2027f297423180ec501b309e4f05 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Tue, 31 Oct 2023 19:27:56 +0300 Subject: [PATCH 32/56] fix: content negotiation json serialization installed --- api/api-ktor/build.gradle.kts | 1 + .../app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/api/api-ktor/build.gradle.kts b/api/api-ktor/build.gradle.kts index e4a35a28..1b2fef2b 100644 --- a/api/api-ktor/build.gradle.kts +++ b/api/api-ktor/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { commonMainImplementation(libs.ktorClientWebSockets) commonMainImplementation(libs.rsocketKtorClient) commonMainImplementation(libs.ktorClientContentNegotiation) + commonMainImplementation(libs.ktorSerializationJson) commonMainApi(projects.api) commonMainImplementation(projects.types.serializable) 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 4c035978..6f942b84 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 @@ -26,6 +26,7 @@ import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.http.* +import io.ktor.serialization.kotlinx.json.* import io.ktor.utils.io.errors.* import io.rsocket.kotlin.ktor.client.RSocketSupport import kotlinx.coroutines.CancellationException @@ -42,17 +43,14 @@ public class KtorMeetacyEngine( } private val httpClient = httpClient.config { - expectSuccess = true install(WebSockets) install(RSocketSupport) install(ContentNegotiation) { - Json(json) { - ignoreUnknownKeys = true - } + json(json) } defaultRequest { - header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) + header(HttpHeaders.ContentType, ContentType.Application.Json) } } From b3f310a133e645e10532a3bf993caa5f41a32898 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Tue, 31 Oct 2023 19:40:38 +0300 Subject: [PATCH 33/56] feat: added prerelease with a snapshot version --- .github/workflows/publish-snapshot.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index d980e35b..4f2add78 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -90,3 +90,18 @@ jobs: ./gradlew publishIosX64PublicationToMeetacySdkRepository \ publishIosSimulatorArm64PublicationToMeetacySdkRepository \ publishIosArm64PublicationToMeetacySdkRepository + + create-release: + runs-on: ubuntu-latest + needs: + - deploy-multiplatform + - deploy-jvm + - deploy-js + - deploy-konan + steps: + - name: Create Release + uses: actions/create-release@v1 + with: + tag_name: ${{ needs.deploy-multiplatform.outputs.snapshot_version }} + release_name: Build ${{ needs.deploy-multiplatform.outputs.snapshot_version }} + prerelease: true From b07de97f4caa1b4133607e8fb8bba5bd4fc0177d Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Tue, 31 Oct 2023 20:00:39 +0300 Subject: [PATCH 34/56] fix: added prerelease with a snapshot version --- .github/workflows/publish-snapshot.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index 4f2add78..d16c63b6 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -31,6 +31,9 @@ jobs: echo "snapshot_version=$snapshot_version" >> $GITHUB_ENV - name: Publish ${{ env.snapshot_version }} run: ./gradlew publishKotlinMultiplatformPublicationToMeetacySdkRepository + - name: Add Sdk Version to Output + id: output_version + run: echo "snapshot_version=${{ env.snapshot_version }}" >> $GITHUB_OUTPUT deploy-jvm: runs-on: ubuntu-latest From 65fae3b3ebdacfecf6a0667d292a1c5d9fe300f0 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Tue, 31 Oct 2023 20:12:18 +0300 Subject: [PATCH 35/56] fix: security vulnerability fixes, output fixes --- .github/workflows/publish-release.yml | 8 ++++---- .github/workflows/publish-snapshot.yml | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 263b5dc9..e9d8ac87 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Gradle Sync run: ./gradlew - name: Add Sdk Version to Env @@ -36,7 +36,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Gradle Sync run: ./gradlew - name: Add Sdk Version to Env @@ -51,7 +51,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Gradle Sync run: ./gradlew - name: Add Sdk Version to Env @@ -66,7 +66,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Konan Cache Setup uses: actions/cache@v3 with: diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index d16c63b6..e2690837 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -17,10 +17,12 @@ jobs: deploy-multiplatform: runs-on: ubuntu-latest + outputs: + release_version: ${{ steps.output_version.outputs.snapshot_version }} steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 with: cache-read-only: ${{ github.ref != 'refs/heads/dev' }} - name: Gradle Sync @@ -40,7 +42,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 with: cache-read-only: ${{ github.ref != 'refs/heads/dev' }} - name: Gradle Sync @@ -57,7 +59,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 with: cache-read-only: ${{ github.ref != 'refs/heads/dev' }} - name: Gradle Sync @@ -74,7 +76,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 with: cache-read-only: ${{ github.ref != 'refs/heads/dev' }} - name: Konan Cache Setup From 7b0804c19d1bc1016e8dee848d154cc6b14cb6cb Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Tue, 31 Oct 2023 20:22:17 +0300 Subject: [PATCH 36/56] fix: output fixes --- .github/workflows/publish-snapshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index e2690837..5c2496b2 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -18,7 +18,7 @@ jobs: deploy-multiplatform: runs-on: ubuntu-latest outputs: - release_version: ${{ steps.output_version.outputs.snapshot_version }} + snapshot_version: ${{ steps.output_version.outputs.snapshot_version }} steps: - uses: actions/checkout@v3 - name: Gradle Cache Setup From 6aad1c3cb0b7e6905953f3a97b6da083a98a4a37 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 08:56:25 +0300 Subject: [PATCH 37/56] fix: serializers fix --- .../kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt index bcc6a05a..7a299abb 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt @@ -11,13 +11,12 @@ import kotlinx.serialization.json.Json @Serializable(with = ServerResponse.Serializer::class) internal sealed interface ServerResponse { - @Serializable + data class Error( val errorCode: Int, val errorMessage: String ) : ServerResponse - @Serializable data class Success(val result: T) : ServerResponse @Suppress("UNCHECKED_CAST") @@ -64,5 +63,5 @@ internal fun Payload.decodeToServerResponse( } internal suspend inline fun HttpResponse.bodyAsSuccess(): T { - return body>().result + return (body>() as ServerResponse.Success).result } From 29cb47b8879f759af11787234852d954107c808e Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 09:09:40 +0300 Subject: [PATCH 38/56] fix: serializers --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 6 +----- .../kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) 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 6f942b84..192f54ee 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 @@ -35,13 +35,9 @@ import kotlinx.serialization.json.Json public class KtorMeetacyEngine( private val baseUrl: Url, httpClient: HttpClient = HttpClient(), - json: Json = Json, + private val json: Json = Json, ) : MeetacyRequestsEngine { - private val json = Json(json) { - ignoreUnknownKeys = true - } - private val httpClient = httpClient.config { expectSuccess = true install(WebSockets) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt index 7a299abb..719b34af 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/Response.kt @@ -27,7 +27,7 @@ internal sealed interface ServerResponse { override fun deserialize(decoder: Decoder): ServerResponse { val data = baseSerializer.deserialize(decoder) return if (data.status) { - Success(data.data as T) + Success(data.result as T) } else { Error(data.errorCode!!, data.errorMessage!!) } @@ -36,7 +36,7 @@ internal sealed interface ServerResponse { override fun serialize(encoder: Encoder, value: ServerResponse) { val data = Data( status = value is Success, - data = (value as? Success)?.result, + result = (value as? Success)?.result, errorCode = (value as? Error)?.errorCode, errorMessage = (value as? Error)?.errorMessage ) @@ -46,7 +46,7 @@ internal sealed interface ServerResponse { @Serializable private data class Data( val status: Boolean, - val data: T? = null, + val result: T? = null, val errorCode: Int? = null, val errorMessage: String? = null ) From 2d554a987d103a0fa17eb41753cc266a3b23517b Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 09:14:49 +0300 Subject: [PATCH 39/56] fix: added ignoreUnknownKeys for future releases --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 192f54ee..6f942b84 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 @@ -35,9 +35,13 @@ import kotlinx.serialization.json.Json public class KtorMeetacyEngine( private val baseUrl: Url, httpClient: HttpClient = HttpClient(), - private val json: Json = Json, + json: Json = Json, ) : MeetacyRequestsEngine { + private val json = Json(json) { + ignoreUnknownKeys = true + } + private val httpClient = httpClient.config { expectSuccess = true install(WebSockets) From 47f4b77f53c7955e96d9198797ce58def34c0ff5 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 09:24:15 +0300 Subject: [PATCH 40/56] fix: exceptions handling --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6f942b84..ba6b9032 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 @@ -119,7 +119,7 @@ public class KtorMeetacyEngine( block() } catch (exception: ResponseException) { val response = try { - json.decodeFromString(exception.response.body()) + json.decodeFromString>(exception.response.body()) as ServerResponse.Error } catch (exception: Throwable) { throw MeetacyInternalException(cause = exception) } From 732550c7cc7a9d033df1fca5fc0653047d15a138 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 09:54:06 +0300 Subject: [PATCH 41/56] fix: content-type now is not specified when making websocket connection --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 ba6b9032..82c4a6a8 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 @@ -50,7 +50,9 @@ public class KtorMeetacyEngine( json(json) } defaultRequest { - header(HttpHeaders.ContentType, ContentType.Application.Json) + if (!url.protocol.isWebsocket()) { + header(HttpHeaders.ContentType, ContentType.Application.Json) + } } } From 15767112e945ddf57a9cf7202486b437009831f7 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 10:07:49 +0300 Subject: [PATCH 42/56] debug: added print to default request --- .../kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 1 + 1 file changed, 1 insertion(+) 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 82c4a6a8..d3381dd4 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 @@ -50,6 +50,7 @@ public class KtorMeetacyEngine( json(json) } defaultRequest { + println("ca62: ${url.protocol}: isWebsocket = ${url.protocol.isWebsocket()}") if (!url.protocol.isWebsocket()) { header(HttpHeaders.ContentType, ContentType.Application.Json) } From 7ea715b1b3acb4660340d6d34ff8d2a0ebe1794f Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 10:33:14 +0300 Subject: [PATCH 43/56] fix: explicitly remove Content-Type header when making RSocket requests --- .../meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt | 5 +---- .../app/meetacy/sdk/engine/ktor/RSocket.kt | 16 ++++++++++++++++ .../ktor/requests/friends/FriendsEngine.kt | 3 ++- .../ktor/requests/updates/UpdatesEngine.kt | 3 ++- 4 files changed, 21 insertions(+), 6 deletions(-) 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 d3381dd4..ba6b9032 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 @@ -50,10 +50,7 @@ public class KtorMeetacyEngine( json(json) } defaultRequest { - println("ca62: ${url.protocol}: isWebsocket = ${url.protocol.isWebsocket()}") - if (!url.protocol.isWebsocket()) { - header(HttpHeaders.ContentType, ContentType.Application.Json) - } + header(HttpHeaders.ContentType, ContentType.Application.Json) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt index 11f6cf5d..b18e8bde 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt @@ -5,8 +5,12 @@ import app.meetacy.sdk.engine.ktor.response.ServerResponse import app.meetacy.sdk.exception.MeetacyConnectionException import app.meetacy.sdk.exception.MeetacyInternalException import app.meetacy.sdk.exception.meetacyApiError +import io.ktor.client.* +import io.ktor.http.* import io.ktor.utils.io.errors.* +import io.rsocket.kotlin.RSocket import io.rsocket.kotlin.RSocketError +import io.rsocket.kotlin.ktor.client.rSocket import kotlinx.coroutines.CancellationException import kotlinx.serialization.json.Json @@ -37,3 +41,15 @@ internal inline fun handleRSocketExceptions( } } } + +internal suspend fun HttpClient.meetacyRSocket( + urlString: String, + secure: Boolean +): RSocket { + return rSocket( + urlString = urlString, + secure = secure + ) { + headers.remove(HttpHeaders.ContentType) + } +} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 9f26a82d..29b4e9bb 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -4,6 +4,7 @@ package app.meetacy.sdk.engine.ktor.requests.friends import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.handleRSocketExceptions +import app.meetacy.sdk.engine.ktor.meetacyRSocket import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess @@ -109,7 +110,7 @@ internal class FriendsEngine( suspend fun streamFriendsLocation(request: EmitFriendsLocationRequest) = handleRSocketExceptions(json) { val url = baseUrl.replaceProtocolWithWebsocket() / "location" / "stream" - val socket = httpClient.rSocket( + val socket = httpClient.meetacyRSocket( urlString = url.string, secure = url.protocol.isWss ) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt index aa2df3b7..0d020c80 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt @@ -1,6 +1,7 @@ package app.meetacy.sdk.engine.ktor.requests.updates import app.meetacy.sdk.engine.ktor.handleRSocketExceptions +import app.meetacy.sdk.engine.ktor.meetacyRSocket import app.meetacy.sdk.engine.requests.EmitUpdatesRequest import app.meetacy.sdk.types.serializable.notification.NotificationSerializable import app.meetacy.sdk.types.serializable.notification.type @@ -29,7 +30,7 @@ internal class UpdatesEngine( suspend fun stream(request: EmitUpdatesRequest) = handleRSocketExceptions(json) { val url = baseUrl.replaceProtocolWithWebsocket() / "updates" / "stream" - val socket = httpClient.rSocket( + val socket = httpClient.meetacyRSocket( urlString = url.string, secure = url.protocol.isWss ) From efca797beb481ce0b4a1283ca0bf0c9f72af20e8 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 10:59:10 +0300 Subject: [PATCH 44/56] fix: different clients for rsocket and http requests --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 63 +++++++++++++++---- .../app/meetacy/sdk/engine/ktor/RSocket.kt | 12 ---- .../ktor/requests/friends/FriendsEngine.kt | 3 +- .../ktor/requests/updates/UpdatesEngine.kt | 5 +- 4 files changed, 56 insertions(+), 27 deletions(-) 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 ba6b9032..bcffce8f 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 @@ -44,8 +44,6 @@ public class KtorMeetacyEngine( private val httpClient = httpClient.config { expectSuccess = true - install(WebSockets) - install(RSocketSupport) install(ContentNegotiation) { json(json) } @@ -53,16 +51,59 @@ public class KtorMeetacyEngine( header(HttpHeaders.ContentType, ContentType.Application.Json) } } + private val rsocketClient = httpClient.config { + expectSuccess = true + install(WebSockets) + install(RSocketSupport) + } + + private val auth = AuthEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val users = UsersEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val friends = FriendsEngine( + baseUrl = baseUrl, + httpClient = this.httpClient, + rsocketClient = rsocketClient, + json = this.json + ) + + private val meetings = MeetingsEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val files = FilesEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val invitations = InvitationsEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val notifications = NotificationsEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) + + private val search = SearchEngine( + baseUrl = baseUrl, + httpClient = this.httpClient + ) - private val auth = AuthEngine(baseUrl, this.httpClient) - private val users = UsersEngine(baseUrl, this.httpClient) - private val friends = FriendsEngine(baseUrl, this.httpClient, this.json) - private val meetings = MeetingsEngine(baseUrl, this.httpClient) - private val files = FilesEngine(baseUrl, this.httpClient) - private val invitations = InvitationsEngine(baseUrl, this.httpClient) - private val notifications = NotificationsEngine(baseUrl, this.httpClient) - private val search = SearchEngine(baseUrl, this.httpClient) - private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json) + private val updates = UpdatesEngine( + baseUrl = baseUrl, + rsocketClient = rsocketClient, + json = this.json + ) override fun getFileUrl( id: FileId diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt index b18e8bde..ae2c80fe 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt @@ -41,15 +41,3 @@ internal inline fun handleRSocketExceptions( } } } - -internal suspend fun HttpClient.meetacyRSocket( - urlString: String, - secure: Boolean -): RSocket { - return rSocket( - urlString = urlString, - secure = secure - ) { - headers.remove(HttpHeaders.ContentType) - } -} diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 29b4e9bb..e1e45b36 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -49,6 +49,7 @@ import kotlinx.serialization.json.put internal class FriendsEngine( baseUrl: Url, private val httpClient: HttpClient, + private val rsocketClient: HttpClient, private val json: Json ) { private val baseUrl = baseUrl / "friends" @@ -110,7 +111,7 @@ internal class FriendsEngine( suspend fun streamFriendsLocation(request: EmitFriendsLocationRequest) = handleRSocketExceptions(json) { val url = baseUrl.replaceProtocolWithWebsocket() / "location" / "stream" - val socket = httpClient.meetacyRSocket( + val socket = rsocketClient.rSocket( urlString = url.string, secure = url.protocol.isWss ) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt index 0d020c80..e8511a4f 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt @@ -1,7 +1,6 @@ package app.meetacy.sdk.engine.ktor.requests.updates import app.meetacy.sdk.engine.ktor.handleRSocketExceptions -import app.meetacy.sdk.engine.ktor.meetacyRSocket import app.meetacy.sdk.engine.requests.EmitUpdatesRequest import app.meetacy.sdk.types.serializable.notification.NotificationSerializable import app.meetacy.sdk.types.serializable.notification.type @@ -24,13 +23,13 @@ import kotlinx.serialization.json.put internal class UpdatesEngine( private val baseUrl: Url, - private val httpClient: HttpClient, + private val rsocketClient: HttpClient, private val json: Json ) { suspend fun stream(request: EmitUpdatesRequest) = handleRSocketExceptions(json) { val url = baseUrl.replaceProtocolWithWebsocket() / "updates" / "stream" - val socket = httpClient.meetacyRSocket( + val socket = rsocketClient.rSocket( urlString = url.string, secure = url.protocol.isWss ) From 17ada8416073b63fd275945f962b4d1e3cc812a1 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 11:29:08 +0300 Subject: [PATCH 45/56] fix: invalid import --- .../meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index e1e45b36..0852bae7 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -4,7 +4,6 @@ package app.meetacy.sdk.engine.ktor.requests.friends import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.handleRSocketExceptions -import app.meetacy.sdk.engine.ktor.meetacyRSocket import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess From 491f6f08cd82bb7d65c9b8956eae993965d60c9a Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 12:06:33 +0300 Subject: [PATCH 46/56] refactor: Removed redundant responses --- .../ktor/requests/friends/FriendsEngine.kt | 17 +++--- .../ktor/requests/meetings/MeetingsEngine.kt | 54 ++++++++----------- .../notifications/NotificationsEngine.kt | 18 +++---- .../ktor/response/ListFriendsResponse.kt | 13 ----- .../ListMeetingParticipantsResponse.kt | 13 ----- .../ktor/response/ListMeetingsResponse.kt | 13 ----- .../ktor/response/ListNotificationResponse.kt | 13 ----- .../engine/ktor/response/SimpleResponse.kt | 6 +-- .../paging/PagingIdSerializable.kt | 5 +- .../paging/PagingResponseSerializable.kt | 15 ++++++ 10 files changed, 58 insertions(+), 109 deletions(-) delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt delete mode 100644 api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt create mode 100644 types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 0852bae7..0d054599 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -4,7 +4,6 @@ package app.meetacy.sdk.engine.ktor.requests.friends import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.handleRSocketExceptions -import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token @@ -15,14 +14,14 @@ import app.meetacy.sdk.engine.requests.ListFriendsRequest import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.location.Location -import app.meetacy.sdk.types.paging.PagingId -import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.location.LocationSerializable import app.meetacy.sdk.types.serializable.location.type import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable +import app.meetacy.sdk.types.serializable.paging.type import app.meetacy.sdk.types.serializable.user.UserIdSerializable import app.meetacy.sdk.types.serializable.user.UserSerializable import app.meetacy.sdk.types.serializable.user.serializable @@ -93,18 +92,16 @@ internal class FriendsEngine( suspend fun list(request: ListFriendsRequest): ListFriendsRequest.Response { val url = baseUrl / "list" val body = request.toBody() + val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() - - val paging = PagingResponse( - nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map { user -> user.type() as RegularUser } - ) + }.bodyAsSuccess>() + .type() + .mapItems { user -> user.type() as RegularUser } - return ListFriendsRequest.Response(paging) + return ListFriendsRequest.Response(response) } suspend fun streamFriendsLocation(request: EmitFriendsLocationRequest) = handleRSocketExceptions(json) { diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 876701f6..d8d3ec27 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -1,15 +1,12 @@ package app.meetacy.sdk.engine.ktor.requests.meetings import app.meetacy.sdk.engine.ktor.apiVersion -import app.meetacy.sdk.engine.ktor.response.ListMeetingParticipantsResponse -import app.meetacy.sdk.engine.ktor.response.ListMeetingsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.types.optional.map -import app.meetacy.sdk.types.paging.PagingId -import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.datetime.DateSerializable @@ -26,6 +23,8 @@ import app.meetacy.sdk.types.serializable.optional.OptionalSerializable import app.meetacy.sdk.types.serializable.optional.serializable import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable +import app.meetacy.sdk.types.serializable.paging.type +import app.meetacy.sdk.types.serializable.user.UserSerializable import app.meetacy.sdk.types.serializable.user.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* @@ -54,17 +53,16 @@ internal class MeetingsEngine( ): ListMeetingsHistoryRequest.Response { val url = baseUrl / "history" / "list" val body = request.toBody() + val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.bodyAsSuccess>() + .type() + .mapItems { meeting -> meeting.type() } - val paging = PagingResponse( - nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map { meeting -> meeting.type() } - ) - return ListMeetingsHistoryRequest.Response(paging) + return ListMeetingsHistoryRequest.Response(response) } private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody( @@ -77,18 +75,16 @@ internal class MeetingsEngine( ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" val body = request.toBody() + val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.bodyAsSuccess>() + .type() + .mapItems { meeting -> meeting.type() } - val paging = PagingResponse( - nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map { meeting -> meeting.type() } - ) - - return ListActiveMeetingsRequest.Response(paging) + return ListActiveMeetingsRequest.Response(response) } private fun ListPastMeetingsRequest.toBody() = ListMeetingsPagingBody( @@ -101,18 +97,16 @@ internal class MeetingsEngine( ): ListPastMeetingsRequest.Response { val url = baseUrl / "history" / "past" val body = request.toBody() + val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() + }.bodyAsSuccess>() + .type() + .mapItems { meeting -> meeting.type() } - val paging = PagingResponse( - nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map { meeting -> meeting.type() } - ) - - return ListPastMeetingsRequest.Response(paging) + return ListPastMeetingsRequest.Response(response) } @Serializable @@ -218,18 +212,16 @@ internal class MeetingsEngine( ): ListMeetingParticipantsRequest.Response { val url = baseUrl / "participants" / "list" val body = request.toBody() + val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() - - val paging = PagingResponse( - data = response.data.map { it.type() }, - nextPagingId = response.nextPagingId?.let(::PagingId) - ) + }.bodyAsSuccess>() + .type() + .mapItems { meeting -> meeting.type() } - return ListMeetingParticipantsRequest.Response(paging) + return ListMeetingParticipantsRequest.Response(response) } @Serializable diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index b0a533e1..22ba9c7f 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -1,21 +1,21 @@ package app.meetacy.sdk.engine.ktor.requests.notifications import app.meetacy.sdk.engine.ktor.apiVersion -import app.meetacy.sdk.engine.ktor.response.ListNotificationsResponse import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.ListNotificationsRequest import app.meetacy.sdk.engine.requests.ReadNotificationRequest -import app.meetacy.sdk.types.paging.PagingId -import app.meetacy.sdk.types.paging.PagingResponse +import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.notification.NotificationIdSerializable +import app.meetacy.sdk.types.serializable.notification.NotificationSerializable import app.meetacy.sdk.types.serializable.notification.serializable import app.meetacy.sdk.types.serializable.notification.type import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable +import app.meetacy.sdk.types.serializable.paging.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.call.* @@ -40,18 +40,16 @@ internal class NotificationsEngine( ): ListNotificationsRequest.Response { val url = baseUrl / "list" val body = request.toBody() + val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) setBody(body) - }.bodyAsSuccess() - - val paging = PagingResponse( - data = response.data.map { it.type() }, - nextPagingId = response.nextPagingId?.let(::PagingId) - ) + }.bodyAsSuccess>() + .type() + .mapItems { notification -> notification.type() } - return ListNotificationsRequest.Response(paging) + return ListNotificationsRequest.Response(response) } @Serializable diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt deleted file mode 100644 index 9e23de4b..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListFriendsResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response - -import app.meetacy.sdk.types.serializable.user.UserSerializable -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class ListFriendsResponse ( - @SerialName("data") - val data: List, - @SerialName("nextPagingId") - val nextPagingId: String? = null -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt deleted file mode 100644 index 363d52ef..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingParticipantsResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response - -import app.meetacy.sdk.types.serializable.user.UserSerializable -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class ListMeetingParticipantsResponse ( - @SerialName("data") - val data: List, - @SerialName("nextPagingId") - val nextPagingId: String? = null -) \ No newline at end of file diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt deleted file mode 100644 index ff2aadd3..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListMeetingsResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response - -import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class ListMeetingsResponse ( - @SerialName("data") - val data: List, - @SerialName("nextPagingId") - val nextPagingId: String? = null -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt deleted file mode 100644 index f2792c30..00000000 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/ListNotificationResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.meetacy.sdk.engine.ktor.response - -import app.meetacy.sdk.types.serializable.notification.NotificationSerializable -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -internal data class ListNotificationsResponse ( - @SerialName("data") - val data: List, - @SerialName("nextPagingId") - val nextPagingId: String? = null -) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt index d1f964a7..87bf403b 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/response/SimpleResponse.kt @@ -4,9 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -internal data class StatusTrueResponse ( - +internal data class StatusTrueResponse( @SerialName("status") val status: Boolean - -) \ No newline at end of file +) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt index b7d56e3f..5c4a7a88 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingIdSerializable.kt @@ -1,5 +1,6 @@ package app.meetacy.sdk.types.serializable.paging +import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.paging.PagingId import kotlinx.serialization.Serializable import kotlin.jvm.JvmInline @@ -8,6 +9,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class PagingIdSerializable(public val string: String) +@OptIn(UnsafeConstructor::class) public fun PagingIdSerializable.type(): PagingId = PagingId(string) - -public fun PagingId.serializable(): PagingIdSerializable = PagingIdSerializable(string) \ No newline at end of file +public fun PagingId.serializable(): PagingIdSerializable = PagingIdSerializable(string) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt new file mode 100644 index 00000000..23008845 --- /dev/null +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt @@ -0,0 +1,15 @@ +package app.meetacy.sdk.types.serializable.paging + +import app.meetacy.sdk.types.paging.PagingResponse +import kotlinx.serialization.Serializable + +@Serializable +public data class PagingResponseSerializable( + val data: List, + val nextPagingId: PagingIdSerializable? +) + +public fun PagingResponseSerializable.type(): PagingResponse = + PagingResponse(data, nextPagingId?.type()) +public fun PagingResponse.serializable(): PagingResponseSerializable = + PagingResponseSerializable(data, nextPagingId?.serializable()) From 151ec137d903509a61324a1fecbe535d8bb8ebf9 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 12:15:47 +0300 Subject: [PATCH 47/56] fix: added default for nextPagingId --- .../sdk/types/serializable/paging/PagingResponseSerializable.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt index 23008845..c5ff2bf7 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/paging/PagingResponseSerializable.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable @Serializable public data class PagingResponseSerializable( val data: List, - val nextPagingId: PagingIdSerializable? + val nextPagingId: PagingIdSerializable? = null ) public fun PagingResponseSerializable.type(): PagingResponse = From a468dabbfdeadfc3cbeac55f67f0a626590ad7c0 Mon Sep 17 00:00:00 2001 From: Alex Sokol / y9san9 Date: Wed, 1 Nov 2023 12:27:16 +0300 Subject: [PATCH 48/56] fix: rsocket serialization --- .../commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt index ae2c80fe..6bcd740d 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/RSocket.kt @@ -23,9 +23,9 @@ internal inline fun handleRSocketExceptions( } catch (exception: RSocketError) { when (exception) { is RSocketError.Custom -> { - val response = json.decodeFromString( + val response = json.decodeFromString>( string = exception.message ?: meetacyApiError(message = "Message should be present when throwing custom error") - ) + ) as ServerResponse.Error throw getException(response) } else -> { From 6ab68a7174d6b6561b1674661686c3952e8b2c04 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Fri, 3 Nov 2023 02:19:32 +0300 Subject: [PATCH 49/56] feat(#79-support-search): support search was added --- .../app/meetacy/sdk/AuthorizedMeetacyApi.kt | 5 ++ .../kotlin/app/meetacy/sdk/MeetacyApi.kt | 19 ++++++ .../search/AuthorizedSearchItemRepository.kt | 58 +++++++++++++++++++ .../sdk/search/SearchItemRepository.kt | 50 ++++++++++++++++ .../meetacy/sdk/types/search/SearchItem.kt | 6 ++ 5 files changed, 138 insertions(+) create mode 100644 api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt create mode 100644 api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt index c91e4370..771d034a 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt @@ -5,8 +5,10 @@ import app.meetacy.sdk.friends.AuthorizedFriendsApi import app.meetacy.sdk.invitations.AuthorizedInvitationsApi import app.meetacy.sdk.meetings.AuthorizedMeetingsApi import app.meetacy.sdk.notifications.AuthorizedNotificationsApi +import app.meetacy.sdk.search.AuthorizedSearchItemRepository import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.updates.AuthorizedUpdatesApi import app.meetacy.sdk.users.AuthorizedSelfUserRepository import app.meetacy.sdk.users.AuthorizedUsersApi @@ -38,4 +40,7 @@ public class AuthorizedMeetacyApi @UnsafeConstructor constructor( data = base.getMe(token), api = this ) + public suspend fun search(location: Location, prompt: String): List = + base.search(token, location, prompt).map { AuthorizedSearchItemRepository.of(it.data, api = this) } + } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt index f7d3538a..6c0b0642 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt @@ -3,13 +3,16 @@ package app.meetacy.sdk import app.meetacy.sdk.auth.AuthApi import app.meetacy.sdk.engine.MeetacyRequestsEngine import app.meetacy.sdk.engine.requests.GetMeRequest +import app.meetacy.sdk.engine.requests.SearchRequest import app.meetacy.sdk.files.FilesApi import app.meetacy.sdk.friends.FriendsApi import app.meetacy.sdk.invitations.InvitationsApi import app.meetacy.sdk.meetings.MeetingsApi import app.meetacy.sdk.notifications.NotificationsApi +import app.meetacy.sdk.search.SearchItemRepository import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.user.SelfUser import app.meetacy.sdk.updates.UpdatesApi import app.meetacy.sdk.users.UsersApi @@ -30,10 +33,26 @@ public class MeetacyApi( return engine.execute(GetMeRequest(token)).me } + public suspend fun search( + token: Token, + location: Location, + prompt: String + ): List { + return engine.execute( + request = SearchRequest( + token, location, prompt + ) + ).items.map { searchItem -> + SearchItemRepository.of(searchItem, api = this) + } + } + @OptIn(UnsafeConstructor::class) public fun authorized(token: Token): AuthorizedMeetacyApi { return AuthorizedMeetacyApi(token, base = this) } + + public companion object } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt new file mode 100644 index 00000000..080f898d --- /dev/null +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt @@ -0,0 +1,58 @@ +package app.meetacy.sdk.search + +import app.meetacy.sdk.AuthorizedMeetacyApi +import app.meetacy.sdk.meetings.AuthorizedMeetingRepository +import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.search.SearchItem +import app.meetacy.sdk.users.AuthorizedUserRepository +import app.meetacy.sdk.types.place.Place as PlaceData + +public sealed class AuthorizedSearchItemRepository { + protected abstract val api: AuthorizedMeetacyApi + public abstract val data: SearchItem + public abstract val base: SearchItemRepository + + public val token: Token get() = api.token + + public class Meeting( + override val data: SearchItem.Meeting, + override val api: AuthorizedMeetacyApi + ) : AuthorizedSearchItemRepository() { + override val base: SearchItemRepository + get() = SearchItemRepository.Meeting(data, api.base) + public val meeting: AuthorizedMeetingRepository + get() = AuthorizedMeetingRepository(data.meeting, api) + } + + public class Place( + override val data: SearchItem.Place, + override val api: AuthorizedMeetacyApi + ) : AuthorizedSearchItemRepository() { + override val base: SearchItemRepository + get() = SearchItemRepository.Place(data) + + public val place: PlaceData + get() = data.place + } + + public class User( + override val data: SearchItem.User, + override val api: AuthorizedMeetacyApi + ) : AuthorizedSearchItemRepository() { + + override val base: SearchItemRepository + get() = SearchItemRepository.User(data, api.base) + public val user: AuthorizedUserRepository + get() = AuthorizedUserRepository.of(data.user, api) + } + + public companion object { + public fun of(data: SearchItem, api: AuthorizedMeetacyApi): AuthorizedSearchItemRepository = + when (data) { + is SearchItem.Meeting -> Meeting(data, api) + is SearchItem.Place -> Place(data, api) + is SearchItem.User -> User(data, api) + } + + } +} diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt new file mode 100644 index 00000000..3abce628 --- /dev/null +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt @@ -0,0 +1,50 @@ +package app.meetacy.sdk.search + +import app.meetacy.sdk.MeetacyApi +import app.meetacy.sdk.meetings.AuthorizedMeetingRepository +import app.meetacy.sdk.meetings.MeetingRepository +import app.meetacy.sdk.types.place.Place as PlaceData +import app.meetacy.sdk.types.search.SearchItem +import app.meetacy.sdk.users.UserRepository + +/** + * When modifying this class, corresponding classes should be altered: + * - [AuthorizedMeetingRepository] + */ + +public sealed class SearchItemRepository { + public abstract val data: SearchItem + + public class Meeting( + override val data: SearchItem.Meeting, + private val api: MeetacyApi + ) : SearchItemRepository() { + public val meeting: MeetingRepository + get() = MeetingRepository(data.meeting, api) + } + + public class Place( + override val data: SearchItem.Place + ) : SearchItemRepository() { + public val place: PlaceData + get() = data.place + } + + public class User( + override val data: SearchItem.User, + private val api: MeetacyApi + ) : SearchItemRepository() { + public val user: UserRepository + get() = UserRepository.of(data.user, api) + } + + public companion object { + public fun of(data: SearchItem, api: MeetacyApi): SearchItemRepository { + return when (data) { + is SearchItem.Meeting -> Meeting(data, api) + is SearchItem.Place -> Place(data) + is SearchItem.User -> User(data, api) + } + } + } +} diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt index 8f45fa8c..a6f194ce 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt @@ -4,6 +4,12 @@ import app.meetacy.sdk.types.meeting.Meeting as MeetingView import app.meetacy.sdk.types.place.Place as PlaceView import app.meetacy.sdk.types.user.User as UserView +/** + * When modifying this class, corresponding classes should be altered: + * - [app.meetacy.sdk.search.SearchItemRepository] + * - [app.meetacy.sdk.search.AuthorizedSearchItemRepository] + */ + public sealed interface SearchItem { public class Meeting(public val meeting: MeetingView) : SearchItem public class User(public val user: UserView) : SearchItem From cf364a5757c800cf4bef17550aba7a8207e92dda Mon Sep 17 00:00:00 2001 From: y9kap Date: Fri, 3 Nov 2023 11:39:27 +0300 Subject: [PATCH 50/56] fix(#76-support-search): some fixes --- .../kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt | 1 + .../commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt | 2 -- .../sdk/search/AuthorizedSearchItemRepository.kt | 10 +++------- .../app/meetacy/sdk/search/SearchItemRepository.kt | 3 +-- .../kotlin/app/meetacy/sdk/types/search/SearchItem.kt | 1 - 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt index 771d034a..23f6a20c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt @@ -40,6 +40,7 @@ public class AuthorizedMeetacyApi @UnsafeConstructor constructor( data = base.getMe(token), api = this ) + public suspend fun search(location: Location, prompt: String): List = base.search(token, location, prompt).map { AuthorizedSearchItemRepository.of(it.data, api = this) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt index 6c0b0642..2fe76e01 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt @@ -52,7 +52,5 @@ public class MeetacyApi( return AuthorizedMeetacyApi(token, base = this) } - - public companion object } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt index 080f898d..c98f6b4b 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt @@ -2,21 +2,17 @@ package app.meetacy.sdk.search import app.meetacy.sdk.AuthorizedMeetacyApi import app.meetacy.sdk.meetings.AuthorizedMeetingRepository -import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.search.SearchItem import app.meetacy.sdk.users.AuthorizedUserRepository import app.meetacy.sdk.types.place.Place as PlaceData public sealed class AuthorizedSearchItemRepository { - protected abstract val api: AuthorizedMeetacyApi public abstract val data: SearchItem public abstract val base: SearchItemRepository - public val token: Token get() = api.token - public class Meeting( override val data: SearchItem.Meeting, - override val api: AuthorizedMeetacyApi + public val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository get() = SearchItemRepository.Meeting(data, api.base) @@ -26,7 +22,7 @@ public sealed class AuthorizedSearchItemRepository { public class Place( override val data: SearchItem.Place, - override val api: AuthorizedMeetacyApi + public val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository get() = SearchItemRepository.Place(data) @@ -37,7 +33,7 @@ public sealed class AuthorizedSearchItemRepository { public class User( override val data: SearchItem.User, - override val api: AuthorizedMeetacyApi + public val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt index 3abce628..62bd4b1c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt @@ -3,15 +3,14 @@ package app.meetacy.sdk.search import app.meetacy.sdk.MeetacyApi import app.meetacy.sdk.meetings.AuthorizedMeetingRepository import app.meetacy.sdk.meetings.MeetingRepository -import app.meetacy.sdk.types.place.Place as PlaceData import app.meetacy.sdk.types.search.SearchItem import app.meetacy.sdk.users.UserRepository +import app.meetacy.sdk.types.place.Place as PlaceData /** * When modifying this class, corresponding classes should be altered: * - [AuthorizedMeetingRepository] */ - public sealed class SearchItemRepository { public abstract val data: SearchItem diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt index a6f194ce..4cd02947 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt @@ -9,7 +9,6 @@ import app.meetacy.sdk.types.user.User as UserView * - [app.meetacy.sdk.search.SearchItemRepository] * - [app.meetacy.sdk.search.AuthorizedSearchItemRepository] */ - public sealed interface SearchItem { public class Meeting(public val meeting: MeetingView) : SearchItem public class User(public val user: UserView) : SearchItem From 9e01d49c762d2e54e4774cfbc92bd69c5a4e52d8 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 00:27:24 +0300 Subject: [PATCH 51/56] fix(#79-support-search): setBody remove at get requests --- .../engine/ktor/requests/meetings/MeetingsEngine.kt | 12 +++--------- .../sdk/engine/ktor/requests/search/SearchEngine.kt | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index d8d3ec27..30ea2504 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -6,7 +6,6 @@ import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.types.optional.map -import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.datetime.DateSerializable @@ -22,6 +21,7 @@ import app.meetacy.sdk.types.serializable.meeting.type import app.meetacy.sdk.types.serializable.optional.OptionalSerializable import app.meetacy.sdk.types.serializable.optional.serializable import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable +import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.serializable.paging.type import app.meetacy.sdk.types.serializable.user.UserSerializable @@ -65,21 +65,15 @@ internal class MeetingsEngine( return ListMeetingsHistoryRequest.Response(response) } - private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody( - amount.serializable(), - pagingId?.serializable() - ) - suspend fun listActiveMeetings( request: ListActiveMeetingsRequest ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" - val body = request.toBody() - val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("amount", request.amount) + parameter("pagingId", request.pagingId) }.bodyAsSuccess>() .type() .mapItems { meeting -> meeting.type() } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt index 1c8e580b..f80611a0 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -4,14 +4,11 @@ import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.SearchRequest -import app.meetacy.sdk.types.serializable.location.LocationSerializable -import app.meetacy.sdk.types.serializable.location.serializable import app.meetacy.sdk.types.serializable.search.SearchItemSerializable import app.meetacy.sdk.types.serializable.search.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* -import kotlinx.serialization.Serializable internal class SearchEngine( baseUrl: Url, @@ -19,16 +16,13 @@ internal class SearchEngine( ) { val baseUrl: Url = baseUrl / "search" - @Serializable - private data class SearchBody(val location: LocationSerializable, val promt: String) - private fun SearchRequest.toBody() = SearchBody(location.serializable(), prompt) - suspend fun search(request: SearchRequest): SearchRequest.Response { - val body = request.toBody() val response = httpClient.get(baseUrl.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("latitude", request.location.latitude) + parameter("longitude", request.location.longitude) + parameter("prompt", request.prompt) }.bodyAsSuccess>() return SearchRequest.Response(response.map { it.type() }) } From d642beae470d7cfbc00866f9bbd5cba901288c4d Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 00:27:24 +0300 Subject: [PATCH 52/56] fix(#79-support-search): setBody remove at get requests --- .../ktor/requests/meetings/MeetingsEngine.kt | 21 +++++-------------- .../ktor/requests/search/SearchEngine.kt | 12 +++-------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index d8d3ec27..5f7fa84d 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -6,7 +6,6 @@ import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.types.optional.map -import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.datetime.DateSerializable @@ -22,6 +21,7 @@ import app.meetacy.sdk.types.serializable.meeting.type import app.meetacy.sdk.types.serializable.optional.OptionalSerializable import app.meetacy.sdk.types.serializable.optional.serializable import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable +import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.paging.serializable import app.meetacy.sdk.types.serializable.paging.type import app.meetacy.sdk.types.serializable.user.UserSerializable @@ -65,21 +65,15 @@ internal class MeetingsEngine( return ListMeetingsHistoryRequest.Response(response) } - private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody( - amount.serializable(), - pagingId?.serializable() - ) - suspend fun listActiveMeetings( request: ListActiveMeetingsRequest ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" - val body = request.toBody() - val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("amount", request.amount) + parameter("pagingId", request.pagingId) }.bodyAsSuccess>() .type() .mapItems { meeting -> meeting.type() } @@ -87,21 +81,16 @@ internal class MeetingsEngine( return ListActiveMeetingsRequest.Response(response) } - private fun ListPastMeetingsRequest.toBody() = ListMeetingsPagingBody( - amount.serializable(), - pagingId?.serializable() - ) - suspend fun listPastMeetings( request: ListPastMeetingsRequest ): ListPastMeetingsRequest.Response { val url = baseUrl / "history" / "past" - val body = request.toBody() val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("amount", request.amount) + parameter("pagingId", request.pagingId) }.bodyAsSuccess>() .type() .mapItems { meeting -> meeting.type() } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt index 1c8e580b..f80611a0 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -4,14 +4,11 @@ import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.SearchRequest -import app.meetacy.sdk.types.serializable.location.LocationSerializable -import app.meetacy.sdk.types.serializable.location.serializable import app.meetacy.sdk.types.serializable.search.SearchItemSerializable import app.meetacy.sdk.types.serializable.search.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* -import kotlinx.serialization.Serializable internal class SearchEngine( baseUrl: Url, @@ -19,16 +16,13 @@ internal class SearchEngine( ) { val baseUrl: Url = baseUrl / "search" - @Serializable - private data class SearchBody(val location: LocationSerializable, val promt: String) - private fun SearchRequest.toBody() = SearchBody(location.serializable(), prompt) - suspend fun search(request: SearchRequest): SearchRequest.Response { - val body = request.toBody() val response = httpClient.get(baseUrl.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("latitude", request.location.latitude) + parameter("longitude", request.location.longitude) + parameter("prompt", request.prompt) }.bodyAsSuccess>() return SearchRequest.Response(response.map { it.type() }) } From 805efc99f0df7281ff104794ec54f69ec08dde89 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 00:59:19 +0300 Subject: [PATCH 53/56] fix(#79-support-search): setBody remove at get search request --- .../sdk/engine/ktor/requests/search/SearchEngine.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt index 1c8e580b..f80611a0 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/search/SearchEngine.kt @@ -4,14 +4,11 @@ import app.meetacy.sdk.engine.ktor.apiVersion import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess import app.meetacy.sdk.engine.ktor.token import app.meetacy.sdk.engine.requests.SearchRequest -import app.meetacy.sdk.types.serializable.location.LocationSerializable -import app.meetacy.sdk.types.serializable.location.serializable import app.meetacy.sdk.types.serializable.search.SearchItemSerializable import app.meetacy.sdk.types.serializable.search.type import app.meetacy.sdk.types.url.Url import io.ktor.client.* import io.ktor.client.request.* -import kotlinx.serialization.Serializable internal class SearchEngine( baseUrl: Url, @@ -19,16 +16,13 @@ internal class SearchEngine( ) { val baseUrl: Url = baseUrl / "search" - @Serializable - private data class SearchBody(val location: LocationSerializable, val promt: String) - private fun SearchRequest.toBody() = SearchBody(location.serializable(), prompt) - suspend fun search(request: SearchRequest): SearchRequest.Response { - val body = request.toBody() val response = httpClient.get(baseUrl.string) { apiVersion(request.apiVersion) token(request.token) - setBody(body) + parameter("latitude", request.location.latitude) + parameter("longitude", request.location.longitude) + parameter("prompt", request.prompt) }.bodyAsSuccess>() return SearchRequest.Response(response.map { it.type() }) } From 57b569552355b7c801a6922d5c48e75a3cb6d141 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 01:09:15 +0300 Subject: [PATCH 54/56] Revert "fix(#76-support-search): some fixes" This reverts commit cf364a5757c800cf4bef17550aba7a8207e92dda. --- .../kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt | 1 - .../commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt | 2 ++ .../sdk/search/AuthorizedSearchItemRepository.kt | 10 +++++++--- .../app/meetacy/sdk/search/SearchItemRepository.kt | 3 ++- .../kotlin/app/meetacy/sdk/types/search/SearchItem.kt | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt index 23f6a20c..771d034a 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/AuthorizedMeetacyApi.kt @@ -40,7 +40,6 @@ public class AuthorizedMeetacyApi @UnsafeConstructor constructor( data = base.getMe(token), api = this ) - public suspend fun search(location: Location, prompt: String): List = base.search(token, location, prompt).map { AuthorizedSearchItemRepository.of(it.data, api = this) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt index 2fe76e01..6c0b0642 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt @@ -52,5 +52,7 @@ public class MeetacyApi( return AuthorizedMeetacyApi(token, base = this) } + + public companion object } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt index c98f6b4b..080f898d 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/AuthorizedSearchItemRepository.kt @@ -2,17 +2,21 @@ package app.meetacy.sdk.search import app.meetacy.sdk.AuthorizedMeetacyApi import app.meetacy.sdk.meetings.AuthorizedMeetingRepository +import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.search.SearchItem import app.meetacy.sdk.users.AuthorizedUserRepository import app.meetacy.sdk.types.place.Place as PlaceData public sealed class AuthorizedSearchItemRepository { + protected abstract val api: AuthorizedMeetacyApi public abstract val data: SearchItem public abstract val base: SearchItemRepository + public val token: Token get() = api.token + public class Meeting( override val data: SearchItem.Meeting, - public val api: AuthorizedMeetacyApi + override val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository get() = SearchItemRepository.Meeting(data, api.base) @@ -22,7 +26,7 @@ public sealed class AuthorizedSearchItemRepository { public class Place( override val data: SearchItem.Place, - public val api: AuthorizedMeetacyApi + override val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository get() = SearchItemRepository.Place(data) @@ -33,7 +37,7 @@ public sealed class AuthorizedSearchItemRepository { public class User( override val data: SearchItem.User, - public val api: AuthorizedMeetacyApi + override val api: AuthorizedMeetacyApi ) : AuthorizedSearchItemRepository() { override val base: SearchItemRepository diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt index 62bd4b1c..3abce628 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/search/SearchItemRepository.kt @@ -3,14 +3,15 @@ package app.meetacy.sdk.search import app.meetacy.sdk.MeetacyApi import app.meetacy.sdk.meetings.AuthorizedMeetingRepository import app.meetacy.sdk.meetings.MeetingRepository +import app.meetacy.sdk.types.place.Place as PlaceData import app.meetacy.sdk.types.search.SearchItem import app.meetacy.sdk.users.UserRepository -import app.meetacy.sdk.types.place.Place as PlaceData /** * When modifying this class, corresponding classes should be altered: * - [AuthorizedMeetingRepository] */ + public sealed class SearchItemRepository { public abstract val data: SearchItem diff --git a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt index 4cd02947..a6f194ce 100644 --- a/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt +++ b/types/src/commonMain/kotlin/app/meetacy/sdk/types/search/SearchItem.kt @@ -9,6 +9,7 @@ import app.meetacy.sdk.types.user.User as UserView * - [app.meetacy.sdk.search.SearchItemRepository] * - [app.meetacy.sdk.search.AuthorizedSearchItemRepository] */ + public sealed interface SearchItem { public class Meeting(public val meeting: MeetingView) : SearchItem public class User(public val user: UserView) : SearchItem From f9385108d12a55a01c811b8646ede43c05bea09c Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 01:12:18 +0300 Subject: [PATCH 55/56] fix(#79-support-search): setBody remove at get search request and revert commit --- .../ktor/requests/meetings/MeetingsEngine.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt index 5f7fa84d..739b0a32 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/meetings/MeetingsEngine.kt @@ -65,15 +65,21 @@ internal class MeetingsEngine( return ListMeetingsHistoryRequest.Response(response) } + private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody( + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listActiveMeetings( request: ListActiveMeetingsRequest ): ListActiveMeetingsRequest.Response { val url = baseUrl / "history" / "active" + val body = request.toBody() + val response = httpClient.get(url.string) { apiVersion(request.apiVersion) token(request.token) - parameter("amount", request.amount) - parameter("pagingId", request.pagingId) + setBody(body) }.bodyAsSuccess>() .type() .mapItems { meeting -> meeting.type() } @@ -81,16 +87,21 @@ internal class MeetingsEngine( return ListActiveMeetingsRequest.Response(response) } + private fun ListPastMeetingsRequest.toBody() = ListMeetingsPagingBody( + amount.serializable(), + pagingId?.serializable() + ) + suspend fun listPastMeetings( request: ListPastMeetingsRequest ): ListPastMeetingsRequest.Response { val url = baseUrl / "history" / "past" + val body = request.toBody() val response = httpClient.post(url.string) { apiVersion(request.apiVersion) token(request.token) - parameter("amount", request.amount) - parameter("pagingId", request.pagingId) + setBody(body) }.bodyAsSuccess>() .type() .mapItems { meeting -> meeting.type() } From ec82afce3c497021151d1da4dc03a93af747315f Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sat, 4 Nov 2023 11:48:09 +0300 Subject: [PATCH 56/56] fix(#79-support-search): add serial name for SearchItemSerializable --- .../types/serializable/search/SearchItemSerializable.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt index 14183c1e..ee9f29f2 100644 --- a/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt +++ b/types/serializable/src/commonMain/kotlin/app/meetacy/sdk/types/serializable/search/SearchItemSerializable.kt @@ -7,6 +7,7 @@ import app.meetacy.sdk.types.serializable.place.serializable import app.meetacy.sdk.types.serializable.place.type import app.meetacy.sdk.types.serializable.user.serializable import app.meetacy.sdk.types.serializable.user.type +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import app.meetacy.sdk.types.serializable.place.PlaceSerializable as PlaceViewSerializable import app.meetacy.sdk.types.serializable.meeting.MeetingSerializable as MeetingViewSerializable @@ -14,8 +15,14 @@ import app.meetacy.sdk.types.serializable.user.UserSerializable as UserViewSeria @Serializable public sealed interface SearchItemSerializable { + @SerialName("meeting") + @Serializable public class Meeting(public val meeting: MeetingViewSerializable) : SearchItemSerializable + @SerialName("user") + @Serializable public class User(public val user: UserViewSerializable) : SearchItemSerializable + @SerialName("place") + @Serializable public class Place(public val place: PlaceViewSerializable) : SearchItemSerializable }