diff --git a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt index 425db344..6f08f8a1 100644 --- a/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt +++ b/api/api-ktor/src/commonMain/kotlin/app/meetacy/sdk/engine/ktor/KtorMeetacyEngine.kt @@ -125,6 +125,7 @@ public class KtorMeetacyEngine( is DeleteFriendRequest -> friends.delete(request) as T is ListFriendsRequest -> friends.list(request) as T is EmitFriendsLocationRequest -> friends.streamFriendsLocation(request) as T + is PushLocationRequest -> friends.pushLocation(request) as T // users is GetMeRequest -> users.getMe(request) as T is GetUserByIdRequest -> users.getUserById(request) as T 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 b0b566c6..100fa1db 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 @@ -7,10 +7,7 @@ import app.meetacy.sdk.engine.ktor.handleRSocketExceptions 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.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.engine.requests.* import app.meetacy.sdk.types.annotation.UnsafeConstructor import app.meetacy.sdk.types.datetime.DateTime import app.meetacy.sdk.types.location.Location @@ -18,6 +15,7 @@ import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable import app.meetacy.sdk.types.serializable.amount.AmountSerializable import app.meetacy.sdk.types.serializable.amount.serializable import app.meetacy.sdk.types.serializable.location.LocationSerializable +import app.meetacy.sdk.types.serializable.location.serializable import app.meetacy.sdk.types.serializable.location.type import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable import app.meetacy.sdk.types.serializable.paging.serializable @@ -121,6 +119,20 @@ internal class FriendsEngine( request.collector.emitAll(flow) } + + @Serializable + private data class PushLocationBody(val location: LocationSerializable) + private fun PushLocationRequest.toBody() = PushLocationBody(location.serializable()) + + suspend fun pushLocation(request: PushLocationRequest) { + val url = baseUrl / "location" / "push" + val body = request.toBody() + httpClient.post(url.string) { + apiVersion(request.apiVersion) + token(request.token) + setBody(body) + }.body() + } } private fun EmitFriendsLocationRequest.encodeToPayload(json: Json): Payload = buildPayload { diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/PushLocationRequest.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/PushLocationRequest.kt new file mode 100644 index 00000000..aefbcd83 --- /dev/null +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/PushLocationRequest.kt @@ -0,0 +1,9 @@ +package app.meetacy.sdk.engine.requests + +import app.meetacy.sdk.types.auth.Token +import app.meetacy.sdk.types.location.Location + +public data class PushLocationRequest( + val token: Token, + val location: Location +) : SimpleMeetacyRequest diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/AuthorizedFriendsLocationApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/AuthorizedFriendsLocationApi.kt index 953b5658..4e5c99bc 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/AuthorizedFriendsLocationApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/AuthorizedFriendsLocationApi.kt @@ -14,17 +14,19 @@ public class AuthorizedFriendsLocationApi( public val base: FriendsLocationApi get() = api.base.friends.location public fun flow(selfLocation: Flow): Flow { - return api.base.friends.location - .flow(api.token, selfLocation) - .map { userOnMap -> - AuthorizedUserLocationSnapshotRepository( - user = AuthorizedRegularUserRepository( - data = userOnMap.user.data, - api = api - ), - location = userOnMap.location, - capturedAt = userOnMap.capturedAt - ) - } + return base.flow(api.token, selfLocation).map { userOnMap -> + AuthorizedUserLocationSnapshotRepository( + user = AuthorizedRegularUserRepository( + data = userOnMap.user.data, + api = api + ), + location = userOnMap.location, + capturedAt = userOnMap.capturedAt + ) + } + } + + public suspend fun push(location: Location) { + base.push(token, location) } } diff --git a/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/FriendsLocationApi.kt b/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/FriendsLocationApi.kt index b8a0f74f..edb8a81c 100644 --- a/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/FriendsLocationApi.kt +++ b/api/src/commonMain/kotlin/app/meetacy/sdk/friends/location/FriendsLocationApi.kt @@ -2,6 +2,7 @@ package app.meetacy.sdk.friends.location import app.meetacy.sdk.MeetacyApi import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest +import app.meetacy.sdk.engine.requests.PushLocationRequest import app.meetacy.sdk.types.auth.Token import app.meetacy.sdk.types.location.Location import app.meetacy.sdk.users.RegularUserRepository @@ -35,4 +36,11 @@ public class FriendsLocationApi( capturedAt = userOnMap.capturedAt ) } + + public suspend fun push( + token: Token, + location: Location + ) { + api.engine.execute(PushLocationRequest(token, location)) + } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 09bbd809..3ac54514 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.9.0" ktor = "2.3.6" -meetacySdk = "0.0.65" +meetacySdk = "0.0.66" # kotlinx kotlinxCoroutines = "1.6.4"