Created
May 14, 2022 17:15
-
-
Save walidum/4b768e89150fe50b1f0976431557224e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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