Skip to content

Commit

Permalink
feat: added push location method
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Mar 8, 2024
1 parent d6b6b1b commit 64e999c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ 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
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
Expand Down Expand Up @@ -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<StatusTrueResponse>()
}
}

private fun EmitFriendsLocationRequest.encodeToPayload(json: Json): Payload = buildPayload {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ public class AuthorizedFriendsLocationApi(
public val base: FriendsLocationApi get() = api.base.friends.location

public fun flow(selfLocation: Flow<Location>): Flow<AuthorizedUserLocationSnapshotRepository> {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,4 +36,11 @@ public class FriendsLocationApi(
capturedAt = userOnMap.capturedAt
)
}

public suspend fun push(
token: Token,
location: Location
) {
api.engine.execute(PushLocationRequest(token, location))
}
}
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.65"
meetacySdk = "0.0.66"

# kotlinx
kotlinxCoroutines = "1.6.4"
Expand Down

0 comments on commit 64e999c

Please sign in to comment.