refactoring
This commit is contained in:
36
src/main/kotlin/eventDemo/app/entity/Player.kt
Normal file
36
src/main/kotlin/eventDemo/app/entity/Player.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package eventDemo.app.entity
|
||||
|
||||
import eventDemo.configuration.PlayerIdSerializer
|
||||
import eventDemo.configuration.UUIDSerializer
|
||||
import eventDemo.libs.event.AggregateId
|
||||
import io.ktor.server.auth.Principal
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.UUID
|
||||
|
||||
@Serializable
|
||||
data class Player(
|
||||
val name: String,
|
||||
@Serializable(with = PlayerIdSerializer::class)
|
||||
val id: PlayerId = PlayerId(UUID.randomUUID()),
|
||||
) : Principal {
|
||||
constructor(id: String, name: String) : this(
|
||||
name,
|
||||
PlayerId(UUID.fromString(id)),
|
||||
)
|
||||
|
||||
@JvmInline
|
||||
value class PlayerId(
|
||||
@Serializable(with = UUIDSerializer::class)
|
||||
override val id: UUID = UUID.randomUUID(),
|
||||
) : AggregateId {
|
||||
override fun toString(): String = id.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class PlayerHand(
|
||||
val player: Player,
|
||||
val cards: List<Card> = emptyList(),
|
||||
) {
|
||||
val count = lazy { cards.count() }
|
||||
}
|
||||
Reference in New Issue
Block a user