Class EventRegister

java.lang.Object
no.ntnu.idatt1002.demo.repo.EventRegister

public class EventRegister extends Object
This class represents a register for events. Allowing for communication between the database and the user interface.
  • Field Details

    • events

      private List<Event> events
    • dao

      private final DAO dao
  • Constructor Details

    • EventRegister

      public EventRegister(DAO dao)
      Constructor for the EventRegister class.
      Parameters:
      dao - the data access object
      Throws:
      IllegalArgumentException - if dao is null
  • Method Details

    • getAllEvents

      public void getAllEvents()
      This method retrieves all events from the database.
    • addEvent

      public void addEvent(int recipeId, int date)
      Adds an event to the database.
      Parameters:
      recipeId - the id of the recipe
      date - the date of the event
    • getIndexFromEvent

      private int getIndexFromEvent(int id)
      Returns the index of the event with the given id.
      Parameters:
      id - the id of the event
      Returns:
      the index of the event
    • deleteEvent

      public void deleteEvent(int id)
      Deletes an event from the database.
      Parameters:
      id - the id of the event to be deleted
      Throws:
      IllegalArgumentException - if the event does not exist
    • getEventById

      public void getEventById(int id)
      Gets the events by the recipe id.
      Parameters:
      id - the id of the recipe
    • getEventsAsList

      public List<Event> getEventsAsList()
      Returns the events in the register as a list.
      Returns:
      the events in the register as a list
    • updateEvent

      public void updateEvent(int eventId, int recipeId, int date)
      This method updates an event in the database.
      Parameters:
      eventId - the id of the event
      recipeId - the id of the recipe
      date - the date of the event
      Throws:
      IllegalArgumentException - if the event does not exist
    • getEventsByDate

      public void getEventsByDate(int date)
      This method gets the events by the date.
      Parameters:
      date - the date of the event
    • packageToEvent

      private void packageToEvent(List<List<String>> eventList)
      Helper method to package the events into the Event class.
      Parameters:
      eventList - the list of events
    • getEvents

      public Map<Integer,Event> getEvents()
      Returns the events in the register.
      Returns:
      the events in the register as a Map
    • toString

      public String toString()
      Returns a string representation of the events.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the events