Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#96-add-support-leave-meeting-request #97

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 LeaveMeetingRequest -> meetings.leaveMeeting(request) as T
is GetMeetingRequest -> meetings.getMeeting(request) as T
is EditMeetingRequest -> meetings.editMeeting(request) as T
is ListMeetingParticipantsRequest -> meetings.listMeetingParticipants(request) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -239,6 +231,21 @@ internal class MeetingsEngine(
}.body<StatusTrueResponse>()
}

@Serializable
private data class LeaveMeetingBody(val meetingId: MeetingIdSerializable)

private fun LeaveMeetingRequest.toBody() = LeaveMeetingBody(meetingId.serializable())

suspend fun leaveMeeting(request: LeaveMeetingRequest) {
val url = baseUrl / "leave"
val body = request.toBody()
httpClient.post(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
}.body<StatusTrueResponse>()
}

@Serializable
private data class GetMeetingBody(val meetingId: MeetingIdSerializable)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 LeaveMeetingRequest(
val token: Token,
val meetingId: MeetingId
) : SimpleMeetacyRequest
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ public class AuthorizedMeetingRepository(
public suspend fun participate() {
api.meetings.participate(data.id)
}

public suspend fun leave() {
api.meetings.leave(data.id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public class AuthorizedMeetingsApi(
base.participate(api.token, meetingId)
}

public suspend fun leave(meetingId: MeetingId) {
base.leave(api.token, meetingId)
}

public suspend fun get(meetingId: MeetingId): AuthorizedMeetingRepository {
val repository = base.get(api.token, meetingId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public class MeetingRepository(
api.meetings.participate(token, id)
}

public suspend fun leave(token: Token) {
api.meetings.leave(token, id)
}

public suspend fun updated(
token: Token
): MeetingRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -103,6 +100,10 @@ public class MeetingsApi(private val api: MeetacyApi) {
api.engine.execute(ParticipateMeetingRequest(token, meetingId))
}

public suspend fun leave(token: Token, meetingId: MeetingId) {
api.engine.execute(LeaveMeetingRequest(token, meetingId))
}

public suspend fun get(token: Token, meetingId: MeetingId): MeetingRepository {
val meeting = api.engine.execute(GetMeetingRequest(token, meetingId)).meeting

Expand Down
Loading