Class ServedBookingPresenter

java.lang.Object
io.github.marcopaglio.booking.presenter.served.ServedBookingPresenter
All Implemented Interfaces:
BookingPresenter

public class ServedBookingPresenter extends Object implements BookingPresenter
A concrete implementation of the presenter for the booking application using a single view and delegating operations on repositories to a service layer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServedBookingPresenter(BookingView view, BookingService bookingService, ClientValidator clientValidator, ReservationValidator reservationValidator)
    Constructs a presenter for the booking application with a view and a service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addClient(String firstName, String lastName)
    Validates and inserts a new client in the repository and notifies the view about the changes.
    void
    addReservation(Client client, String date)
    Validates and inserts a new reservation in the repository and notifies the view about the changes.
    void
    Finds all the existing clients in the repository through the service layer and gives the list to the view for showing them.
    void
    Finds all the existing reservations in the repository through the service layer and gives the list to the view for showing them.
    void
    Removes an existing client and all his reservations from the repository and notifies the view about the changes.
    void
    Removes an existing reservation from the repository and notifies the view about the changes.
    void
    renameClient(Client client, String newFirstName, String newLastName)
    Validates and modifies names of an existing client and notifies the view about the changes.
    void
    rescheduleReservation(Reservation reservation, String newDate)
    Modifies the date of an existing reservation and notifies the view about the changes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ServedBookingPresenter

      public ServedBookingPresenter(BookingView view, BookingService bookingService, ClientValidator clientValidator, ReservationValidator reservationValidator)
      Constructs a presenter for the booking application with a view and a service.
      Parameters:
      view - the View used to show the user interface.
      bookingService - the BookingService used to interact with repositories.
      clientValidator - the inputs checker for Client entities.
      reservationValidator - the inputs checker for Reservation entities.
  • Method Details

    • allClients

      public void allClients()
      Finds all the existing clients in the repository through the service layer and gives the list to the view for showing them.
      Specified by:
      allClients in interface BookingPresenter
    • allReservations

      public void allReservations()
      Finds all the existing reservations in the repository through the service layer and gives the list to the view for showing them.
      Specified by:
      allReservations in interface BookingPresenter
    • deleteClient

      public void deleteClient(Client client)
      Removes an existing client and all his reservations from the repository and notifies the view about the changes. This method delegates its elimination and of all his reservations to the service layer.
      Specified by:
      deleteClient in interface BookingPresenter
      Parameters:
      client - the client to delete.
    • deleteReservation

      public void deleteReservation(Reservation reservation)
      Removes an existing reservation from the repository and notifies the view about the changes. This method delegates its elimination to the service layer.
      Specified by:
      deleteReservation in interface BookingPresenter
      Parameters:
      reservation - the reservation to delete.
    • addClient

      public void addClient(String firstName, String lastName)
      Validates and inserts a new client in the repository and notifies the view about the changes. This method delegates the inserting to the service layer.
      Specified by:
      addClient in interface BookingPresenter
      Parameters:
      firstName - the name of the client to add.
      lastName - the surname of the client to add.
    • addReservation

      public void addReservation(Client client, String date)
      Validates and inserts a new reservation in the repository and notifies the view about the changes. This method delegates the inserting to the service layer.
      Specified by:
      addReservation in interface BookingPresenter
      Parameters:
      client - the associated client of the reservation to add.
      date - the date of the reservation to add.
    • renameClient

      public void renameClient(Client client, String newFirstName, String newLastName)
      Validates and modifies names of an existing client and notifies the view about the changes. This method delegates the renaming to the service layer only if new names are actually different from the old ones.
      Specified by:
      renameClient in interface BookingPresenter
      Parameters:
      client - the client to modify.
      newFirstName - the new name for the client.
      newLastName - the new surname for the client.
    • rescheduleReservation

      public void rescheduleReservation(Reservation reservation, String newDate)
      Modifies the date of an existing reservation and notifies the view about the changes. This method delegates the rescheduling to the service layer only if new date is actually different from the old one.
      Specified by:
      rescheduleReservation in interface BookingPresenter
      Parameters:
      reservation - the reservation to modify.
      newDate - the new date for the reservation.