Skip to content
This repository was archived by the owner on Nov 29, 2021. It is now read-only.
This repository was archived by the owner on Nov 29, 2021. It is now read-only.

Have some notion of validation of commands in Aggregate? #19

@arianvp

Description

@arianvp

The current definition of Aggregate is as follows:

data Aggregate state event command =
  Aggregate
  { aggregateCommandHandler :: state -> command -> [event]
  , aggregateProjection :: Projection state event
  }

But people tell me I should never trust user input. What if the incoming command is invalid? How would I handle this? Usually I have something like:

data Validation errors v = Error errors | Validated v
instance Semigroup errors => Applicative (Validation errors)

data EmailError = IsNotAnEmail | NotAnEducationalInstitution | AlreadyExists
validateSubmitEmail :: EmailCommand -> EmailState -> Validation [EmailError] EmailEvent

Would I have to map errors to "events" ? Such that, an invalid command inserts an ErrorOccured <reason> event?

But that would give you superflous events that probably should not affect the state in the Projection

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions