Class PostController
java.lang.Object
com.example.blogs.app.api.post.controller.PostController
REST controller for managing post resources.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreatePost(UserPrincipal userPrincipal, @NotNull @Valid PostCreateRequestDTO requestDTO, MultipartFile previewImage) Creates a new post with a preview image.deletePostById(Long postId) Deletes a post by its ID.getPostBySlug(String slug) Retrieves a post by its unique slug identifier.updatePostById(Long postId, @NotNull @Valid PostUpdateRequestDTO requestDTO, MultipartFile previewImage) Updates a post by its ID with partial field updates.
-
Constructor Details
-
PostController
public PostController()
-
-
Method Details
-
deletePostById
@DeleteMapping("/{postId}") @PreAuthorize("@postSecurity.isOwner(#postId)") public ResponseEntity<Void> deletePostById(@PathVariable Long postId) Deletes a post by its ID.- Parameters:
postId- the ID of the post to delete- Returns:
- no content response on successful deletion
-
getPostBySlug
Retrieves a post by its unique slug identifier.- Parameters:
slug- the unique slug of the post- Returns:
- post details with associated comments
-
updatePostById
@PreAuthorize("@postSecurity.isOwner(#postId)") @PatchMapping(path="/{postId}", consumes="multipart/form-data") public ResponseEntity<PostUpdateResponseDTO> updatePostById(@PathVariable Long postId, @NotNull @Valid @RequestPart("post") @NotNull @Valid PostUpdateRequestDTO requestDTO, @RequestPart(value="previewImage",required=false) MultipartFile previewImage) Updates a post by its ID with partial field updates. At least one field must be provided in the request.- Parameters:
postId- the ID of the post to updaterequestDTO- the update request containing fields to updatepreviewImage- the new preview image file to upload (optional)- Returns:
- updated post details
-
createPost
@PostMapping(consumes="multipart/form-data") public ResponseEntity<PostCreateResponseDTO> createPost(@AuthenticationPrincipal UserPrincipal userPrincipal, @NotNull @Valid @RequestPart("post") @NotNull @Valid PostCreateRequestDTO requestDTO, @RequestPart("previewImage") MultipartFile previewImage) Creates a new post with a preview image.- Parameters:
userPrincipal- authenticated user principal containing the author IDrequestDTO- the post creation request containing title, description, and contentpreviewImage- the preview image file to upload- Returns:
- created post details with generated slug and preview image URL
-