Class EventService

java.lang.Object
app.YUP.service.EventService

@Service public class EventService extends Object
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 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

      public void deleteEvent(Event event)
      Service method to delete a user event from the repository.
      Parameters:
      event - the Event object to be deleted. It must not be null.
      Throws:
      ResourceNotFoundException - if the user to delete is null.
    • getEventsByOwner

      public List<EventResponse> getEventsByOwner(String userId)
      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

      public void isEventOwner(String userId, UUID eventId)
      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

      public byte[] getImageData(UUID id)
      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

      public List<EventResponse> getAllEvents()
      Retrieves all events from the event repository and maps them to their corresponding DTOs.
      Returns:
      A list of EventResponse containing all events mapped to their DTO representation.
    • getAllGEOEvents

      public GeoJsonWrapper getAllGEOEvents()
      Retrieves all events from the event repository and maps them to their corresponding DTOs.
      Returns:
      A list of GeoJsonWrapper containing all events mapped to their DTO representation.
    • getEventById

      public Event getEventById(UUID eventId)
      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

      public Set<User> getEventParticipants(UUID eventId)
      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

      public Set<String> getEventParticipantsEmails(Set<User> participants)
      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

      public EventResponse mapEntityToDTO(Event event)
      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

      public GeoJsonWrapper convertToGeoJson(List<Event> events)
      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

      public void updateParticipants(UUID eventId, int participants)
      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

      public boolean existsById(UUID eventId)