Package no.ntnu.idatt1002.demo.repo
Class EventRegister
java.lang.Object
no.ntnu.idatt1002.demo.repo.EventRegister
This class represents a register for events.
Allowing for communication between the database and the user interface.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEvent
(int recipeId, int date) Adds an event to the database.void
deleteEvent
(int id) Deletes an event from the database.void
This method retrieves all events from the database.void
getEventById
(int id) Gets the events by the recipe id.Returns the events in the register.Returns the events in the register as a list.void
getEventsByDate
(int date) This method gets the events by the date.private int
getIndexFromEvent
(int id) Returns the index of the event with the given id.private void
packageToEvent
(List<List<String>> eventList) Helper method to package the events into the Event class.toString()
Returns a string representation of the events.void
updateEvent
(int eventId, int recipeId, int date) This method updates an event in the database.
-
Field Details
-
events
-
dao
-
-
Constructor Details
-
EventRegister
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 recipedate
- 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
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 eventrecipeId
- the id of the recipedate
- 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
Helper method to package the events into the Event class.- Parameters:
eventList
- the list of events
-
getEvents
Returns the events in the register.- Returns:
- the events in the register as a Map
-
toString
Returns a string representation of the events.
-