Skip to content

Commit

Permalink
WIP(#76-support-auth-header): list meetings history is independence
Browse files Browse the repository at this point in the history
  • Loading branch information
y9Kap committed Oct 20, 2023
1 parent 4b85250 commit fee6809
Show file tree
Hide file tree
Showing 52 changed files with 2,171 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import dev.icerock.moko.network.generated.models.Location as GeneratedLocation
import dev.icerock.moko.network.generated.models.Meeting as GeneratedMeeting
import dev.icerock.moko.network.generated.models.Notification as GeneratedNotification
import dev.icerock.moko.network.generated.models.User as GeneratedUser
import app.meetacy.sdk.engine.ktor.response.models.Meeting as LolMeeting
import app.meetacy.sdk.engine.ktor.response.models.User as LolUser

internal fun GeneratedUser.mapToSelfUser(): SelfUser = mapToUser() as SelfUser
internal fun GeneratedUser.mapToRegularUser(): RegularUser = mapToUser() as RegularUser
Expand All @@ -46,6 +48,26 @@ internal fun GeneratedUser.mapToUser(): User = if (isSelf) {
)
}

@OptIn(UnsafeConstructor::class)
internal fun LolUser.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 GeneratedInvitation.toInvitation(): Invitation = Invitation(
id = identity.let(::InvitationId),
meeting = meeting.mapToMeeting(),
Expand All @@ -66,6 +88,26 @@ internal fun String.mapToRelationship(): Relationship? = when(this) {
else -> null
}

internal fun LolMeeting.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(LolUser::mapToUser),
avatarId = avatarId?.let(::FileId),
visibility = when (visibility) {
LolMeeting.Visibility.PUBLIC -> Meeting.Visibility.Public
LolMeeting.Visibility.PRIVATE -> Meeting.Visibility.Private
}
)

internal fun GeneratedMeeting.mapToMeeting(): Meeting = Meeting(
id = MeetingId(id),
creator = creator.mapToUser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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.response.models.CreateMeetingResponse
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
Expand All @@ -23,6 +25,7 @@ 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

internal class MeetingsEngine(
private val baseUrl: Url,
Expand All @@ -34,18 +37,28 @@ internal class MeetingsEngine(
suspend fun listMeetingsHistory(
request: ListMeetingsHistoryRequest
): ListMeetingsHistoryRequest.Response = with(request) {
val response = base.meetingsHistoryListPost(
listMeetingsRequest = ListMeetingsRequest(
amount = amount.int,
pagingId = pagingId?.string
),
apiVersion = request.apiVersion.int.toString(),
authorization = request.token.string
)
val url = baseUrl / "meetings" / "history" / "list"

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

val string = httpClient.post(url.string) {
setBody(
TextContent(
text = jsonObject.toString(),
contentType = ContentType.Application.Json
)
)
header("Authorization", token.string)
}.body<String>()

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

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

return ListMeetingsHistoryRequest.Response(paging)
Expand Down Expand Up @@ -128,15 +141,13 @@ internal class MeetingsEngine(
}

val string = httpClient.post(url.string) {
headers {
append("Authorization", token.string)
}
setBody(
TextContent(
text = jsonObject.toString(),
contentType = ContentType.Application.Json
)
)
header("Authorization", token.string)
}.body<String>()

val meeting = Json.decodeFromString<CreateMeetingResponse>(string).result
Expand Down Expand Up @@ -174,15 +185,13 @@ internal class MeetingsEngine(
}

val string = httpClient.post(url.string) {
headers {
append("Authorization", token.string)
}
setBody(
TextContent(
text = jsonObject.toString(),
contentType = ContentType.Application.Json
)
)
header("Authorization", token.string)
}.body<String>()

val meeting = Json.decodeFromString<EditMeetingResponse>(string).result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@ internal class UsersEngine(
}

val string = httpClient.post(url.string) {
headers {
append("Authorization", token.string)
}
setBody(
TextContent(
text = jsonObject.toString(),
contentType = ContentType.Application.Json
)
)

header("Authorization", token.string)
}.body<String>()

val user = Json.decodeFromString<EditUserResponse>(string).result
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param id
*/
@Serializable
internal data class AcceptInvitationRequest (

@SerialName("id")
val id: String? = null

)

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param accessIdentity
* @param fileIdentity
*/
@Serializable
internal data class AccessAvatarRequest (

@SerialName("accessIdentity")
val accessIdentity: String,

@SerialName("fileIdentity")
val fileIdentity: String? = null

)

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param friendId
*/
@Serializable
internal data class AccessFriendRequest (

@SerialName("friendId")
val friendId: String

)

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param accessIdentity
*/
@Serializable
internal data class AccessIdentityRequest (

@SerialName("accessIdentity")
val accessIdentity: String

)

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param meetingId
*/
@Serializable
internal data class AccessMeetingIdRequest (

@SerialName("meetingId")
val meetingId: String

)

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Meetacy Backend API
* _Version 1.0.2 of the `Meetacy` API documentation_. It is recommended to fill in the request body on your own according to the sample provided below. The `Notifications` section is under development.
*
* OpenAPI spec version: 1.0.2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package app.meetacy.sdk.engine.ktor.response.models

import kotlinx.serialization.Serializable






import kotlinx.serialization.SerialName


/**
*
* @param id
*/
@Serializable
internal data class CancelInvitationRequest (

@SerialName("id")
val id: String

)

Loading

0 comments on commit fee6809

Please sign in to comment.