Implement clients API

This commit is contained in:
Paul-Henri Froidmont 2025-03-03 00:24:13 +01:00
parent 91584c18d5
commit 31014d1a0c
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
14 changed files with 474 additions and 228 deletions

View file

@ -0,0 +1,54 @@
package lu.foyer
package clients
import zio.*
import java.util.UUID
object ClientHandlers:
val layer: ULayer[List[CommandHandler[ClientCommand, ClientEvent, ClientState]]] =
ZLayer.succeed(
List(
CreateHandler,
UpdateHandler,
DisableHandler
)
)
object CreateHandler extends CommandHandlerCreate[ClientCommand.Create, ClientEvent.Created]:
val name = "create"
def onCommand(entityId: UUID, command: ClientCommand.Create): Task[ClientEvent.Created] =
ZIO.succeed(
ClientEvent.Created(
command.lastName,
command.firstName,
command.birthDate,
command.drivingLicenseDate,
command.phoneNumber,
command.email,
command.address
)
)
object UpdateHandler
extends CommandHandlerUpdate[ClientCommand.Update, ClientEvent.Updated, ClientState.Actif]:
val name = "update"
def onCommand(entityId: UUID, state: ClientState.Actif, command: ClientCommand.Update)
: Task[ClientEvent.Updated] =
ZIO.succeed(
ClientEvent.Updated(
command.lastName,
command.firstName,
command.birthDate,
command.drivingLicenseDate,
command.phoneNumber,
command.email,
command.address
)
)
object DisableHandler
extends CommandHandlerUpdate[ClientCommand.Disable, ClientEvent.Disabled, ClientState.Actif]:
val name = "disable"
def onCommand(entityId: UUID, state: ClientState.Actif, command: ClientCommand.Disable)
: Task[ClientEvent.Disabled] =
ZIO.succeed(ClientEvent.Disabled(command.reason))