Fix tests
This commit is contained in:
parent
efdc50eb1d
commit
87bd780f9f
34 changed files with 230 additions and 303 deletions
|
|
@ -1,39 +1,32 @@
|
|||
package lu.foyer
|
||||
|
||||
import lu.foyer.JsonApiResponse.One
|
||||
import zio.*
|
||||
import zio.Console.*
|
||||
import zio.http.*
|
||||
import zio.http.codec.*
|
||||
import zio.http.codec.PathCodec.path
|
||||
import zio.http.endpoint.*
|
||||
import zio.schema.*
|
||||
|
||||
import java.net.URI
|
||||
import java.time.LocalDate
|
||||
import java.util.UUID
|
||||
|
||||
trait CommandEngineController[Command: Schema, Event: Schema, State: Schema]
|
||||
extends JsonApiController:
|
||||
trait CommandEngineController[Command, Event: Schema, State: Schema] extends JsonApiController:
|
||||
|
||||
def commandEngine: CommandEngine[Command, Event, State]
|
||||
|
||||
private lazy val fetchMany =
|
||||
Endpoint(Method.GET / entityName)
|
||||
// .query(HttpCodec.query[Page])
|
||||
.query(HttpCodec.query[Page])
|
||||
.jsonApiMany[State]
|
||||
|
||||
private lazy val fetchOne =
|
||||
Endpoint(Method.GET / entityName / uuid("entityId"))
|
||||
Endpoint(Method.GET / entityName / string("entityId"))
|
||||
.jsonApiOne[State]
|
||||
|
||||
private lazy val fetchEventsMany =
|
||||
Endpoint(Method.GET / entityName / uuid("entityId") / "events")
|
||||
// .query(HttpCodec.query[Page])
|
||||
Endpoint(Method.GET / entityName / string("entityId") / "events")
|
||||
.query(HttpCodec.query[Page])
|
||||
.jsonApiMany[Event]
|
||||
|
||||
private lazy val fetchEventsOne =
|
||||
Endpoint(Method.GET / entityName / uuid("entityId") / "events" / uuid("eventId"))
|
||||
Endpoint(Method.GET / entityName / string("entityId") / "events" / string("eventId"))
|
||||
.jsonApiOne[Event]
|
||||
|
||||
private def generateCommands = commandEngine.handlers.map(handler =>
|
||||
|
|
@ -49,15 +42,17 @@ trait CommandEngineController[Command: Schema, Event: Schema, State: Schema]
|
|||
val route = endpoint.implementJsonApiOneEvent(command =>
|
||||
for
|
||||
entityId <- Random.nextUUID
|
||||
(event, state) <- commandEngine
|
||||
.handleCommand(command, handler.name, entityId)
|
||||
(event, _) <- commandEngine
|
||||
.handleCommand(command, handler.name, entityId.toString)
|
||||
yield Some(event)
|
||||
)
|
||||
(endpoint, route)
|
||||
|
||||
private def generateUpdateCommand(handler: CommandHandler[Command, Event, State]) =
|
||||
given Schema[Command] = handler.commandSchema.asInstanceOf[Schema[Command]]
|
||||
val endpoint = Endpoint(Method.PUT / entityName / uuid("entityId") / "commands" / handler.name)
|
||||
val endpoint = Endpoint(
|
||||
Method.PUT / entityName / string("entityId") / "commands" / handler.name
|
||||
)
|
||||
.in[Command]
|
||||
.jsonApiOne[Event]
|
||||
val route = endpoint.implementJsonApiOneEvent((entityId, command) =>
|
||||
|
|
@ -70,17 +65,13 @@ trait CommandEngineController[Command: Schema, Event: Schema, State: Schema]
|
|||
private lazy val (commands, commandsRoutes) = generateCommands.unzip
|
||||
|
||||
private lazy val fetchManyRoute =
|
||||
fetchMany.implementJsonApiManyEntity(_ =>
|
||||
commandEngine.stateRepo.fetchMany(Page(None, None, totals = Some(true)))
|
||||
)
|
||||
fetchMany.implementJsonApiManyEntity(commandEngine.stateRepo.fetchMany)
|
||||
|
||||
private lazy val fetchOneRoute =
|
||||
fetchOne.implementJsonApiOneEntity(commandEngine.stateRepo.fetchOne)
|
||||
|
||||
private lazy val fetchEventsManyRoute =
|
||||
fetchEventsMany.implementJsonApiManyEvent(entityId =>
|
||||
commandEngine.eventRepo.fetchMany(entityId, Page(None, None, totals = Some(true)))
|
||||
)
|
||||
fetchEventsMany.implementJsonApiManyEvent(commandEngine.eventRepo.fetchMany(_, _))
|
||||
|
||||
private lazy val fetchEventsOneRoute =
|
||||
fetchEventsOne.implementJsonApiOneEvent(commandEngine.eventRepo.fetchOne(_, _))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue