4 lab CommentController
This commit is contained in:
parent
419eb0b15a
commit
6a071071e2
@ -1,5 +1,41 @@
|
||||
package ru.ulstu.is.sbapp.Comment.controller;
|
||||
|
||||
public class CommentController {
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.Comment.service.CommentService;
|
||||
import ru.ulstu.is.sbapp.Post.controller.PostDto;
|
||||
import ru.ulstu.is.sbapp.Post.service.PostService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/controller")
|
||||
public class CommentController {
|
||||
private final CommentService commentService;
|
||||
public CommentController(CommentService commentService) {
|
||||
this.commentService = commentService;
|
||||
}
|
||||
@GetMapping("/{id}")
|
||||
public CommentDto getComment(@PathVariable Long id) {
|
||||
return new CommentDto(commentService.findComment(id));
|
||||
}
|
||||
@GetMapping
|
||||
public List<CommentDto> getComments() {
|
||||
return commentService.findAllComments().stream()
|
||||
.map(CommentDto::new)
|
||||
.toList();
|
||||
}
|
||||
@PostMapping
|
||||
public CommentDto createComment(@RequestParam("Text") String Text){
|
||||
return new CommentDto(commentService.addComment(Text));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public CommentDto updateComment(@PathVariable Long id,
|
||||
@RequestParam("Text") String Text){
|
||||
return new CommentDto(commentService.updateComment(id,Text));
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public CommentDto deleteComment(@PathVariable Long id) {
|
||||
return new CommentDto(commentService.deleteComment(id));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.ulstu.is.sbapp.Comment.controller;
|
||||
|
||||
import ru.ulstu.is.sbapp.Comment.model.Comment;
|
||||
import ru.ulstu.is.sbapp.Post.model.Post;
|
||||
import ru.ulstu.is.sbapp.User.model.User;
|
||||
|
||||
@ -8,9 +9,9 @@ public class CommentDto {
|
||||
private String Text;
|
||||
private Post post;
|
||||
private User user;
|
||||
public CommentDto(String text)
|
||||
public CommentDto(Comment comment)
|
||||
{
|
||||
this.Text=text;
|
||||
this.Text=comment.getText();
|
||||
}
|
||||
public Long getId()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user