Skip to content

Commit

Permalink
WIP(#76-support-auth-header): meeting independence was added
Browse files Browse the repository at this point in the history
  • Loading branch information
y9Kap committed Oct 22, 2023
1 parent 5f4fe8d commit 22ac94b
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.meetacy.sdk.engine.ktor.requests.extencion

import app.meetacy.sdk.engine.requests.MeRequestWithToken
import app.meetacy.sdk.engine.requests.MeetacyRequest
import app.meetacy.sdk.engine.requests.MeetacyRequestWithToken
import app.meetacy.sdk.engine.requests.TokenProviderEmpty
import io.ktor.client.*
import io.ktor.client.call.*
Expand All @@ -10,7 +9,7 @@ import io.ktor.http.*
import io.ktor.http.content.*
import kotlinx.serialization.json.JsonObject

public suspend inline fun <T, R : MeRequestWithToken<T>> post(
public suspend inline fun <T, R : MeetacyRequestWithToken<T>> post(
urlString: String,
jsonObject: JsonObject,
httpClient: HttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ 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.ListMeetingsResponse
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.url.Url
import dev.icerock.moko.network.generated.apis.MeetingsApiImpl
import dev.icerock.moko.network.generated.models.*
import dev.icerock.moko.network.generated.models.ListMapMeetingsResponse
import dev.icerock.moko.network.generated.models.ListMeetingParticipantsResponse
import dev.icerock.moko.network.generated.models.User
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
Expand All @@ -25,9 +24,8 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonObject
import dev.icerock.moko.network.generated.models.ListMeetingParticipantsRequest as GeneratedListMeetingParticipantsRequest
import dev.icerock.moko.network.generated.models.Meeting as GeneratedMeeting
import app.meetacy.sdk.engine.ktor.response.models.Meeting as LolMeeting
import dev.icerock.moko.network.generated.models.Meeting as GeneratedMeeting

internal class MeetingsEngine(
private val baseUrl: Url,
Expand Down Expand Up @@ -61,18 +59,20 @@ internal class MeetingsEngine(
suspend fun listActiveMeetings(
request: ListActiveMeetingsRequest
): ListActiveMeetingsRequest.Response = with(request) {
val response = base.meetingsHistoryActiveGet(
listMeetingsRequest = ListMeetingsRequest(
amount = amount.int,
pagingId = pagingId?.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "history" / "active"

val jsonObject = buildJsonObject {
put("amount", amount.int)
put("pagingId", pagingId?.string)
}

val string = post(url.string, jsonObject, httpClient, request)

val response = Json.decodeFromString<ListMeetingsResponse>(string).result

val paging = PagingResponse(
nextPagingId = response.result.nextPagingId?.let(::PagingId),
data = response.result.data.map(GeneratedMeeting::mapToMeeting)
nextPagingId = response.nextPagingId?.let(::PagingId),
data = response.data.map(LolMeeting::mapToMeeting)
)

return ListActiveMeetingsRequest.Response(paging)
Expand All @@ -81,18 +81,20 @@ internal class MeetingsEngine(
suspend fun listPastMeetings(
request: ListPastMeetingsRequest
): ListPastMeetingsRequest.Response = with(request) {
val response = base.meetingsHistoryPastGet(
listMeetingsRequest = ListMeetingsRequest(
amount = amount.int,
pagingId = pagingId?.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "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<ListMeetingsResponse>(string).result

val paging = PagingResponse(
nextPagingId = response.result.nextPagingId?.let(::PagingId),
data = response.result.data.map(GeneratedMeeting::mapToMeeting)
nextPagingId = response.nextPagingId?.let(::PagingId),
data = response.data.map(LolMeeting::mapToMeeting)
)

return ListPastMeetingsRequest.Response(paging)
Expand All @@ -101,18 +103,19 @@ internal class MeetingsEngine(
suspend fun listMeetingsMap(
request: ListMeetingsMapRequest
): ListMeetingsMapRequest.Response = with (request) {
val response = base.meetingsMapListPost(
listMapMeetingsRequest = ListMapMeetingsRequest(
location = Location(
latitude = location.latitude,
longitude = location.longitude
)
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "map" / "list"

val data = response.result.map(GeneratedMeeting::mapToMeeting)
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<ListMapMeetingsResponse>(string).result

val data = response.map(GeneratedMeeting::mapToMeeting)

return ListMeetingsMapRequest.Response(data)
}
Expand Down Expand Up @@ -187,7 +190,7 @@ internal class MeetingsEngine(
)
)
header("Authorization", token.string)
header("Api-Version", request.apiVersion.int.toString())
header("Api-Version", apiVersion.int.toString())
}.body<String>()

val meeting = Json.decodeFromString<EditMeetingResponse>(string).result
Expand All @@ -198,43 +201,47 @@ internal class MeetingsEngine(
suspend fun listMeetingParticipants(
request: ListMeetingParticipantsRequest
): ListMeetingParticipantsRequest.Response {
val response = base.meetingsParticipantsListPost(
listMeetingParticipantsRequest = GeneratedListMeetingParticipantsRequest(
amount = request.amount.int,
meetingId = request.meetingId.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "participants" / "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<ListMeetingParticipantsResponse>(string).result

val paging = PagingResponse(
data = response.result.data.map(User::mapToUser),
nextPagingId = response.result.nextPagingId?.let(::PagingId)
data = response.data.map(User::mapToUser),
nextPagingId = response.nextPagingId?.let(::PagingId)
)

return ListMeetingParticipantsRequest.Response(paging)
}

suspend fun participateMeeting(request: ParticipateMeetingRequest) {
base.meetingsParticipatePost(
accessMeetingIdRequest = AccessMeetingIdRequest(
meetingId = request.meetingId.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "participate"

val jsonObject = buildJsonObject {
put("meetingId", request.meetingId.string)
}

post(url.string, jsonObject, httpClient, request)
}

suspend fun getMeeting(request: GetMeetingRequest): GetMeetingRequest.Response {
val response = base.meetingsGetPost(
accessMeetingIdRequest = AccessMeetingIdRequest(
meetingId = request.meetingId.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "get"

val jsonObject = buildJsonObject {
put("meetingId", request.meetingId.string)
}

val string = post(url.string, jsonObject, httpClient, request)

val response = Json.decodeFromString<CreateMeetingResponse>(string).result

val meeting = response.result.mapToMeeting()
val meeting = response.mapToMeeting()

return GetMeetingRequest.Response(meeting)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class NotificationsEngine(
lastNotificationId = lastNotificationId.string
),
apiVersion = apiVersion.int.toString(),
authorization = request.token.string
authorization = token.string
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class CreateMeetingRequest(
public val description: String?,
public val visibility: Meeting.Visibility,
public val fileId: FileId? = null
) : MeetacyRequest<CreateMeetingRequest.Response>, MeRequestWithToken<CreateMeetingRequest.Response> {
) : MeetacyRequest<CreateMeetingRequest.Response>, MeetacyRequestWithToken<CreateMeetingRequest.Response> {
public data class Response(val meeting: Meeting)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import app.meetacy.sdk.types.meeting.MeetingId
import app.meetacy.sdk.types.optional.Optional

public data class EditMeetingRequest(
public val token: Token,
public override val token: Token,
public val meetingId: MeetingId,
public val title: Optional<String>,
public val description: Optional<String?>,
public val location: Optional<Location>,
public val date: Optional<Date>,
public val avatarId: Optional<FileId?>,
public val visibility: Optional<Meeting.Visibility>
) : MeetacyRequest<EditMeetingRequest.Response> {
) : MeetacyRequest<EditMeetingRequest.Response>, MeetacyRequestWithToken<EditMeetingRequest.Response> {
public data class Response(val meeting: Meeting)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import app.meetacy.sdk.types.meeting.Meeting
import app.meetacy.sdk.types.meeting.MeetingId

public data class GetMeetingRequest(
val token: Token,
override val token: Token,
val meetingId: MeetingId
) : MeetacyRequest<GetMeetingRequest.Response> {
) : MeetacyRequest<GetMeetingRequest.Response>, MeetacyRequestWithToken<GetMeetingRequest.Response> {
public data class Response(val meeting: Meeting)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingResponse

public data class ListActiveMeetingsRequest(
val token: Token,
override val token: Token,
val amount: Amount,
val pagingId: PagingId?
) : MeetacyRequest<ListActiveMeetingsRequest.Response> {
) : MeetacyRequest<ListActiveMeetingsRequest.Response>,
MeetacyRequestWithToken<ListActiveMeetingsRequest.Response> {
public data class Response(val paging: PagingResponse<Meeting>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import app.meetacy.sdk.types.paging.PagingResponse
import app.meetacy.sdk.types.user.User

public data class ListMeetingParticipantsRequest(
val token: Token,
override val token: Token,
val meetingId: MeetingId,
val amount: Amount,
val pagingId: PagingId?
) : MeetacyRequest<ListMeetingParticipantsRequest.Response> {
) : MeetacyRequest<ListMeetingParticipantsRequest.Response>,
MeetacyRequestWithToken<ListMeetingParticipantsRequest.Response> {
public data class Response(val paging: PagingResponse<User>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public data class ListMeetingsHistoryRequest(
override val token: Token,
val amount: Amount,
val pagingId: PagingId?
) : MeetacyRequest<ListMeetingsHistoryRequest.Response>, MeRequestWithToken<ListMeetingsHistoryRequest.Response> {
) : MeetacyRequest<ListMeetingsHistoryRequest.Response>, MeetacyRequestWithToken<ListMeetingsHistoryRequest.Response> {
public data class Response(val paging: PagingResponse<Meeting>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import app.meetacy.sdk.types.location.Location
import app.meetacy.sdk.types.meeting.Meeting

public data class ListMeetingsMapRequest(
val token: Token,
override val token: Token,
val location: Location
) : MeetacyRequest<ListMeetingsMapRequest.Response> {
) : MeetacyRequest<ListMeetingsMapRequest.Response>, MeetacyRequestWithToken<ListMeetingsMapRequest.Response> {
public data class Response(val meetings: List<Meeting>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingResponse

public data class ListPastMeetingsRequest(
val token: Token,
override val token: Token,
val amount: Amount,
val pagingId: PagingId?
) : MeetacyRequest<ListPastMeetingsRequest.Response> {
) : MeetacyRequest<ListPastMeetingsRequest.Response>,
MeetacyRequestWithToken<ListPastMeetingsRequest.Response> {
public data class Response(val paging: PagingResponse<Meeting>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ public sealed interface MeetacyRequest<out T> {
}

public typealias SimpleMeetacyRequest = MeetacyRequest<Unit>
public typealias SimpleMeetacyRequestWithToken = MeetacyRequestWithToken<Unit>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.meeting.MeetingId

public data class ParticipateMeetingRequest(
val token: Token,
override val token: Token,
val meetingId: MeetingId
) : SimpleMeetacyRequest
) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.meetacy.sdk.engine.requests

import app.meetacy.sdk.types.auth.Token

public sealed interface MeRequestWithToken<out T> : MeetacyRequest<T> {
public sealed interface MeetacyRequestWithToken<out T> : MeetacyRequest<T> {
public val token: Token
}

Expand Down

0 comments on commit 22ac94b

Please sign in to comment.