Scrolls from the reservation book

Exercise 5 of 6 in chapter 10 · 280 XP · 5 objectives checked by tests

Topics covered: Workflow events#[AsEnteredListener]entered and leaveMailer

There is a problem in the tavern: the traveler receives “Your table awaits” as soon as they fill in the form. But nothing is confirmed yet: Gorm can still turn the reservation down, on a fully booked feast night. And when he cancels a reservation, the traveler knows nothing about it.

The confirmation scroll must go out when the tavern confirms. And a cancellation scroll, when it cancels.

Workflow events

On every transition, the workflow announces each of its steps:

  1. guard: is the transition allowed?
  2. leave: the object leaves its place;
  3. transition: it is on its way;
  4. enter, then entered: it has arrived at its new place;
  5. completed: it is over;
  6. announce: for each transition that is now possible.

Each event also exists per workflow, per transition or per place (workflow.reservation.entered.confirmed). Reacting to a status change means listening to the right one.

The benefit: whether the reservation is confirmed from the reservation book, a command or the API, the scroll goes out.

Your mission

  1. When a reservation arrives at confirmed, the confirmation scroll goes out.
  2. When it arrives at canceled, a cancellation scroll goes out: subject “Your reservation at the Drunken Dragon is canceled”, with the title “Your reservation is canceled”, the name, the date, and a “Book another table” link. Write Parcheminier::envoyerLAnnulation() (send the cancellation) and its template, emails/annulation.html.twig.
  3. Canceling an already confirmed reservation sends only the cancellation; honoring sends nothing.
  4. The reservation form no longer sends the confirmation.

Write the listeners in ParcheminsDuRegistre (the reservation book's scrolls). To try it out: log in with gorm@drunken-dragon.me / barrel, confirm and cancel reservations in the reservation book, then open the 📬 mailbox.