/** * @param UuidInterface $reservationId * * @throws CannotGiveBackReservationWhichWasNotGivenAway */ public function giveBack(UuidInterface $reservationId) { $reservation = $this->reservations->get($reservationId); if (!$reservation->isGivenAway()) { throw new CannotGiveBackReservationWhichWasNotGivenAway(sprintf('Cannot give back reservation %s which was not given away.', $reservation->id())); } $this->reservations->remove($reservationId); }
/** * @param UuidInterface $reservationId * @param \DateTime $givenAwayAt * * @throws BookInReservationAlreadyGivenAway */ public function giveAway(UuidInterface $reservationId, \DateTime $givenAwayAt) { $reservation = $this->reservations->get($reservationId); if ($this->reservations->existsAlreadyGivenOfBook($reservation->bookId())) { throw new BookInReservationAlreadyGivenAway(sprintf('Book with id %s in reservation with id %s was already given away.', $reservation->bookId(), $reservation->id())); } $reservation->giveAway($givenAwayAt); $this->reservations->save($reservation); }