feat(codegen): Scala EventSourcedEntity.#561
Conversation
johanandren
left a comment
There was a problem hiding this comment.
LGTM with some small things
| rawEntity.getEntityType, | ||
| State(FullyQualifiedName(rawEntity.getState, protoReference)), | ||
| // FIXME this assumes the state is defined in the same proto file as the | ||
| // entity, which I don't think is necessarily true. |
There was a problem hiding this comment.
At least that is how all our samples does it, I think that if we want to support that the state message is in some other package that will likely need changes elsewhere as well.
There was a problem hiding this comment.
yeah I copied this comment :-)
| ValueEntityTestKitGenerator.generateManagedTest(entity, service) | ||
| case _: ModelBuilder.EventSourcedEntity => | ||
| Nil // FIXME | ||
| Nil |
There was a problem hiding this comment.
still to be done
| Nil | |
| Nil // FIXME |
octonato
left a comment
There was a problem hiding this comment.
LGTM, left a few minor suggestions
|
|
||
| def provider(entity: ModelBuilder.EventSourcedEntity, service: ModelBuilder.EntityService): File = { | ||
| val packageName = entity.fqn.parent.scalaPackage | ||
| val className = entity.fqn.name + "Provider" |
There was a problem hiding this comment.
can be moved in Entity model, like the 'Abstract' and the 'Handler'
| sealed abstract class Entity(val fqn: FullyQualifiedName, val entityType: String) | ||
| sealed abstract class Entity(val fqn: FullyQualifiedName, val entityType: String) { | ||
| val abstractEntityName = "Abstract" + fqn.name | ||
| val handlerName = fqn.name + "Handler" |
| case ModelBuilder.EventSourcedEntity(_, _, _, events) => | ||
| events.map { event => | ||
| s"""|def ${lowerFirst(event.fqn.name)}(currentState: ${typeName( | ||
| eventSourcedEntity.state.fqn)}, ${lowerFirst(event.fqn.name)}: ${typeName(event.fqn)}): ${typeName( |
There was a problem hiding this comment.
We can use $stateType instead of ${typeName(eventSourcedEntity.state.fqn)}. Will make is shorter to read.
| |class MyEntityHandler(entity: MyEntity) extends EventSourcedEntityHandler[MyState, MyEntity](entity) { | ||
| | def handleEvent(state: MyState, event: Any): MyState = { | ||
| | event match { | ||
| | case SetEvent => |
There was a problem hiding this comment.
that looks strange, matching on the companion object?
shouldn't it be case setEvent: SetEvent, and then the asInstanceOf isn't needed?
There was a problem hiding this comment.
yes fixed (I merged the fix in now)
| object EventSourcedEntityHandler { | ||
| final case class CommandHandlerNotFound(commandName: String) extends RuntimeException | ||
|
|
||
| final case class EventHandlerNotFound(commandName: String) extends RuntimeException |
There was a problem hiding this comment.
we should use the exceptions from the javasdk
com.akkaserverless.javasdk.impl.eventsourcedentity.EventSourcedEntityHandler.CommandHandlerNotFound and same with EventHandlerNotFound
There was a problem hiding this comment.
Ah leftover, I'll remove this.
| | * and the command handler methods in the <code>Counter</code> class. | ||
| | */ | ||
| |class MyEntityHandler(entity: MyEntity) extends EventSourcedEntityHandler[MyState, MyEntity](entity) { | ||
| | def handleEvent(state: MyState, event: Any): MyState = { |
There was a problem hiding this comment.
I'd prefer to have handleCommand before handleEvent
References #560