Class EventController

java.lang.Object
app.YUP.controller.EventController

@Controller @RequestMapping("/event") public class EventController extends Object
This class is a controller for handling event related requests. It provides endpoints for creating a new event, viewing event details, and viewing all events.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createEvent(@Valid EventRequest event, jakarta.servlet.http.HttpServletRequest request, org.springframework.validation.BindingResult result, org.springframework.web.multipart.MultipartFile eventImageFile, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response)
    This method is used to create a new event.
    deleteEvent(UUID eventId, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Deletes an event.
    eventPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to display the event creation page.
    getAllEvents(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to retrieve all events.
    getAllGEOEvents(jakarta.servlet.http.HttpServletResponse response)
    This method is used to retrieve all events in GeoJSON format.
    getEventById(UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to retrieve a specific event by its ID.
    getEventByOwner(UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to retrieve a specific event with an owner view.
    org.springframework.http.ResponseEntity<byte[]>
    Retrieves the image of a specific event by its ID.
    getEventParticipants(UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Handles HTTP GET requests to retrieve the list of participants for a specified event.
    getEventsByOwner(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to retrieve events owned by the authenticated user.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventController

      public EventController()
  • Method Details

    • eventPage

      @GetMapping("/newEvent") public String eventPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to display the event creation page. It takes a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the AuthenticationService to get the username from the cookie in the request. It then uses the UserService to get the firstname of the user and adds it to the model. It also adds a new EventRequest object and the values of the EventTag enum to the model. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      model - This is the Model object that can be used to pass attributes to the view.
      request - This is the HttpServletRequest object that contains the request details.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • createEvent

      @PostMapping("/api/newEvent") public String createEvent(@Valid @Valid EventRequest event, jakarta.servlet.http.HttpServletRequest request, org.springframework.validation.BindingResult result, @RequestParam("eventImageFile") org.springframework.web.multipart.MultipartFile eventImageFile, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response)
      This method is used to create a new event. It takes an EventRequest object, a HttpServletRequest object, a BindingResult object, a MultipartFile object, a Model object, and a HttpServletResponse object as parameters. It uses the AuthenticationService to get the username from the cookie in the request. It then uses the EventService to create a new event. It also sends an email to the user with the event creation details. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      event - This is a request object that contains the details of the event to be created.
      request - This is the HttpServletRequest object that contains the request details.
      result - This is the BindingResult object that contains the results of the validation of the event request.
      eventImageFile - This is the MultipartFile object that contains the image of the event.
      model - This is the Model object that can be used to pass attributes to the view.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • getEventsByOwner

      @GetMapping("/myEvents") public String getEventsByOwner(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to retrieve events owned by the authenticated user. It takes a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the AuthenticationService to get the username from the cookie in the request. It then uses the UserService to get the firstname of the user and adds it to the model. It also adds the events owned by the user to the model. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      model - This is the Model object that can be used to pass attributes to the view.
      request - This is the HttpServletRequest object that contains the request details.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • getEventByOwner

      @GetMapping("/myEvents/{eventId}") public String getEventByOwner(@PathVariable UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to retrieve a specific event with an owner view. It takes a UUID eventId, a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the EventService to get the event by its ID and maps it to a DTO. It verifies if the user is the owner of the event and adds relevant attributes to the model. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      eventId - This is the UUID of the event to be retrieved.
      model - This is the Model object that can be used to pass attributes to the view.
      request - This is the HttpServletRequest object that contains the request details.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • getAllEvents

      @GetMapping("/all") public String getAllEvents(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to retrieve all events. It takes a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the EventService to get all events and adds them to the model. It also gets the username from the cookie in the request and adds the firstname of the user to the model. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      model - This is the Model object that can be used to pass attributes to the view.
      request - This is the HttpServletRequest object that contains the request details.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • getEventImage

      @GetMapping("/{eventId}/image") public org.springframework.http.ResponseEntity<byte[]> getEventImage(@PathVariable UUID eventId)
      Retrieves the image of a specific event by its ID.
      Parameters:
      eventId - The UUID of the event for which the image is to be retrieved.
      Returns:
      A ResponseEntity containing the image data in byte array format. The content type is set to 'image/jpeg'.
    • getEventById

      @GetMapping("/{eventId}") public String getEventById(@PathVariable UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to retrieve a specific event by its ID. It takes a UUID representing the event ID, a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the EventService to get the event by its ID and maps it to an EventResponse object. It then adds the EventResponse object to the model. It also gets the username from the cookie in the request and adds the firstname and username of the user to the model. It sets the HTTP status code of the response to 200 (OK). It returns a string that represents the name of the view to be rendered.
      Parameters:
      eventId - This is the UUID that represents the ID of the event.
      model - This is the Model object that can be used to pass attributes to the view.
      request - This is the HttpServletRequest object that contains the request details.
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      String This returns the name of the view to be rendered.
    • deleteEvent

      @PostMapping("/api/delete") public String deleteEvent(@RequestParam UUID eventId, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Deletes an event. * Retrieves the specified event using the event ID and deletes it if the user is authenticated and is the owner of the event.
      Parameters:
      eventId - The UUID of the event to delete.
      request - The HttpServletRequest object.
      response - The HttpServletResponse object.
      Returns:
      A redirection to the user's events page.
    • getEventParticipants

      @GetMapping("/{eventId}/participants") public String getEventParticipants(@PathVariable UUID eventId, org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Handles HTTP GET requests to retrieve the list of participants for a specified event.

      The endpoint verifies if the user is authenticated and is the owner of the event before retrieving the participants' details.

      Parameters:
      eventId - The UUID of the event for which participants are to be retrieved.
      model - The model object to add attributes used for rendering views.
      request - The HttpServletRequest object to access request information.
      response - The HttpServletResponse object to set the response status.
      Returns:
      The name of the view to render the participants' details.
    • getAllGEOEvents

      @GetMapping("/api/geo/all") @ResponseBody public GeoJsonWrapper getAllGEOEvents(jakarta.servlet.http.HttpServletResponse response)
      This method is used to retrieve all events in GeoJSON format. It takes a HttpServletResponse object as a parameter. It uses the EventService to get all events in GeoJSON format. It sets the HTTP status code of the response to 200 (OK). It returns a GeoJsonWrapper object that contains the GeoJSON data of all events.
      Parameters:
      response - This is the HttpServletResponse object that contains the response details.
      Returns:
      GeoJsonWrapper This returns the GeoJSON data of all events.