Class UserEventPostController

java.lang.Object
io.github.navjotsrakhra.eventmanager.controller.UserEventPostController

@RestController @RequestMapping("/user/events") public class UserEventPostController extends Object
The EventPostController class handles HTTP requests related to event posts.
Version:
1.0
Author:
Navjot Singh Rakhra
  • Constructor Details

    • UserEventPostController

      public UserEventPostController(EventPostGetService eventPostGetService, EventPostAddService eventPostAddService, EventPostEditService eventPostEditService)
      Constructor for the EventPostController class.
      Parameters:
      eventPostGetService - Service for retrieving event posts.
      eventPostAddService - Service for adding event posts.
      eventPostEditService - Service of edition event posts.
  • Method Details

    • getAllEvents

      @GetMapping public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<EventPostDTO>> getAllEvents(@PageableDefault(size=5,sort="postedAt",direction=DESC) org.springframework.data.domain.Pageable pagination, Principal principal)
      Handles GET requests for the "/events" URL and retrieves a list of all events posted by the current user. EventPostDTO is the exposed version of EventPost.
      Parameters:
      pagination - The pagination object. See Pageable. Defaults to page 0, size 5, sorted by postedAt.
      principal - The Principal object is used to retrieve the username of the user making the request.
      Returns:
      ResponseEntity containing a list of EventPostDTO objects representing events posted by current user.
    • addEvent

      @PostMapping("/post") public org.springframework.http.ResponseEntity<?> addEvent(@RequestBody EventPostDTO newEvent, Principal principal) throws DateValidationFailedException
      Handles POST requests for the "/events/post" URL to add a new event post if the user is the owner of the post. EventPostDTO is the exposed version of EventPost
      Parameters:
      newEvent - The EventPostDTO object to be added, validated using @Valid annotation in the EventPostAddService.addEvent(EventPost, Principal).
      principal - The Principal object is used to retrieve the username of the user making the request.
      Returns:
      ResponseEntity indicating the result of the operation.
      Throws:
      DateValidationFailedException - if date validation fails.
    • editEvent

      @PostMapping("/edit/{ID}") public org.springframework.http.ResponseEntity<?> editEvent(@PathVariable Long ID, @RequestBody EventPostDTO editedEvent, Principal principal) throws DateValidationFailedException
      Handles POST requests for the "/events/edit/{ID}" URL to edit a post if the user is the owner of the post. EventPostDTO is the exposed version of EventPost
      Parameters:
      editedEvent - The EventPostDTO object to be edited, validated using @Valid annotation in the EventPostAddService.addEvent(EventPost, Principal).
      principal - The Principal object is used to retrieve the username of the user making the request.
      Returns:
      ResponseEntity indicating the result of the operation.
      Throws:
      DateValidationFailedException - if date validation fails.
    • deleteEvent

      @DeleteMapping("/delete/{ID}") public org.springframework.http.ResponseEntity<?> deleteEvent(@PathVariable Long ID, Principal principal)
      Handles DELETE requests for the "/events/delete/{ID}" URL to delete an event post if the user is the owner of the post. EventPostDTO is the exposed version of EventPost
      Parameters:
      ID - The ID of the event post to delete.
      principal - The Principal object is used to retrieve the username of the user making the request.
      Returns:
      ResponseEntity indicating the result of the operation.
    • handleValidationException

      @ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<List<String>> handleValidationException(org.springframework.web.bind.MethodArgumentNotValidException methodArgumentNotValidException)
      Handles exceptions related to method argument validation.
      Parameters:
      methodArgumentNotValidException - Exception related to method argument validation.
      Returns:
      ResponseEntity containing a list of error messages with a BAD_REQUEST status.
    • handleDateValidationException

      @ExceptionHandler(DateValidationFailedException.class) public org.springframework.http.ResponseEntity<String> handleDateValidationException(DateValidationFailedException e)
      Handles exceptions related to method date validation.
      Parameters:
      e - Exception related to date validation.
      Returns:
      ResponseEntity containing an error message with a BAD_REQUEST status.
    • handlePostNotFoundException

      @ExceptionHandler(PostNotFoundException.class) public org.springframework.http.ResponseEntity<String> handlePostNotFoundException(PostNotFoundException e)
      Handles exceptions related to post not found.
      Parameters:
      e - Exception related to error where the post to edit's ID is not found.
      Returns:
      ResponseEntity containing an error message with a NOT_FOUND status.