Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark a todo as done #1

Closed
codeliner opened this issue May 4, 2015 · 2 comments
Closed

Mark a todo as done #1

codeliner opened this issue May 4, 2015 · 2 comments
Labels

Comments

@codeliner
Copy link
Member

  1. Create a dedicated command for the action called MarkTodoAsDone and put it into the todo command folder
  2. Create a command handler for the new command
    • Create a factory for the command handler and put it here
    • The command handler needs to fetch an existing Todo from the TodoList so inject the TodoList as dependency into the command handler using the factory
    • Make the command handler available in the container by using the command handler FQCN as service name and point it to the factory. See configuration for the PostTodoCommandHandler as an example
  3. Now you can route the command to its handler
    • Route the http request representing the command to the Commanding\API.
      You can do this in the routes configuration.
    • The API will translate the request into a command message and dispatch the message on the command bus. The command bus is responsible to locate and invoke the responsible command handler. To do so the command bus also need some route information.
  4. In the command handler you should load the effected Todo from the TodoList
  5. The Todo aggregate root is responsible for handling the action so it needs a new method to do so.
    • In the method the Todo should check it's current status. Only if it is open it can be marked as done otherwise it should throw an exception
    • If the precondition is met the Todo should not change it's state directly but instead record a new domain event called TodoWasMarkedAsDone
    • Add a state changing method in the Todo aggregate root based on the new event. Call the method whenTodoWasMarkedAsDone and require the recorded event as a input parameter then change the TodoStatus to done
  6. The same event needs also be handled by a projector so that the read model gets updated. You already know how to route a command message to a handler. Now do the same for the event and route it to a projector which updates the read model table.

Bonus Points: Write at least one unit test which covers that an open Todo can change its state to done and records a TodoWasMarkedAsDone event to track the change.

@codeliner
Copy link
Member Author

@DannyvdSluijs please submit your PR against the develop branch of proophessor-do. Thanks

@DannyvdSluijs
Copy link

@codeliner Yes will do.

DannyvdSluijs pushed a commit to DannyvdSluijs/proophessor-do that referenced this issue Sep 16, 2015
@prolic prolic closed this as completed Sep 16, 2015
codeliner added a commit that referenced this issue Nov 23, 2015
prolic pushed a commit that referenced this issue Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants