Class PostController

java.lang.Object
com.example.blogs.app.api.post.controller.PostController

@RestController @RequestMapping("/posts") public class PostController extends Object
REST controller for managing post resources.
  • 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

      @GetMapping("/{slug}") public ResponseEntity<PostDTO> getPostBySlug(@PathVariable String slug)
      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 update
      requestDTO - the update request containing fields to update
      previewImage - 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 ID
      requestDTO - the post creation request containing title, description, and content
      previewImage - the preview image file to upload
      Returns:
      created post details with generated slug and preview image URL