Skip to content

Commit

Permalink
fix: mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
y9vad9 committed Mar 19, 2024
1 parent 02caa0e commit 2e6f199
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
}

Expand All @@ -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),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal object GetAuthorizationSessionsCommand : RSocketCommand<GetAuthorizatio
results = result.authorizations.map { it.sdk() },
nextPageToken = result.nextPageToken
.takeIf { it.isNotEmpty() }
?.let { PageToken.createOrThrow(it) },
?.let { PageToken.factory.createOrThrow(it) },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object StartAuthorizationCommand : RSocketCommand<StartAuthorizationReq
}
).let { result ->
StartAuthorizationRequest.Result(
verificationHash = VerificationHash.createOrThrow(result.verificationHash),
verificationHash = VerificationHash.factory.createOrThrow(result.verificationHash),
attempts = Count.factory.createOrThrow(result.attempts),
expiresAt = Instant.fromEpochMilliseconds(result.expiresAt),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal object CreateTimerCommand : RSocketCommand<CreateTimerRequest, CreateTi
},
extra = input.accessHash.toExtra(),
).let { result ->
CreateTimerRequest.Result(TimerId.createOrThrow(result.timerId))
CreateTimerRequest.Result(TimerId.factory.createOrThrow(result.timerId))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal object GetUserTimersCommand : RSocketCommand<GetUserTimersRequest, Page
results = result.timers.map { it.sdk() },
nextPageToken = result.nextPageToken
.takeIf { it.isNotEmpty() }
?.let { PageToken.createOrThrow(it) },
?.let { PageToken.factory.createOrThrow(it) },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal object GetTimerMembersCommand : RSocketCommand<GetMembersRequest, Page<
results = result.users.map { it.sdk() },
nextPageToken = result.nextPageToken
.takeIf { it.isNotEmpty() }
?.let { PageToken.createOrThrow(it) },
?.let { PageToken.factory.createOrThrow(it) },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal object CreateInviteCommand : RSocketCommand<CreateInviteRequest, Create
},
extra = input.accessHash.toExtra(),
).let { result ->
CreateInviteRequest.Result(InviteCode.createOrThrow(result.inviteCode))
CreateInviteRequest.Result(InviteCode.factory.createOrThrow(result.inviteCode))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal object GetInvitesCommand : RSocketCommand<GetInvitesRequest, Page<Invit
results = result.invites.map { it.sdk() },
nextPageToken = result.nextPageToken
.takeIf { it.isNotEmpty() }
?.let { PageToken.createOrThrow(it) },
?.let { PageToken.factory.createOrThrow(it) },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import org.timemates.sdk.users.profile.types.User as SdkUser

internal fun RSUser.sdk(): SdkUser {
return SdkUser(
id = UserId.createOrThrow(id),
name = UserName.createOrThrow(name),
description = description.takeIf { it.isNotEmpty() }?.let { UserDescription.createOrThrow(it) },
emailAddress = email.takeIf { it.isNotEmpty() }?.let { EmailAddress.createOrThrow(it) },
avatar = gravatarId.takeIf { it.isNotBlank() }?.let { Avatar.GravatarId.createOrThrow(it) },
id = UserId.factory.createOrThrow(id),
name = UserName.factory.createOrThrow(name),
description = description.takeIf { it.isNotEmpty() }?.let { UserDescription.factory.createOrThrow(it) },
emailAddress = email.takeIf { it.isNotEmpty() }?.let { EmailAddress.factory.createOrThrow(it) },
avatar = gravatarId.takeIf { it.isNotBlank() }?.let { Avatar.GravatarId.factory.createOrThrow(it) },
)
}

0 comments on commit 2e6f199

Please sign in to comment.