From 0acb70726725d3bb4adb4cc5c73368d70f6b8271 Mon Sep 17 00:00:00 2001 From: y9Kap Date: Sun, 10 Mar 2024 00:45:36 +0300 Subject: [PATCH] feat(#96-add-support-quit-meeting-request): support quit meeting request was added --- .../sdk/engine/ktor/KtorMeetacyEngine.kt | 1 + .../ktor/requests/meetings/MeetingsEngine.kt | 29 ++++++++++++------- .../sdk/engine/requests/QuitMeetingRequest.kt | 9 ++++++ .../meetings/AuthorizedMeetingRepository.kt | 4 +++ .../sdk/meetings/AuthorizedMeetingsApi.kt | 4 +++ .../meetacy/sdk/meetings/MeetingRepository.kt | 4 +++ .../app/meetacy/sdk/meetings/MeetingsApi.kt | 9 +++--- 7 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/QuitMeetingRequest.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 6f08f8a..1639d0b 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 @@ -139,6 +139,7 @@ public class KtorMeetacyEngine( is ListMeetingsMapRequest -> meetings.listMeetingsMap(request) as T is CreateMeetingRequest -> meetings.createMeeting(request) as T is ParticipateMeetingRequest -> meetings.participateMeeting(request) as T + is QuitMeetingRequest -> meetings.quitMeeting(request) as T is GetMeetingRequest -> meetings.getMeeting(request) as T is EditMeetingRequest -> meetings.editMeeting(request) as T is ListMeetingParticipantsRequest -> meetings.listMeetingParticipants(request) as T 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 662613e..ee65c3e 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,15 +4,7 @@ import app.meetacy.sdk.engine.ktor.apiVersion 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.CreateMeetingRequest -import app.meetacy.sdk.engine.requests.EditMeetingRequest -import app.meetacy.sdk.engine.requests.GetMeetingRequest -import app.meetacy.sdk.engine.requests.ListActiveMeetingsRequest -import app.meetacy.sdk.engine.requests.ListMeetingParticipantsRequest -import app.meetacy.sdk.engine.requests.ListMeetingsHistoryRequest -import app.meetacy.sdk.engine.requests.ListMeetingsMapRequest -import app.meetacy.sdk.engine.requests.ListPastMeetingsRequest -import app.meetacy.sdk.engine.requests.ParticipateMeetingRequest +import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.types.optional.map import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable @@ -35,8 +27,8 @@ 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.HttpClient -import io.ktor.client.call.body +import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.request.* import kotlinx.serialization.Serializable @@ -239,6 +231,21 @@ internal class MeetingsEngine( }.body() } + @Serializable + private data class QuitMeetingBody(val meetingId: MeetingIdSerializable) + + private fun QuitMeetingRequest.toBody() = QuitMeetingBody(meetingId.serializable()) + + suspend fun quitMeeting(request: QuitMeetingRequest) { + val url = baseUrl / "quit" + val body = request.toBody() + httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.body() + } + @Serializable private data class GetMeetingBody(val meetingId: MeetingIdSerializable) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/QuitMeetingRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/QuitMeetingRequest.kt new file mode 100644 index 0000000..a6b6437 --- /dev/null +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/QuitMeetingRequest.kt @@ -0,0 +1,9 @@ +package app.meetacy.sdk.engine.requests + +import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.meeting.MeetingId + +public data class QuitMeetingRequest( + val token: Token, + val meetingId: MeetingId +) : SimpleMeetacyRequest 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 456c330..2abe309 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingRepository.kt @@ -74,4 +74,8 @@ public class AuthorizedMeetingRepository( public suspend fun participate() { api.meetings.participate(data.id) } + + public suspend fun quit() { + api.meetings.quit(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 5c37365..885a03a 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/AuthorizedMeetingsApi.kt @@ -93,6 +93,10 @@ public class AuthorizedMeetingsApi( base.participate(api.token, meetingId) } + public suspend fun quit(meetingId: MeetingId) { + base.quit(api.token, meetingId) + } + public suspend fun get(meetingId: MeetingId): AuthorizedMeetingRepository { val repository = base.get(api.token, meetingId) 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 338aef6..5c4d19f 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingRepository.kt @@ -77,6 +77,10 @@ public class MeetingRepository( api.meetings.participate(token, id) } + public suspend fun quit(token: Token) { + api.meetings.quit(token, id) + } + public suspend fun updated( token: Token ): 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 d7506c6..0a6f6e8 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/meetings/MeetingsApi.kt @@ -1,10 +1,7 @@ package app.meetacy.sdk.meetings import app.meetacy.sdk.MeetacyApi -import app.meetacy.sdk.engine.requests.CreateMeetingRequest -import app.meetacy.sdk.engine.requests.EditMeetingRequest -import app.meetacy.sdk.engine.requests.GetMeetingRequest -import app.meetacy.sdk.engine.requests.ParticipateMeetingRequest +import app.meetacy.sdk.engine.requests.* import app.meetacy.sdk.meetings.history.MeetingsHistoryApi import app.meetacy.sdk.meetings.map.MeetingsMapApi import app.meetacy.sdk.meetings.participants.MeetingParticipantsApi @@ -103,6 +100,10 @@ public class MeetingsApi(private val api: MeetacyApi) { api.engine.execute(ParticipateMeetingRequest(token, meetingId)) } + public suspend fun quit(token: Token, meetingId: MeetingId) { + api.engine.execute(QuitMeetingRequest(token, meetingId)) + } + public suspend fun get(token: Token, meetingId: MeetingId): MeetingRepository { val meeting = api.engine.execute(GetMeetingRequest(token, meetingId)).meeting