update ktlint
This commit is contained in:
@@ -10,7 +10,9 @@ sealed interface AggregateId {
|
||||
|
||||
@JvmInline
|
||||
@Serializable(with = GameIdSerializer::class)
|
||||
value class GameId(override val id: UUID = UUID.randomUUID()) : AggregateId {
|
||||
value class GameId(
|
||||
override val id: UUID = UUID.randomUUID(),
|
||||
) : AggregateId {
|
||||
constructor(id: String) : this(UUID.fromString(id))
|
||||
|
||||
override fun toString(): String = id.toString()
|
||||
|
||||
@@ -8,9 +8,7 @@ data class Game(
|
||||
val id: GameId,
|
||||
) {
|
||||
companion object {
|
||||
fun new(): Game {
|
||||
return Game(GameId())
|
||||
}
|
||||
fun new(): Game = Game(GameId())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import java.util.UUID
|
||||
|
||||
@JvmInline
|
||||
@Serializable(with = CommandIdSerializer::class)
|
||||
value class CommandId(private val id: UUID = UUID.randomUUID()) {
|
||||
value class CommandId(
|
||||
private val id: UUID = UUID.randomUUID(),
|
||||
) {
|
||||
constructor(id: String) : this(UUID.fromString(id))
|
||||
|
||||
override fun toString(): String = id.toString()
|
||||
|
||||
@@ -18,11 +18,7 @@ class CommandStream {
|
||||
commands.forEach { sendRequest(it) }
|
||||
}
|
||||
|
||||
fun readNext(): Command? {
|
||||
return commandBus.firstOrNull()
|
||||
}
|
||||
fun readNext(): Command? = commandBus.firstOrNull()
|
||||
|
||||
fun <U : Command> readNext(commandClass: Class<U>): U? {
|
||||
return commandBus.filterIsInstance(commandClass).firstOrNull()
|
||||
}
|
||||
fun <U : Command> readNext(commandClass: Class<U>): U? = commandBus.filterIsInstance(commandClass).firstOrNull()
|
||||
}
|
||||
|
||||
@@ -21,11 +21,7 @@ class EventStream<ID : AggregateId> {
|
||||
fun <U : Event<ID>> read(
|
||||
aggregateId: ID,
|
||||
eventClass: Class<U>,
|
||||
): U? {
|
||||
return eventBus.get(aggregateId)?.filterIsInstance(eventClass)?.firstOrNull()
|
||||
}
|
||||
): U? = eventBus.get(aggregateId)?.filterIsInstance(eventClass)?.firstOrNull()
|
||||
}
|
||||
|
||||
inline fun <reified U : Event<ID>, ID : AggregateId> EventStream<ID>.read(aggregateId: ID): U? {
|
||||
return this.read(aggregateId, U::class.java)
|
||||
}
|
||||
inline fun <reified U : Event<ID>, ID : AggregateId> EventStream<ID>.read(aggregateId: ID): U? = this.read(aggregateId, U::class.java)
|
||||
|
||||
@@ -26,14 +26,20 @@ class Game(
|
||||
) {
|
||||
@Serializable
|
||||
@Resource("card")
|
||||
class Card(val game: Game) {
|
||||
class Card(
|
||||
val game: Game,
|
||||
) {
|
||||
@Serializable
|
||||
@Resource("")
|
||||
class PutCard(val card: Card)
|
||||
class PutCard(
|
||||
val card: Card,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@Resource("last")
|
||||
class LastCard(val card: Card)
|
||||
class LastCard(
|
||||
val card: Card,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +53,8 @@ fun Routing.card() {
|
||||
}
|
||||
|
||||
get<Game.Card.LastCard> {
|
||||
eventStream.read<PlayCardEvent, GameId>(it.card.game.id)
|
||||
eventStream
|
||||
.read<PlayCardEvent, GameId>(it.card.game.id)
|
||||
?.let { it1 -> call.respond<Card>(it1.card) }
|
||||
?: call.response.status(HttpStatusCode.BadRequest)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ import org.koin.ktor.ext.inject
|
||||
@Resource("/command")
|
||||
class CommandRoute {
|
||||
@Resource("send")
|
||||
class Send(val commandRoute: CommandRoute) {
|
||||
class Send(
|
||||
val commandRoute: CommandRoute,
|
||||
) {
|
||||
@Serializable
|
||||
data class Response(
|
||||
val id: CommandId,
|
||||
@@ -29,7 +31,9 @@ class CommandRoute {
|
||||
}
|
||||
|
||||
@Resource("next")
|
||||
class Next(val commandRoute: CommandRoute)
|
||||
class Next(
|
||||
val commandRoute: CommandRoute,
|
||||
)
|
||||
}
|
||||
|
||||
fun Routing.command() {
|
||||
|
||||
Reference in New Issue
Block a user