Skip to content

Commit

Permalink
fix(#93-add-getSubscriptions-and-getSubscribers-methods): change user…
Browse files Browse the repository at this point in the history
… type to UserDetails
  • Loading branch information
y9Kap committed Mar 7, 2024
1 parent 58487fa commit b8067e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ 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.type
import app.meetacy.sdk.types.serializable.paging.PagingIdSerializable
import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable
import app.meetacy.sdk.types.serializable.paging.serializable
import app.meetacy.sdk.types.serializable.paging.type
import app.meetacy.sdk.types.serializable.user.UserIdSerializable
import app.meetacy.sdk.types.serializable.user.UserSerializable
import app.meetacy.sdk.types.serializable.user.serializable
import app.meetacy.sdk.types.serializable.user.type
import app.meetacy.sdk.types.serializable.user.*
import app.meetacy.sdk.types.url.Url
import app.meetacy.sdk.types.user.RegularUser
import app.meetacy.sdk.types.user.UserLocationSnapshot
Expand Down Expand Up @@ -108,9 +105,9 @@ internal class FriendsEngine(
parameter("id", request.userId?.string)
parameter("amount", request.amount.int)
parameter("pagingId", request.pagingId?.string)
}.bodyAsSuccess<PagingResponseSerializable<UserSerializable>>()
}.bodyAsSuccess<PagingResponseSerializable<UserDetailsSerializable>>()
.type()
.mapItems { user -> user.type() as RegularUser }
.mapItems { userDetails -> userDetails.type() }

return GetSubscriptionsRequest.Response(response)
}
Expand All @@ -124,9 +121,9 @@ internal class FriendsEngine(
parameter("id", request.userId?.string)
parameter("amount", request.amount.int)
parameter("pagingId", request.pagingId?.string)
}.bodyAsSuccess<PagingResponseSerializable<UserSerializable>>()
}.bodyAsSuccess<PagingResponseSerializable<UserDetailsSerializable>>()
.type()
.mapItems { user -> user.type() as RegularUser }
.mapItems { userDetails -> userDetails.type() }

return GetSubscribersRequest.Response(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.meetacy.sdk.types.amount.Amount
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingResponse
import app.meetacy.sdk.types.user.RegularUser
import app.meetacy.sdk.types.user.UserDetails
import app.meetacy.sdk.types.user.UserId

public data class GetSubscribersRequest(
Expand All @@ -13,5 +13,5 @@ public data class GetSubscribersRequest(
val pagingId: PagingId?,
val userId: UserId?,
) : MeetacyRequest<GetSubscriptionsRequest.Response> {
public data class Response(val paging: PagingResponse<RegularUser>)
public data class Response(val paging: PagingResponse<UserDetails>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.meetacy.sdk.types.amount.Amount
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingResponse
import app.meetacy.sdk.types.user.RegularUser
import app.meetacy.sdk.types.user.UserDetails
import app.meetacy.sdk.types.user.UserId

public data class GetSubscriptionsRequest(
Expand All @@ -13,5 +13,5 @@ public data class GetSubscriptionsRequest(
val pagingId: PagingId?,
val userId: UserId?,
) : MeetacyRequest<GetSubscriptionsRequest.Response> {
public data class Response(val paging: PagingResponse<RegularUser>)
public data class Response(val paging: PagingResponse<UserDetails>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import app.meetacy.sdk.AuthorizedMeetacyApi
import app.meetacy.sdk.friends.location.AuthorizedFriendsLocationApi
import app.meetacy.sdk.types.amount.Amount
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.paging.*
import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingRepository
import app.meetacy.sdk.types.paging.PagingSource
import app.meetacy.sdk.types.paging.mapItems
import app.meetacy.sdk.types.user.UserId
import app.meetacy.sdk.users.AuthorizedRegularUserRepository
import app.meetacy.sdk.users.AuthorizedUserDetailsRepository

/**
* When modifying this class, corresponding classes should be altered:
Expand Down Expand Up @@ -40,24 +44,18 @@ public class AuthorizedFriendsApi(private val api: AuthorizedMeetacyApi) {
amount: Amount,
pagingId: PagingId? = null,
userId: UserId? = null
): PagingRepository<AuthorizedRegularUserRepository> =
): PagingRepository<AuthorizedUserDetailsRepository> =
base.subscriptions(token, amount, pagingId, userId).mapItems { user ->
AuthorizedRegularUserRepository(
data = user.data,
api = api
)
AuthorizedUserDetailsRepository.of(user.data, api)
}

public suspend fun subscribers(
amount: Amount,
pagingId: PagingId? = null,
userId: UserId? = null
): PagingRepository<AuthorizedRegularUserRepository> =
base.subscribers(token, amount, pagingId, userId).mapItems { user ->
AuthorizedRegularUserRepository(
data = user.data,
api = api
)
): PagingRepository<AuthorizedUserDetailsRepository> =
base.subscriptions(token, amount, pagingId, userId).mapItems { user ->
AuthorizedUserDetailsRepository.of(user.data, api)
}

public fun paging(
Expand Down
19 changes: 11 additions & 8 deletions api/src/commonMain/kotlin/app/meetacy/sdk/friends/FriendsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package app.meetacy.sdk.friends
import app.meetacy.sdk.MeetacyApi
import app.meetacy.sdk.engine.requests.*
import app.meetacy.sdk.friends.location.FriendsLocationApi
import app.meetacy.sdk.users.RegularUserRepository
import app.meetacy.sdk.types.amount.Amount
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.paging.*
import app.meetacy.sdk.types.paging.PagingId
import app.meetacy.sdk.types.paging.PagingRepository
import app.meetacy.sdk.types.paging.PagingSource
import app.meetacy.sdk.types.user.UserId
import app.meetacy.sdk.users.RegularUserRepository
import app.meetacy.sdk.users.UserDetailsRepository

/**
* When modifying this class, corresponding classes should be altered:
Expand Down Expand Up @@ -47,7 +50,7 @@ public class FriendsApi(private val api: MeetacyApi) {
amount: Amount,
pagingId: PagingId? = null,
userId: UserId? = null
): PagingRepository<RegularUserRepository> = PagingRepository(
): PagingRepository<UserDetailsRepository> = PagingRepository(
amount = amount,
startPagingId = pagingId
) { currentAmount, currentPagingId ->
Expand All @@ -58,8 +61,8 @@ public class FriendsApi(private val api: MeetacyApi) {
amount = currentAmount,
pagingId = currentPagingId
)
).paging.mapItems { regularUser ->
RegularUserRepository(regularUser, api)
).paging.mapItems { userDetails ->
UserDetailsRepository.of(userDetails, api)
}
}

Expand All @@ -68,7 +71,7 @@ public class FriendsApi(private val api: MeetacyApi) {
amount: Amount,
pagingId: PagingId? = null,
userId: UserId? = null,
): PagingRepository<RegularUserRepository> = PagingRepository(
): PagingRepository<UserDetailsRepository> = PagingRepository(
amount = amount,
startPagingId = pagingId
) { currentAmount, currentPagingId ->
Expand All @@ -79,8 +82,8 @@ public class FriendsApi(private val api: MeetacyApi) {
amount = currentAmount,
pagingId = currentPagingId
)
).paging.mapItems { regularUser ->
RegularUserRepository(regularUser, api)
).paging.mapItems { userDetails ->
UserDetailsRepository.of(userDetails, api)
}
}

Expand Down

0 comments on commit b8067e4

Please sign in to comment.