Class UserEventPostController
java.lang.Object
io.github.navjotsrakhra.eventmanager.controller.UserEventPostController
The EventPostController class handles HTTP requests related to event posts.
- Version:
- 1.0
- Author:
- Navjot Singh Rakhra
-
Constructor Summary
ConstructorsConstructorDescriptionUserEventPostController(EventPostGetService eventPostGetService, EventPostAddService eventPostAddService, EventPostEditService eventPostEditService) Constructor for the EventPostController class. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?> addEvent(EventPostDTO newEvent, Principal principal) Handles POST requests for the "/events/post" URL to add a new event post if the user is the owner of the post.org.springframework.http.ResponseEntity<?> deleteEvent(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.org.springframework.http.ResponseEntity<?> editEvent(Long ID, EventPostDTO editedEvent, Principal principal) Handles POST requests for the "/events/edit/{ID}" URL to edit a post if the user is the owner of the post.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<EventPostDTO>> getAllEvents(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.org.springframework.http.ResponseEntity<String> Handles exceptions related to method date validation.org.springframework.http.ResponseEntity<String> Handles exceptions related to post not found.handleValidationException(org.springframework.web.bind.MethodArgumentNotValidException methodArgumentNotValidException) Handles exceptions related to method argument validation.
-
Constructor Details
-
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.EventPostDTOis the exposed version ofEventPost.- Parameters:
pagination- The pagination object. SeePageable. 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.
-
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.EventPostDTOis the exposed version ofEventPost- 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.
-