Package app.YUP.service
Class EventService
java.lang.Object
app.YUP.service.EventService
This class represents the service layer for the Event entity.
It contains methods for creating, retrieving, validating, and converting events.
The class is annotated with Spring's @Service annotation to indicate that it's a service component.
- Version:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertToGeoJson(List<Event> events) Converts a list of events to a GeoJSON representation.voidcreateEvent(EventRequest event, String userId, org.springframework.validation.BindingResult result, org.springframework.web.multipart.MultipartFile eventImageFile, org.springframework.ui.Model model) Creates a new event by saving the provided event object to the repository.voiddeleteEvent(Event event) Service method to delete a user event from the repository.booleanexistsById(UUID eventId) Retrieves all events from the event repository and maps them to their corresponding DTOs.Retrieves all events from the event repository and maps them to their corresponding DTOs.getEventById(UUID eventId) Retrieves an event by its unique identifier.getEventParticipants(UUID eventId) Retrieves the participants of a given event.getEventParticipantsEmails(Set<User> participants) Retrieves the emails of participants of a given event.getEventsByOwner(String userId) Retrieves all events owned by a specific user.byte[]getImageData(UUID id) Retrieves an event image by their ID (event id).voidisEventOwner(String userId, UUID eventId) This method checks if a user is the owner of a specific event.mapEntityToDTO(Event event) Maps an EventDTO object to an Event entity object.voidupdateParticipants(UUID eventId, int participants) Updates the number of participants for a specific event.
-
Constructor Details
-
EventService
public EventService()
-
-
Method Details
-
createEvent
public void createEvent(EventRequest event, String userId, org.springframework.validation.BindingResult result, org.springframework.web.multipart.MultipartFile eventImageFile, org.springframework.ui.Model model) Creates a new event by saving the provided event object to the repository.- Parameters:
event- The event object to be created and saved.userId- The username of the user creating the event.result- The BindingResult object that holds the result of the validation of the event.eventImageFile- The image file of the event.model- The Model object that holds the model attributes.
-
deleteEvent
Service method to delete a user event from the repository.- Parameters:
event- theEventobject to be deleted. It must not benull.- Throws:
ResourceNotFoundException- if the user to delete is null.
-
getEventsByOwner
Retrieves all events owned by a specific user.- Parameters:
userId- The username of the user.- Returns:
- A list of EventResponse objects representing the events owned by the user.
-
isEventOwner
This method checks if a user is the owner of a specific event. It takes the userId of the user and the eventId of the event as parameters. It retrieves the user and event using their respective services and compares the owner of the event with the user. If the user is not the owner of the event, it throws an UnauthorizedAccessException.- Parameters:
userId- This is the ID of the user to be checked.eventId- This is the UUID of the event to be checked.- Throws:
UnauthorizedAccessException- if the user is not the owner of the event.
-
getImageData
Retrieves an event image by their ID (event id).- Parameters:
id- The id of the event to retrieve.- Returns:
- The blob of the event image
-
getAllEvents
Retrieves all events from the event repository and maps them to their corresponding DTOs.- Returns:
- A list of
EventResponsecontaining all events mapped to their DTO representation.
-
getAllGEOEvents
Retrieves all events from the event repository and maps them to their corresponding DTOs.- Returns:
- A list of
GeoJsonWrappercontaining all events mapped to their DTO representation.
-
getEventById
Retrieves an event by its unique identifier.- Parameters:
eventId- The UUID identifying the event to retrieve.- Returns:
- The event corresponding to the provided ID.
- Throws:
ResourceNotFoundException- if no event with the specified ID is found.
-
getEventParticipants
Retrieves the participants of a given event. This method takes an Event UUID as input and returns a set of Users who have reservations for the event. If the event has no reservations, an empty set is returned.- Parameters:
eventId- the Event object from which to retrieve the participants- Returns:
- a set of User objects who are participants of the event, or an empty set if there are no reservations
-
getEventParticipantsEmails
Retrieves the emails of participants of a given event. This method takes an Event object as input and returns a set of emails of users who have reservations for the event. If the event has no reservations, an empty set is returned.- Parameters:
participants- the Event object from which to retrieve the participants' emails- Returns:
- a set of emails of users who are participants of the event, or an empty set if there are no reservations
-
mapEntityToDTO
Maps an EventDTO object to an Event entity object.- Parameters:
event- The Event object used for mapping and creation of EventResponse object.- Returns:
- The EventResponse DTO object mapped from the Event object.
-
convertToGeoJson
Converts a list of events to a GeoJSON representation. Each event is converted to a GeoJSON feature.- Parameters:
events- The list of events to convert.- Returns:
- A GeoJsonWrapper containing the GeoJSON representation of the events.
-
updateParticipants
Updates the number of participants for a specific event.- Parameters:
eventId- The UUID identifying the event to update.participants- The new number of participants.
-
existsById
-