diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt index 35019d0e..27958966 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/Mappers.kt @@ -15,27 +15,17 @@ import app.meetacy.sdk.types.meeting.MeetingId import app.meetacy.sdk.types.notification.Notification import app.meetacy.sdk.types.notification.NotificationId import app.meetacy.sdk.types.user.* -import dev.icerock.moko.network.generated.models.Notification.Type.MEETING_INVITATION -import dev.icerock.moko.network.generated.models.Notification.Type.SUBSCRIPTION -import dev.icerock.moko.network.generated.models.Invitation as GeneratedInvitation -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 -import app.meetacy.sdk.engine.ktor.response.models.Notification as LolNotification -import app.meetacy.sdk.engine.ktor.response.models.Invitation as LolInvitation -import app.meetacy.sdk.engine.ktor.response.models.Location as LolLocation +import app.meetacy.sdk.engine.ktor.response.models.Invitation as ModelInvitation +import app.meetacy.sdk.engine.ktor.response.models.Location as ModelLocation +import app.meetacy.sdk.engine.ktor.response.models.Meeting as ModelMeeting +import app.meetacy.sdk.engine.ktor.response.models.Notification as ModelNotification +import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser -internal fun GeneratedUser.mapToSelfUser(): SelfUser = mapToUser() as SelfUser -internal fun GeneratedUser.mapToRegularUser(): RegularUser = mapToUser() as RegularUser - -internal fun LolUser.mapToSelfUser(): SelfUser = mapToUser() as SelfUser -internal fun LolUser.mapToRegularUser(): RegularUser = mapToUser() as RegularUser +internal fun ModelUser.mapToSelfUser(): SelfUser = mapToUser() as SelfUser +internal fun ModelUser.mapToRegularUser(): RegularUser = mapToUser() as RegularUser @OptIn(UnsafeConstructor::class) -internal fun GeneratedUser.mapToUser(): User = if (isSelf) { +internal fun ModelUser.mapToUser(): User = if (isSelf) { SelfUser( id = UserId(id), nickname = nickname, @@ -54,39 +44,7 @@ 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(), - invitedUser = invitedUser.mapToUser(), - inviterUser = inviterUser.mapToUser(), - isAccepted = when (isAccepted) { - null -> AcceptationState.Waiting - true -> AcceptationState.Accepted - false -> AcceptationState.Declined - } -) - -internal fun LolInvitation.toInvitation(): Invitation = Invitation( +internal fun ModelInvitation.toInvitation(): Invitation = Invitation( id = identity.let(::InvitationId), meeting = meeting.mapToMeeting(), invitedUser = invitedUser.mapToUser(), @@ -106,7 +64,7 @@ internal fun String.mapToRelationship(): Relationship? = when(this) { else -> null } -internal fun LolMeeting.mapToMeeting(): Meeting = Meeting( +internal fun ModelMeeting.mapToMeeting(): Meeting = Meeting( id = MeetingId(id), creator = creator.mapToUser(), date = Date(date), @@ -118,57 +76,18 @@ internal fun LolMeeting.mapToMeeting(): Meeting = Meeting( description = description, participantsCount = participantsCount, isParticipating = isParticipating, - previewParticipants = previewParticipants.map(LolUser::mapToUser), + previewParticipants = previewParticipants.map(ModelUser::mapToUser), avatarId = avatarId?.let(::FileId), visibility = when (visibility) { - LolMeeting.Visibility.PUBLIC -> Meeting.Visibility.Public - LolMeeting.Visibility.PRIVATE -> Meeting.Visibility.Private + ModelMeeting.Visibility.PUBLIC -> Meeting.Visibility.Public + ModelMeeting.Visibility.PRIVATE -> Meeting.Visibility.Private } ) -internal fun GeneratedMeeting.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(GeneratedUser::mapToUser), - avatarId = avatarId?.let(::FileId), - visibility = when (visibility) { - GeneratedMeeting.Visibility.PUBLIC -> Meeting.Visibility.Public - GeneratedMeeting.Visibility.PRIVATE -> Meeting.Visibility.Private - } -) - -internal fun GeneratedLocation.mapToLocation(): Location = - Location(latitude, longitude) - -internal fun GeneratedNotification.mapToNotification(): Notification = when (this.type) { - SUBSCRIPTION -> Notification.Subscription( - id = NotificationId(id), - isNew = isNew, - date = Date(date), - subscriber = subscriber!!.mapToRegularUser() - ) - MEETING_INVITATION -> Notification.Invitation( - id = NotificationId(id), - isNew = isNew, - date = Date(date), - meeting = meeting!!.mapToMeeting(), - inviter = inviter!!.mapToRegularUser() - ) -} - -internal fun LolLocation.mapToLocation(): Location = +internal fun ModelLocation.mapToLocation(): Location = Location(latitude, longitude) -internal fun LolNotification.mapToNotification(): Notification = when (this.type) { +internal fun ModelNotification.mapToNotification(): Notification = when (this.type) { app.meetacy.sdk.engine.ktor.response.models.Notification.Type.SUBSCRIPTION -> Notification.Subscription( id = NotificationId(id), isNew = isNew, diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt index 8cce8109..16b72061 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/files/FilesEngine.kt @@ -1,5 +1,6 @@ package app.meetacy.sdk.engine.ktor.requests.files +import app.meetacy.sdk.engine.ktor.response.models.GenerateIdentityResponse import app.meetacy.sdk.engine.requests.GetFileRequest import app.meetacy.sdk.engine.requests.UploadFileRequest import app.meetacy.sdk.files.DownloadableFile @@ -10,7 +11,6 @@ import app.meetacy.sdk.io.asMeetacyInput import app.meetacy.sdk.types.file.FileId import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.url.parametersOf -import dev.icerock.moko.network.generated.models.GenerateIdentityResponse import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.request.forms.* diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt index 80e19a93..e6d72351 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/FriendsEngine.kt @@ -8,15 +8,16 @@ import app.meetacy.sdk.engine.ktor.mapToRegularUser import app.meetacy.sdk.engine.ktor.mapToUser import app.meetacy.sdk.engine.ktor.requests.extencion.post import app.meetacy.sdk.engine.ktor.response.models.ListFriendsResponse -import app.meetacy.sdk.engine.ktor.response.models.Location +import app.meetacy.sdk.engine.ktor.response.models.Location as ModelLocation import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse -import app.meetacy.sdk.engine.ktor.response.models.User +import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser import app.meetacy.sdk.engine.requests.AddFriendRequest import app.meetacy.sdk.engine.requests.DeleteFriendRequest import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest import app.meetacy.sdk.engine.requests.ListFriendsRequest import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.datetime.DateTime +import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse import app.meetacy.sdk.types.url.Url @@ -36,13 +37,14 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put internal class FriendsEngine( - private val baseUrl: Url, + baseUrl: Url, private val httpClient: HttpClient, private val json: Json ) { + private val baseUrl = baseUrl / "friends" suspend fun add(request: AddFriendRequest): StatusTrueResponse { - val url = baseUrl / "friends" / "add" + val url = baseUrl / "add" val jsonObject = buildJsonObject { put("friendId", request.friendId.string) @@ -54,7 +56,7 @@ internal class FriendsEngine( } suspend fun delete(request: DeleteFriendRequest): StatusTrueResponse { - val url = baseUrl / "friends" / "delete" + val url = baseUrl / "delete" val jsonObject = buildJsonObject { put("friendId", request.friendId.string) @@ -66,7 +68,7 @@ internal class FriendsEngine( } suspend fun list(request: ListFriendsRequest): ListFriendsRequest.Response { - val url = baseUrl / "friends" / "list" + val url = baseUrl / "list" val jsonObject = buildJsonObject { put("amount", request.amount.int.toString()) @@ -86,7 +88,7 @@ internal class FriendsEngine( } suspend fun streamFriendsLocation(request: EmitFriendsLocationRequest) = handleRSocketExceptions(json) { - val url = baseUrl.replaceProtocolWithWebsocket() / "friends" / "location" / "stream" + val url = baseUrl.replaceProtocolWithWebsocket() / "location" / "stream" val socket = httpClient.rSocket( urlString = url.string, @@ -115,7 +117,7 @@ private fun EmitFriendsLocationRequest.encodeToPayload(json: Json): Payload = bu data(json.encodeToString(initObject)) } -private fun app.meetacy.sdk.types.location.Location.encodeToPayload(): Payload = buildPayload { +private fun Location.encodeToPayload(): Payload = buildPayload { val locationString = buildJsonObject { val `object` = buildJsonObject { put("latitude", latitude) @@ -128,14 +130,14 @@ private fun app.meetacy.sdk.types.location.Location.encodeToPayload(): Payload = } @Serializable -private data class LolUserLocationSnapshotSerializable( - val user: User, - val location: Location, // TODO: изменить название класса после удаления зависимостей +private data class ModelUserLocationSnapshotSerializable( + val user: ModelUser, + val location: ModelLocation, val capturedAt: String ) private fun Payload.decodeToUserLocationSnapshot(json: Json): UserLocationSnapshot { - val deserialized = json.decodeFromString(data.readText()) + val deserialized = json.decodeFromString(data.readText()) return UserLocationSnapshot( user = deserialized.user.mapToUser() as RegularUser, diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt index 79c17e15..2c818f4c 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.kt @@ -1,73 +1,81 @@ package app.meetacy.sdk.engine.ktor.requests.invitations +import app.meetacy.sdk.engine.ktor.requests.extencion.post +import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse import app.meetacy.sdk.engine.ktor.toInvitation -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.url.Url -import dev.icerock.moko.network.generated.apis.InvitationsApi -import dev.icerock.moko.network.generated.apis.InvitationsApiImpl import io.ktor.client.* import kotlinx.serialization.json.Json -import dev.icerock.moko.network.generated.models.AcceptInvitationRequest as GeneratedAcceptInvitationRequest -import dev.icerock.moko.network.generated.models.CancelInvitationRequest as GeneratedCancelInvitationRequest -import dev.icerock.moko.network.generated.models.CreateInvitationRequest as GeneratedCreateInvitationRequest -import dev.icerock.moko.network.generated.models.DenyInvitationRequest as GeneratedDenyInvitationRequest +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put internal class InvitationsEngine( - private val baseUrl: Url, + baseUrl: Url, private val httpClient: HttpClient, - json: Json + private val json: Json ) { - private val base: InvitationsApi = InvitationsApiImpl(baseUrl.string, httpClient, json) - + private val baseUrl = baseUrl / "invitations" suspend fun create( request: CreateInvitationRequest ): CreateInvitationRequest.Response { - val response = base.invitationsCreatePost( - createInvitationRequest = GeneratedCreateInvitationRequest( - meetingId = request.meetingId.string, - userId = request.userId.string - ), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ).result + val url = baseUrl / "create" + + val jsonObject = buildJsonObject { + put("meetingId", request.meetingId.string) + put("userId", request.userId.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + val response = json.decodeFromString(string).result return CreateInvitationRequest.Response(response.toInvitation()) } suspend fun accept( request: AcceptInvitationRequest - ) { - base.invitationsAcceptPost( - acceptInvitationRequest = GeneratedAcceptInvitationRequest( - id = request.invitationId.string - ), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ) + ): StatusTrueResponse { + val url = baseUrl / "accept" + + val jsonObject = buildJsonObject { + put("invitationId", request.invitationId.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + return json.decodeFromString(string) } suspend fun deny( request: DenyInvitationRequest - ) { - base.invitationsDenyPost( - denyInvitationRequest = GeneratedDenyInvitationRequest( - id = request.invitationId.string - ), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ) + ): StatusTrueResponse { + val url = baseUrl / "deny" + + val jsonObject = buildJsonObject { + put("invitationId", request.invitationId.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + return json.decodeFromString(string) } suspend fun cancel( request: CancelInvitationRequest - ) { - base.invitationsCancelPost( - cancelInvitationRequest = GeneratedCancelInvitationRequest( - id = request.invitationId.string - ), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ) + ): StatusTrueResponse { + val url = baseUrl / "cancel" + + val jsonObject = buildJsonObject { + put("invitationId", request.invitationId.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + return json.decodeFromString(string) } } 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 fe6eab26..2152b7f0 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 @@ -3,18 +3,21 @@ 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.requests.extencion.post +import app.meetacy.sdk.engine.ktor.response.models.* 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.ListMapMeetingsResponse +import app.meetacy.sdk.engine.ktor.response.models.ListMeetingParticipantsResponse import app.meetacy.sdk.engine.ktor.response.models.ListMeetingsResponse -import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse +import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser 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.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.* @@ -24,19 +27,18 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import kotlinx.serialization.json.putJsonObject -import app.meetacy.sdk.engine.ktor.response.models.Meeting as LolMeeting -import dev.icerock.moko.network.generated.models.Meeting as GeneratedMeeting +import app.meetacy.sdk.engine.ktor.response.models.Meeting as ModelMeeting internal class MeetingsEngine( - private val baseUrl: Url, + baseUrl: Url, private val httpClient: HttpClient, - json: Json + private val json: Json ) { - + private val baseUrl = baseUrl / "meetings" suspend fun listMeetingsHistory( request: ListMeetingsHistoryRequest ): ListMeetingsHistoryRequest.Response = with(request) { - val url = baseUrl / "meetings" / "history" / "list" + val url = baseUrl / "history" / "list" val jsonObject = buildJsonObject { put("amount", amount.int.toString()) @@ -45,11 +47,11 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(LolMeeting::mapToMeeting) + data = response.data.map(ModelMeeting::mapToMeeting) ) return ListMeetingsHistoryRequest.Response(paging) @@ -58,7 +60,7 @@ internal class MeetingsEngine( suspend fun listActiveMeetings( request: ListActiveMeetingsRequest ): ListActiveMeetingsRequest.Response = with(request) { - val url = baseUrl / "meetings" / "history" / "active" + val url = baseUrl / "history" / "active" val jsonObject = buildJsonObject { put("amount", amount.int.toString()) @@ -76,11 +78,11 @@ internal class MeetingsEngine( header("Api-Version", request.apiVersion.int.toString()) }.body() - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(LolMeeting::mapToMeeting) + data = response.data.map(ModelMeeting::mapToMeeting) ) return ListActiveMeetingsRequest.Response(paging) @@ -89,7 +91,7 @@ internal class MeetingsEngine( suspend fun listPastMeetings( request: ListPastMeetingsRequest ): ListPastMeetingsRequest.Response = with(request) { - val url = baseUrl / "meetings" / "history" / "past" + val url = baseUrl / "history" / "past" val jsonObject = buildJsonObject { put("amount", amount.int.toString()) @@ -98,11 +100,11 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( nextPagingId = response.nextPagingId?.let(::PagingId), - data = response.data.map(LolMeeting::mapToMeeting) + data = response.data.map(ModelMeeting::mapToMeeting) ) return ListPastMeetingsRequest.Response(paging) @@ -111,7 +113,7 @@ internal class MeetingsEngine( suspend fun listMeetingsMap( request: ListMeetingsMapRequest ): ListMeetingsMapRequest.Response = with (request) { - val url = baseUrl / "meetings" / "map" / "list" + val url = baseUrl / "map" / "list" val jsonObject = buildJsonObject { putJsonObject("location") { @@ -121,17 +123,17 @@ internal class MeetingsEngine( } val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result - val data = response.map(GeneratedMeeting::mapToMeeting) + val data = response.map(ModelMeeting::mapToMeeting) return ListMeetingsMapRequest.Response(data) } suspend fun createMeeting( request: CreateMeetingRequest - ): CreateMeetingRequest.Response = with(request){ - val url = baseUrl / "meetings" / "create" + ): CreateMeetingRequest.Response = with(request) { + val url = baseUrl / "create" val jsonObject = buildJsonObject { put("title", title) @@ -147,13 +149,13 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val meeting = Json.decodeFromString(string).result + val meeting = json.decodeFromString(string).result return CreateMeetingRequest.Response(meeting.mapToMeeting()) } suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) { - val url = baseUrl / "meetings" / "edit" + val url = baseUrl / "edit" val jsonObject = buildJsonObject { put("meetingId", meetingId.string) @@ -183,7 +185,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val meeting = Json.decodeFromString(string).result + val meeting = json.decodeFromString(string).result return EditMeetingRequest.Response(meeting.mapToMeeting()) } @@ -191,7 +193,7 @@ internal class MeetingsEngine( suspend fun listMeetingParticipants( request: ListMeetingParticipantsRequest ): ListMeetingParticipantsRequest.Response { - val url = baseUrl / "meetings" / "participants" / "list" + val url = baseUrl / "participants" / "list" val jsonObject = buildJsonObject { put("meetingId", request.meetingId.string) @@ -201,10 +203,10 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result val paging = PagingResponse( - data = response.data.map(User::mapToUser), + data = response.data.map(ModelUser::mapToUser), nextPagingId = response.nextPagingId?.let(::PagingId) ) @@ -212,7 +214,7 @@ internal class MeetingsEngine( } suspend fun participateMeeting(request: ParticipateMeetingRequest): StatusTrueResponse { - val url = baseUrl / "meetings" / "participate" + val url = baseUrl / "participate" val jsonObject = buildJsonObject { put("meetingId", request.meetingId.string) @@ -224,7 +226,7 @@ internal class MeetingsEngine( } suspend fun getMeeting(request: GetMeetingRequest): GetMeetingRequest.Response { - val url = baseUrl / "meetings" / "get" + val url = baseUrl / "get" val jsonObject = buildJsonObject { put("meetingId", request.meetingId.string) @@ -232,7 +234,7 @@ internal class MeetingsEngine( val string = post(url.string, jsonObject, httpClient, request) - val response = Json.decodeFromString(string).result + val response = json.decodeFromString(string).result val meeting = response.mapToMeeting() diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt index f7c9c627..c1364e64 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/notifications/NotificationsEngine.kt @@ -1,35 +1,39 @@ package app.meetacy.sdk.engine.ktor.requests.notifications import app.meetacy.sdk.engine.ktor.mapToNotification +import app.meetacy.sdk.engine.ktor.requests.extencion.post +import app.meetacy.sdk.engine.ktor.response.models.ListNotificationsResponse +import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse import app.meetacy.sdk.engine.requests.ListNotificationsRequest import app.meetacy.sdk.engine.requests.ReadNotificationRequest 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.NotificationsApiImpl import io.ktor.client.* import kotlinx.serialization.json.Json -import dev.icerock.moko.network.generated.models.ListNotificationsRequest as GeneratedListNotificationsRequest -import dev.icerock.moko.network.generated.models.ReadNotificationRequest as GeneratedReadNotificationRequest +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put internal class NotificationsEngine( baseUrl: Url, - httpClient: HttpClient, - json: Json + private val httpClient: HttpClient, + private val json: Json ) { - private val base = NotificationsApiImpl(baseUrl.string, httpClient, json) + private val baseUrl = baseUrl / "notifications" suspend fun list( request: ListNotificationsRequest ): ListNotificationsRequest.Response = with (request) { - val response = base.notificationsListPost( - listNotificationsRequest = GeneratedListNotificationsRequest( - amount = amount.int, - pagingId = pagingId?.string - ), - apiVersion = apiVersion.int.toString(), - authorization = request.token.string - ).result + val url = baseUrl / "list" + + val jsonObject = buildJsonObject { + put("amount", amount.int.toString()) + put("pagingId", pagingId?.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + val response = json.decodeFromString(string).result val paging = PagingResponse( data = response.data.map { it.mapToNotification() }, @@ -39,13 +43,15 @@ internal class NotificationsEngine( ListNotificationsRequest.Response(paging) } - suspend fun read(request: ReadNotificationRequest) = with (request) { - base.notificationsReadPost( - readNotificationRequest = GeneratedReadNotificationRequest( - lastNotificationId = lastNotificationId.string - ), - apiVersion = apiVersion.int.toString(), - authorization = token.string - ) + suspend fun read(request: ReadNotificationRequest): StatusTrueResponse = with (request) { + val url = baseUrl / "read" + + val jsonObject = buildJsonObject { + put("lastNotificationId", request.lastNotificationId.string) + } + + val string = post(url.string, jsonObject, httpClient, request) + + return json.decodeFromString(string) } } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt index 5e4a86ab..8b7eb3fe 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/updates/UpdatesEngine.kt @@ -1,11 +1,9 @@ package app.meetacy.sdk.engine.ktor.requests.updates -import app.meetacy.sdk.engine.ktor.exception.getException import app.meetacy.sdk.engine.ktor.handleRSocketExceptions import app.meetacy.sdk.engine.ktor.mapToNotification -import app.meetacy.sdk.engine.ktor.response.ServerResponse -import app.meetacy.sdk.engine.ktor.response.decodeToEmptyServerResponse import app.meetacy.sdk.engine.requests.EmitUpdatesRequest +import app.meetacy.sdk.engine.ktor.response.models.Notification as ModelNotification import app.meetacy.sdk.types.update.Update import app.meetacy.sdk.types.update.UpdateId import app.meetacy.sdk.types.url.Url @@ -15,16 +13,13 @@ import io.rsocket.kotlin.payload.Payload import io.rsocket.kotlin.payload.buildPayload import io.rsocket.kotlin.payload.data import kotlinx.coroutines.flow.emitAll -import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -import dev.icerock.moko.network.generated.models.Notification as GeneratedNotification internal class UpdatesEngine( private val baseUrl: Url, @@ -69,7 +64,7 @@ private sealed interface UpdateSerializable { @Serializable data class Notification( override val id: String, - val notification: GeneratedNotification + val notification: ModelNotification ) : UpdateSerializable } diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt index cf0fb02a..d0b5d063 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/users/UsersEngine.kt @@ -2,6 +2,10 @@ package app.meetacy.sdk.engine.ktor.requests.users import app.meetacy.sdk.engine.ktor.mapToSelfUser import app.meetacy.sdk.engine.ktor.mapToUser +import app.meetacy.sdk.engine.ktor.requests.extencion.post +import app.meetacy.sdk.engine.ktor.requests.extencion.postWithoutToken +import app.meetacy.sdk.engine.ktor.response.models.GetUserResponse +import app.meetacy.sdk.engine.ktor.response.models.ValidateUsernameRequest import app.meetacy.sdk.engine.requests.EditUserRequest import app.meetacy.sdk.engine.requests.GetMeRequest import app.meetacy.sdk.engine.requests.GetUserRequest @@ -12,9 +16,6 @@ import app.meetacy.sdk.types.optional.ifPresent import app.meetacy.sdk.types.url.Url import app.meetacy.sdk.types.user.SelfUser import app.meetacy.sdk.types.user.Username -import dev.icerock.moko.network.generated.apis.UserApi -import dev.icerock.moko.network.generated.apis.UserApiImpl -import dev.icerock.moko.network.generated.models.EditUserResponse import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* @@ -23,22 +24,25 @@ import io.ktor.http.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -import dev.icerock.moko.network.generated.models.GetUserRequest as GeneratedGetUserRequest -import dev.icerock.moko.network.generated.models.ValidateUsernameRequest as GeneratedValidateUsernameRequest +import app.meetacy.sdk.engine.ktor.response.models.GetUserRequest as ModelGetUserRequest internal class UsersEngine( - private val baseUrl: Url, + baseUrl: Url, private val httpClient: HttpClient, - json: Json + private val json: Json ) { - private val base: UserApi = UserApiImpl(baseUrl.string, httpClient, json) + private val baseUrl = baseUrl / "users" suspend fun getMe(request: GetMeRequest): GetMeRequest.Response { - val response = base.usersGetPost( - getUserRequest = GeneratedGetUserRequest(), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ) + val url = baseUrl / "get" + + val jsonObject = buildJsonObject { + put("id", ModelGetUserRequest().id) + } + + val string = post(url.string, jsonObject, httpClient, request) + + val response = json.decodeFromString(string) return GetMeRequest.Response( (response.result?.mapToUser() ?: meetacyApiError("'result' should present")) @@ -47,13 +51,17 @@ internal class UsersEngine( } suspend fun getUser(request: GetUserRequest): GetUserRequest.Response { - val response = base.usersGetPost( - getUserRequest = GeneratedGetUserRequest( - id = request.userId.string, - ), - apiVersion = request.apiVersion.int.toString(), - authorization = request.token.string - ) + val url = baseUrl / "get" + + val jsonObject = buildJsonObject { + put("id", ModelGetUserRequest( + request.userId.string + ).id) + } + + val string = post(url.string, jsonObject, httpClient, request) + + val response = json.decodeFromString(string) return GetUserRequest.Response( response.result?.mapToUser() ?: meetacyApiError("'result' should present") @@ -93,12 +101,15 @@ internal class UsersEngine( @OptIn(UnsafeConstructor::class) suspend fun usernameAvailable(request: UsernameAvailableRequest): UsernameAvailableRequest.Response { - val response = base.usersValidatePost( - validateUsernameRequest = GeneratedValidateUsernameRequest( - username = request.username.string - ), - apiVersion = request.apiVersion.int.toString() - ) + val url = baseUrl / "username" / "validate" + + val jsonObject = buildJsonObject { + put("username", request.username.string) + } + + val string = postWithoutToken(url.string, jsonObject, httpClient, request) + + val response = json.decodeFromString(string) return UsernameAvailableRequest.Response(username = Username(response.username)) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt index 8b436028..59933cf6 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/AcceptInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class AcceptInvitationRequest( - public val token: Token, + public override val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest +): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt index 49a0ab05..064f9c3e 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CancelInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class CancelInvitationRequest( - public val token: Token, + public override val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest +): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt index 32a96d00..d78f6b6c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/CreateInvitationRequest.kt @@ -1,16 +1,14 @@ package app.meetacy.sdk.engine.requests import app.meetacy.sdk.types.auth.Token -import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.invitation.Invitation import app.meetacy.sdk.types.meeting.MeetingId -import app.meetacy.sdk.types.user.User import app.meetacy.sdk.types.user.UserId public data class CreateInvitationRequest( - val token: Token, + override val token: Token, val userId: UserId, val meetingId: MeetingId -) : MeetacyRequest { +) : MeetacyRequest, MeetacyRequestWithToken { public data class Response(val invitation: Invitation) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt index eb48c074..edc0897c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/DenyInvitationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.invitation.InvitationId public class DenyInvitationRequest( - public val token: Token, + public override val token: Token, public val invitationId: InvitationId -): SimpleMeetacyRequest +): SimpleMeetacyRequest, SimpleMeetacyRequestWithToken diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt index 1eb709cc..cc11c405 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetMeRequest.kt @@ -3,6 +3,8 @@ package app.meetacy.sdk.engine.requests import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.user.SelfUser -public data class GetMeRequest(val token: Token): MeetacyRequest { +public data class GetMeRequest( + override val token: Token +): MeetacyRequest, MeetacyRequestWithToken { public data class Response(val me: SelfUser) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt index 5aec5da4..9ab53e3a 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt @@ -5,9 +5,9 @@ import app.meetacy.sdk.types.user.User import app.meetacy.sdk.types.user.UserId public data class GetUserRequest( - val token: Token, + override val token: Token, val userId: UserId -) : MeetacyRequest { +) : MeetacyRequest, MeetacyRequestWithToken { public data class Response( val user: User ) diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt index b04163fb..cb8f8026 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListNotificationsRequest.kt @@ -7,9 +7,9 @@ import app.meetacy.sdk.types.paging.PagingId import app.meetacy.sdk.types.paging.PagingResponse public data class ListNotificationsRequest( - val token: Token, + override val token: Token, val amount: Amount, val pagingId: PagingId? -) : MeetacyRequest { +) : MeetacyRequest, MeetacyRequestWithToken { public data class Response(val paging: PagingResponse) } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt index b7d677d8..6115b412 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ReadNotificationRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.notification.NotificationId public data class ReadNotificationRequest( - val token: Token, + override val token: Token, val lastNotificationId: NotificationId -) : SimpleMeetacyRequest +) : SimpleMeetacyRequest, SimpleMeetacyRequestWithToken diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt index a54626f4..e62d01b9 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/UsernameAvailableRequest.kt @@ -4,6 +4,6 @@ import app.meetacy.sdk.types.user.Username public data class UsernameAvailableRequest( val username: Username -) : MeetacyRequest { +) : MeetacyRequest, TokenProviderEmpty { public data class Response(val username: Username) }