Package app.YUP.service
Class ReservationService
java.lang.Object
app.YUP.service.ReservationService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckIfEventIsReservedByUser(User user, UUID eventId) Checks if a specific event is reserved by a user.voidcheckIfUserIsOwnerOfReservation(UUID userId, User userLogged, Event event) This method checks if the logged-in user is the owner of the reservation.booleanThis method checks if the current time is before the start time of the event.createReservation(ReservationRequest reservationRequest, User user) Creates a new reservation in the system.voiddeleteReservation(Event event, User user) Deletes a reservation from the system.getAllEventsReservedByUser(UUID userId) Retrieves all events reserved by a specific user.getAllReservationsForEvent(UUID eventId) Retrieves the reservations of a given event in alphabetical order by participant last name and first name This method takes an Event UUID as input and returns a set of ParticipantResponse objects representing the reservations for the event.getByUserIdAndEventId(UUID userId, UUID eventId) Retrieves a reservation by user ID and event ID.getPresenceCounts(Set<ParticipantResponse> participants) Counts the number of participants who are present and not present.returnReservationCode(User user, UUID eventId) This method is used to return the reservation code for a specific event that a user has reserved.intupdatePresenceByPrenotationCode(String prenotationCode, UUID userID, UUID eventID) Updates the presence status of a reservation by its prenotation code.
-
Constructor Details
-
ReservationService
public ReservationService()
-
-
Method Details
-
createReservation
Creates a new reservation in the system.- Parameters:
reservationRequest- the reservation dto to create
-
checkUserCanReserveBeforeStartDateTime
This method checks if the current time is before the start time of the event. It is used to ensure that a user can only reserve an event before it starts.- Parameters:
event- The Event object for which the start time is being checked.- Returns:
- true if the current time is before the start time of the event, false otherwise.
-
deleteReservation
Deletes a reservation from the system.- Parameters:
event- The event for which the reservation should be deleted.user- The user who made the reservation.- Throws:
ResourceNotFoundException- If no reservation exists for the given eventId and user.InvalidParameterException- If the eventId is null or the user is null.
-
getByUserIdAndEventId
Retrieves a reservation by user ID and event ID.- Parameters:
userId- The UUID of the user who made the reservation.eventId- The UUID of the event for which the reservation was made.- Returns:
- The reservation that matches the provided user ID and event ID.
- Throws:
ResourceNotFoundException- If no reservation exists for the given user ID and event ID.
-
checkIfEventIsReservedByUser
Checks if a specific event is reserved by a user.- Parameters:
user- The user to check the reservations for.eventId- The ID of the event to check.- Returns:
- true if the user has reserved the event, false otherwise.
-
returnReservationCode
This method is used to return the reservation code for a specific event that a user has reserved. It first fetches all the reservations made by the user. Then it iterates over these reservations to find the one that matches the provided event ID. If it finds a match, it breaks the loop and returns the prenotation code of the reservation. If it doesn't find a match, it throws an InvalidParameterException indicating that the user has not reserved this event.- Parameters:
user- The User object for whom to fetch the reservation code.eventId- The UUID of the event for which to fetch the reservation code.- Returns:
- The reservation code as a String.
- Throws:
InvalidParameterException- if the user has not reserved the event.
-
getAllEventsReservedByUser
Retrieves all events reserved by a specific user.This method first checks if a user with the provided UUID exists in the system. If the user does not exist, it throws an InvalidParameterException. If the user exists, it fetches all reservations made by the user. If the user has not made any reservations, it throws an InvalidParameterException. If the user has made reservations, it maps each reservation to its corresponding event and returns a list of these events.
- Parameters:
userId- The UUID of the user for whom to fetch reserved events.- Returns:
- A list of Event objects that were reserved by the user with the given UUID.
- Throws:
InvalidParameterException- if the user does not exist or if the user has not made any reservations.
-
updatePresenceByPrenotationCode
Updates the presence status of a reservation by its prenotation code.- Parameters:
prenotationCode- The unique identifier for the reservation.userID- The ID of the user who is updating the reservation.eventID- The ID of the event associated with the reservation.- Returns:
- -2 if the reservation with the given prenotation code does not exist, -1 if the reservation is already marked as present, 0 if the presence status of the reservation is successfully updated.
- Throws:
InvalidParameterException- if the event ID does not match the event associated with the reservation.InvalidPermissionException- if the user does not have permission to update the reservation for the given event.
-
checkIfUserIsOwnerOfReservation
This method checks if the logged-in user is the owner of the reservation. It throws an exception if the logged-in user is trying to create a reservation for another user or if the user is trying to create a reservation for an event they own.- Parameters:
userId- The UUID of the user for whom the reservation is being created.userLogged- The User object of the logged-in user.event- The Event object for which the reservation is being created.- Throws:
InvalidPermissionException- if the logged-in user is trying to create a reservation for another user.InvalidParameterException- if the user is trying to create a reservation for an event they own.
-
getAllReservationsForEvent
Retrieves the reservations of a given event in alphabetical order by participant last name and first name This method takes an Event UUID as input and returns a set of ParticipantResponse objects representing the reservations for the event. If the event has no reservations, an empty set is returned.- Parameters:
eventId- the UUID of the event for which to retrieve the reservations- Returns:
- a set of ParticipantResponse objects representing the reservations of the event, or an empty set if there are no reservations
- Throws:
IllegalArgumentException- if the event does not exist
-
getPresenceCounts
Counts the number of participants who are present and not present.- Parameters:
participants- a set ofParticipantResponseobjects representing the participants of an event- Returns:
- a map with two keys:
- "present" - the count of participants with presence set to true
- "notPresent" - the count of participants with presence set to false
-