Skip to content

Commit

Permalink
feat(close #101): implement meeting batch inviting
Browse files Browse the repository at this point in the history
  • Loading branch information
kramlex committed Apr 6, 2024
1 parent 5aa835f commit e09e00c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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.invitation.Invitation
import app.meetacy.sdk.types.serializable.invitation.InvitationIdSerializable
import app.meetacy.sdk.types.serializable.invitation.InvitationSerializable
import app.meetacy.sdk.types.serializable.invitation.serializable
Expand All @@ -17,6 +18,7 @@ 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 app.meetacy.sdk.types.user.UserId
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.post
Expand All @@ -32,12 +34,12 @@ internal class InvitationsEngine(
@Serializable
private data class CreateInvitationBody(
val meetingId: MeetingIdSerializable,
val userId: UserIdSerializable
val usersIds: List<UserIdSerializable>
)

private fun CreateInvitationRequest.toBody() = CreateInvitationBody(
meetingId.serializable(),
userId.serializable()
usersIds.map(UserId::serializable)
)

suspend fun create(
Expand All @@ -49,8 +51,8 @@ internal class InvitationsEngine(
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
}.bodyAsSuccess<InvitationSerializable>()
return CreateInvitationRequest.Response(response.type())
}.bodyAsSuccess<List<InvitationSerializable>>()
return CreateInvitationRequest.Response(response.map(InvitationSerializable::type))
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import app.meetacy.sdk.types.user.UserId

public data class CreateInvitationRequest(
val token: Token,
val userId: UserId,
val usersIds: List<UserId>,
val meetingId: MeetingId
) : MeetacyRequest<CreateInvitationRequest.Response> {
public data class Response(val invitation: Invitation)
public data class Response(val invitations: List<Invitation>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ package app.meetacy.sdk.invitations

import app.meetacy.sdk.AuthorizedMeetacyApi
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.datetime.DateTime
import app.meetacy.sdk.types.invitation.InvitationId
import app.meetacy.sdk.types.meeting.MeetingId
import app.meetacy.sdk.types.user.User
import app.meetacy.sdk.types.user.UserId
import app.meetacy.sdk.users.UserRepository
import kotlin.jvm.JvmName

public class AuthorizedInvitationsApi(private val api: AuthorizedMeetacyApi) {
public val token: Token get() = api.token
public val base: InvitationsApi = api.base.invitations

public suspend fun create(
userId: UserId,
usersIds: List<UserId>,
meetingId: MeetingId
): AuthorizedInvitationRepository {
val invitation = base.create(token, userId, meetingId).data
): List<AuthorizedInvitationRepository> {
val invitations = base.create(token, usersIds, meetingId)

return AuthorizedInvitationRepository(invitation, api)
return invitations.map { AuthorizedInvitationRepository(it.data, api) }
}

public suspend fun accept(invitationId: InvitationId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package app.meetacy.sdk.invitations

import app.meetacy.sdk.MeetacyApi
import app.meetacy.sdk.engine.requests.*
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.auth.Token
import app.meetacy.sdk.types.datetime.DateTime
import app.meetacy.sdk.types.invitation.InvitationId
import app.meetacy.sdk.types.meeting.MeetingId
import app.meetacy.sdk.types.user.User
import app.meetacy.sdk.types.user.UserId
import app.meetacy.sdk.users.UserRepository
import kotlin.jvm.JvmName

public class InvitationsApi(private val api: MeetacyApi) {
public suspend fun create(
token: Token,
userId: UserId,
usersIds: List<UserId>,
meetingId: MeetingId
): InvitationsRepository {
val invitation = api.engine.execute(
): List<InvitationsRepository> {
val invitations = api.engine.execute(
request = CreateInvitationRequest(
token,
userId,
usersIds,
meetingId
)
).invitation
).invitations

return InvitationsRepository(invitation, api)
return invitations.map { InvitationsRepository(it, api) }
}

public suspend fun accept(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

kotlin = "1.9.0"
ktor = "2.3.6"
meetacySdk = "0.0.70"
meetacySdk = "0.0.71"

# kotlinx
kotlinxCoroutines = "1.6.4"
Expand Down

0 comments on commit e09e00c

Please sign in to comment.