-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added user details and subscribers
- Loading branch information
Showing
25 changed files
with
584 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/GetUserRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package app.meetacy.sdk.engine.requests | ||
|
||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.user.User | ||
import app.meetacy.sdk.types.user.UserDetails | ||
import app.meetacy.sdk.types.user.UserId | ||
|
||
public data class GetUserRequest( | ||
val token: Token, | ||
val userId: UserId? | ||
) : MeetacyRequest<GetUserRequest.Response> { | ||
public data class Response( | ||
val user: User | ||
) | ||
public data class Response(val user: UserDetails) | ||
} |
48 changes: 48 additions & 0 deletions
48
api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedRegularUserDetailsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app.meetacy.sdk.users | ||
|
||
import app.meetacy.sdk.AuthorizedMeetacyApi | ||
import app.meetacy.sdk.MeetacyApi | ||
import app.meetacy.sdk.files.FileRepository | ||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.user.* | ||
|
||
public class AuthorizedRegularUserDetailsRepository( | ||
override val data: RegularUserDetails, | ||
private val api: AuthorizedMeetacyApi | ||
) : AuthorizedUserDetailsRepository { | ||
override val base: RegularUserDetailsRepository get() = RegularUserDetailsRepository(data, api.base) | ||
|
||
override val id: UserId get() = data.id | ||
override val nickname: String get() = data.nickname | ||
override val avatar: FileRepository? get() = FileRepository(data.avatarId, api) | ||
override val relationship: Relationship get() = data.relationship | ||
override val username: Username? get() = data.username | ||
override val subscribersAmount: Amount.OrZero get() = data.subscribersAmount | ||
override val subscriptionsAmount: Amount.OrZero get() = data.subscriptionsAmount | ||
|
||
override val isSelf: Boolean get() = false | ||
override val email: Nothing? get() = null | ||
override val emailVerified: Nothing? get() = null | ||
|
||
public suspend fun addFriend() { | ||
api.friends.add(data.id) | ||
} | ||
|
||
public suspend fun deleteFriend() { | ||
api.friends.delete(data.id) | ||
} | ||
|
||
public suspend fun usernameAvailable(username: Username): Username { | ||
return api.users.usernameAvailable(username) | ||
} | ||
|
||
override suspend fun updated(): AuthorizedRegularUserDetailsRepository { | ||
// Cast is fine since we already know that user associated with that id is regular | ||
return api.users.get(id) as AuthorizedRegularUserDetailsRepository | ||
} | ||
|
||
override fun toUser(): AuthorizedRegularUserRepository { | ||
return AuthorizedRegularUserRepository(data.toUser(), api) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedSelfUserDetailsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package app.meetacy.sdk.users | ||
|
||
import app.meetacy.sdk.AuthorizedMeetacyApi | ||
import app.meetacy.sdk.MeetacyApi | ||
import app.meetacy.sdk.auth.AuthApi | ||
import app.meetacy.sdk.auth.AuthorizedAuthApi | ||
import app.meetacy.sdk.files.AuthorizedFilesApi | ||
import app.meetacy.sdk.files.FileRepository | ||
import app.meetacy.sdk.files.FilesApi | ||
import app.meetacy.sdk.friends.AuthorizedFriendsApi | ||
import app.meetacy.sdk.friends.FriendsApi | ||
import app.meetacy.sdk.invitations.AuthorizedInvitationsApi | ||
import app.meetacy.sdk.invitations.InvitationsApi | ||
import app.meetacy.sdk.meetings.AuthorizedMeetingsApi | ||
import app.meetacy.sdk.meetings.MeetingsApi | ||
import app.meetacy.sdk.notifications.AuthorizedNotificationsApi | ||
import app.meetacy.sdk.notifications.NotificationsApi | ||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.email.Email | ||
import app.meetacy.sdk.types.file.FileId | ||
import app.meetacy.sdk.types.optional.Optional | ||
import app.meetacy.sdk.types.user.SelfUserDetails | ||
import app.meetacy.sdk.types.user.UserId | ||
import app.meetacy.sdk.types.user.Username | ||
import app.meetacy.sdk.updates.AuthorizedUpdatesApi | ||
import app.meetacy.sdk.updates.UpdatesApi | ||
|
||
public class AuthorizedSelfUserDetailsRepository( | ||
override val data: SelfUserDetails, | ||
public val api: AuthorizedMeetacyApi | ||
) : AuthorizedUserDetailsRepository { | ||
override val base: SelfUserDetailsRepository get() = SelfUserDetailsRepository(data, api.base) | ||
|
||
override val id: UserId get() = data.id | ||
override val email: Email? get() = data.email | ||
override val nickname: String get() = data.nickname | ||
override val emailVerified: Boolean get() = data.emailVerified | ||
override val username: Username? get() = data.username | ||
override val avatar: FileRepository? get() = FileRepository(data.avatarId, api) | ||
override val subscribersAmount: Amount.OrZero get() = data.subscribersAmount | ||
override val subscriptionsAmount: Amount.OrZero get() = data.subscriptionsAmount | ||
|
||
override val isSelf: Boolean get() = true | ||
override val relationship: Nothing? get() = null | ||
|
||
public val token: Token get() = api.token | ||
public val files: AuthorizedFilesApi get() = api.files | ||
public val auth: AuthorizedAuthApi get() = api.auth | ||
public val friends: AuthorizedFriendsApi get() = api.friends | ||
public val users: AuthorizedUsersApi get() = api.users | ||
public val meetings: AuthorizedMeetingsApi get() = api.meetings | ||
public val invitations: AuthorizedInvitationsApi get() = api.invitations | ||
public val notifications: AuthorizedNotificationsApi get() = api.notifications | ||
public val updates: AuthorizedUpdatesApi get() = api.updates | ||
|
||
public suspend fun edited( | ||
nickname: String, | ||
username: Username?, | ||
avatarId: FileId? | ||
): AuthorizedSelfUserRepository = api.users.edit(nickname, username, avatarId) | ||
|
||
public suspend fun edited( | ||
nickname: Optional<String> = Optional.Undefined, | ||
username: Optional<Username?> = Optional.Undefined, | ||
avatarId: Optional<FileId?> = Optional.Undefined | ||
): AuthorizedSelfUserRepository = api.users.edit(nickname, username, avatarId) | ||
|
||
public suspend fun usernameAvailable(username: Username): Username { | ||
return api.users.usernameAvailable(username) | ||
} | ||
|
||
override suspend fun updated(): AuthorizedSelfUserDetailsRepository { | ||
return api.getMe() | ||
} | ||
|
||
override fun toUser(): AuthorizedSelfUserRepository { | ||
return AuthorizedSelfUserRepository(data.toUser(), api) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUserDetailsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package app.meetacy.sdk.users | ||
|
||
import app.meetacy.sdk.AuthorizedMeetacyApi | ||
import app.meetacy.sdk.files.FileRepository | ||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.email.Email | ||
import app.meetacy.sdk.types.user.* | ||
|
||
public sealed interface AuthorizedUserDetailsRepository { | ||
public val data: UserDetails | ||
public val base: UserDetailsRepository | ||
|
||
public val isSelf: Boolean | ||
public val relationship: Relationship? | ||
public val id: UserId | ||
public val nickname: String | ||
public val username: Username? | ||
public val email: Email? | ||
public val emailVerified: Boolean? | ||
public val avatar: FileRepository? | ||
public val subscribersAmount: Amount.OrZero | ||
public val subscriptionsAmount: Amount.OrZero | ||
|
||
public fun toUser(): AuthorizedUserRepository | ||
public suspend fun updated(): AuthorizedUserDetailsRepository | ||
|
||
public companion object { | ||
public fun of( | ||
data: UserDetails, | ||
api: AuthorizedMeetacyApi | ||
): AuthorizedUserDetailsRepository = when (data) { | ||
is RegularUserDetails -> AuthorizedRegularUserDetailsRepository(data, api) | ||
is SelfUserDetails -> AuthorizedSelfUserDetailsRepository(data, api) | ||
} | ||
} | ||
} |
17 changes: 14 additions & 3 deletions
17
api/src/commonMain/kotlin/app/meetacy/sdk/users/AuthorizedUserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.