Implement clients API
This commit is contained in:
parent
91584c18d5
commit
31014d1a0c
14 changed files with 474 additions and 228 deletions
54
core/src/lu/foyer/clients/ClientHandlers.scala
Normal file
54
core/src/lu/foyer/clients/ClientHandlers.scala
Normal 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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue