Skip to content

Commit

Permalink
EVA-COSMETICS queries iface
Browse files Browse the repository at this point in the history
  • Loading branch information
Rattenkrieg committed Jul 7, 2023
1 parent e62b2eb commit 5769132
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions eva-domain/src/main/kotlin/com/razz/eva/domain/Queries.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.razz.eva.domain

interface Queries<MID : ModelId<out Comparable<*>>, M : Model<MID, *>> : suspend (MID) -> M {

suspend fun find(id: MID): M?

suspend fun get(id: MID): M

override suspend fun invoke(id: MID): M = get(id)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.razz.eva.examples.changes.user

interface UserQueries {
import com.razz.eva.domain.Queries

interface UserQueries : Queries<User.Id, User> {

class UserNotFoundException private constructor(
message: String,
) : IllegalStateException(message) {
constructor(id: User.Id) : this("User is not found for ${id.id}")
}

suspend fun get(id: User.Id): User
}
10 changes: 5 additions & 5 deletions eva-uow/src/main/kotlin/com/razz/eva/uow/ModelParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable(with = Serializer::class)
class ModelParam<MID : ModelId<*>, M : Model<MID, *>> private constructor(
class ModelParam<MID : ModelId<out Comparable<*>>, M : Model<MID, *>> private constructor(
private var model: M?,
private val id: MID,
private val modelQueries: suspend (MID) -> M
Expand All @@ -31,7 +31,7 @@ class ModelParam<MID : ModelId<*>, M : Model<MID, *>> private constructor(
}
}

class Serializer<MID : ModelId<*>, M : Model<MID, *>>(
class Serializer<MID : ModelId<out Comparable<*>>, M : Model<MID, *>>(
private val idSerializer: KSerializer<MID>,
@Suppress("unused") private val modelNoopSerializer: KSerializer<M>,
) : KSerializer<ModelParam<MID, *>> {
Expand All @@ -43,7 +43,7 @@ class ModelParam<MID : ModelId<*>, M : Model<MID, *>> private constructor(

companion object Factory {

fun <MID : ModelId<*>, M : Model<MID, *>> InstantiationContext.modelParam(
fun <MID : ModelId<out Comparable<*>>, M : Model<MID, *>> InstantiationContext.modelParam(
model: M,
modelQueries: suspend (MID) -> M,
): ModelParam<MID, M> {
Expand All @@ -55,14 +55,14 @@ class ModelParam<MID : ModelId<*>, M : Model<MID, *>> private constructor(
return modelParam
}

fun <MID : ModelId<*>, M : Model<MID, *>> modelParam(
fun <MID : ModelId<out Comparable<*>>, M : Model<MID, *>> modelParam(
model: M,
modelQueries: suspend (MID) -> M,
): ModelParam<MID, M> {
return ModelParam(model, modelQueries)
}

fun <MID : ModelId<*>, M : Model<MID, *>> idModelParam(
fun <MID : ModelId<out Comparable<*>>, M : Model<MID, *>> idModelParam(
modelId: MID,
modelQueries: suspend (MID) -> M,
): ModelParam<MID, M> {
Expand Down

0 comments on commit 5769132

Please sign in to comment.