Skip to content

Instantly share code, notes, and snippets.

@walidum
Created May 14, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidum/4b768e89150fe50b1f0976431557224e to your computer and use it in GitHub Desktop.
Save walidum/4b768e89150fe50b1f0976431557224e to your computer and use it in GitHub Desktop.
package com.devskiller.tasks.blog.rest;
import com.devskiller.tasks.blog.model.dto.CommentDto;
import com.devskiller.tasks.blog.model.dto.NewCommentDto;
import com.devskiller.tasks.blog.service.CommentService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/posts")
public class CommentController {
private final CommentService commentService;
public CommentController(CommentService commentService) {
this.commentService = commentService;
}
@GetMapping(value = "/{postId}/comments")
@ResponseStatus(HttpStatus.OK)
public List<CommentDto> comments(@PathVariable String postId) {
return commentService.getCommentsForPost(postId);
}
@PostMapping(value = "/{id}/comments")
@ResponseStatus(HttpStatus.CREATED)
public String addComment(@RequestBody NewCommentDto commentDto) {
return commentService.addComment(commentDto);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment