From 2e6f1991053b561042f0f4ff10b82592f46137fb Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Tue, 19 Mar 2024 16:06:25 +0100 Subject: [PATCH] fix: mappers --- .../api/rsocket/authorizations/AuthMappers.kt | 12 ++++++------ .../GetAuthorizationSessionsCommand.kt | 2 +- .../commands/StartAuthorizationCommand.kt | 2 +- .../api/rsocket/timers/TimerMappers.kt | 18 +++++++++++------- .../timers/commands/CreateTimerCommand.kt | 2 +- .../timers/commands/GetUserTimersCommand.kt | 2 +- .../members/commands/GetTimerMembersCommand.kt | 2 +- .../invites/commands/CreateInviteCommand.kt | 2 +- .../invites/commands/GetInvitesCommand.kt | 2 +- .../timemates/api/rsocket/users/UsersMapper.kt | 10 +++++----- 10 files changed, 29 insertions(+), 25 deletions(-) diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/AuthMappers.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/AuthMappers.kt index e34a543..a301541 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/AuthMappers.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/AuthMappers.kt @@ -15,9 +15,9 @@ import org.timemates.sdk.authorization.sessions.types.Authorization as SdkAuth internal fun Metadata.sdk(): SdkAuth.Metadata { return SdkAuth.Metadata( - applicationName = ApplicationName.createOrThrow(clientName), - clientVersion = ClientVersion.createOrThrow(clientVersion), - clientIpAddress = ClientIpAddress.createOrThrow("UNDEFINED") + applicationName = ApplicationName.factory.createOrThrow(clientName), + clientVersion = ClientVersion.factory.createOrThrow(clientVersion), + clientIpAddress = ClientIpAddress.factory.createOrThrow("UNDEFINED") ) } @@ -30,11 +30,11 @@ internal fun SdkAuth.Metadata.rs(): Metadata { internal fun RSAuthorization.sdk(): SdkAuth { return SdkAuth( - accessHash = accessHash?.let { SdkAuth.Hash(HashValue.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, - refreshHash = refreshHash?.let { SdkAuth.Hash(HashValue.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, + accessHash = accessHash?.let { SdkAuth.Hash(HashValue.factory.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, + refreshHash = refreshHash?.let { SdkAuth.Hash(HashValue.factory.createOrThrow(it.value), Instant.fromEpochMilliseconds(it.expiresAt)) }, generationTime = Instant.fromEpochMilliseconds(generationTime), metadata = metadata?.sdk(), - userId = UserId.createOrThrow(userId), + userId = UserId.factory.createOrThrow(userId), ) } diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt index 7f13531..fa5d1d7 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/authorizations/commands/GetAuthorizationSessionsCommand.kt @@ -23,7 +23,7 @@ internal object GetAuthorizationSessionsCommand : RSocketCommand StartAuthorizationRequest.Result( - verificationHash = VerificationHash.createOrThrow(result.verificationHash), + verificationHash = VerificationHash.factory.createOrThrow(result.verificationHash), attempts = Count.factory.createOrThrow(result.attempts), expiresAt = Instant.fromEpochMilliseconds(result.expiresAt), ) diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt index a54dba3..0b5ad5f 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/TimerMappers.kt @@ -1,16 +1,15 @@ package org.timemates.api.rsocket.timers +import kotlinx.datetime.Instant import org.timemates.api.timers.sessions.types.TimerState import org.timemates.sdk.common.constructor.createOrThrow import org.timemates.sdk.common.types.value.Count import org.timemates.sdk.timers.members.invites.types.value.InviteCode -import org.timemates.sdk.timers.types.Timer import org.timemates.sdk.timers.types.TimerSettings import org.timemates.sdk.timers.types.value.TimerDescription import org.timemates.sdk.timers.types.value.TimerId import org.timemates.sdk.timers.types.value.TimerName import org.timemates.sdk.users.profile.types.value.UserId -import kotlinx.datetime.Instant import kotlin.time.Duration.Companion.minutes import kotlin.time.DurationUnit import org.timemates.api.timers.members.invites.types.Invite as RSInvite @@ -23,10 +22,10 @@ import org.timemates.sdk.timers.types.TimerSettings as SdkTimerSettings internal fun RSTimer.sdk(): SdkTimer { return SdkTimer( - timerId = TimerId.createOrThrow(id), - name = TimerName.createOrThrow(name), - description = TimerDescription.createOrThrow(description), - ownerId = UserId.createOrThrow(ownerId), + timerId = TimerId.factory.createOrThrow(id), + name = TimerName.factory.createOrThrow(name), + description = TimerDescription.factory.createOrThrow(description), + ownerId = UserId.factory.createOrThrow(ownerId), membersCount = Count.factory.createOrThrow(membersCount), state = currentState?.sdk() ?: SdkTimerState.Inactive(Instant.DISTANT_PAST), settings = settings?.sdk() ?: TimerSettings(), @@ -40,20 +39,25 @@ internal fun RSTimerState.sdk(): SdkTimerState { endsAt = Instant.fromEpochMilliseconds(phase.value.endsAt), publishTime = publishTime, ) + is TimerState.PhaseOneOf.Inactive -> SdkTimerState.Inactive( publishTime = publishTime, ) + is TimerState.PhaseOneOf.Paused -> SdkTimerState.Paused( publishTime = publishTime, ) + is TimerState.PhaseOneOf.Rest -> SdkTimerState.Rest( endsAt = Instant.fromEpochMilliseconds(phase.value.endsAt), publishTime = publishTime, ) + is TimerState.PhaseOneOf.Running -> SdkTimerState.Running( endsAt = Instant.fromEpochMilliseconds(phase.value.endsAt), publishTime = publishTime, ) + null -> SdkTimerState.Inactive(Instant.DISTANT_PAST) } } @@ -82,7 +86,7 @@ internal fun SdkTimerSettings.rs(): RSTimer.Settings { internal fun RSInvite.sdk(): SdkInvite { return SdkInvite( - inviteCode = InviteCode.createOrThrow(code), + inviteCode = InviteCode.factory.createOrThrow(code), creationTime = Instant.fromEpochMilliseconds(creationTime), limit = Count.factory.createOrThrow(limit), ) diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt index b6c3ab7..90f7d16 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/CreateTimerCommand.kt @@ -19,7 +19,7 @@ internal object CreateTimerCommand : RSocketCommand - CreateTimerRequest.Result(TimerId.createOrThrow(result.timerId)) + CreateTimerRequest.Result(TimerId.factory.createOrThrow(result.timerId)) } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt index 452aea0..f85ef3b 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/commands/GetUserTimersCommand.kt @@ -23,7 +23,7 @@ internal object GetUserTimersCommand : RSocketCommand - CreateInviteRequest.Result(InviteCode.createOrThrow(result.inviteCode)) + CreateInviteRequest.Result(InviteCode.factory.createOrThrow(result.inviteCode)) } } } \ No newline at end of file diff --git a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt index c835074..2da5898 100644 --- a/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt +++ b/rsocket-engine/src/main/kotlin/org/timemates/api/rsocket/timers/members/invites/commands/GetInvitesCommand.kt @@ -24,7 +24,7 @@ internal object GetInvitesCommand : RSocketCommand