4 lab попытка сделать добавление постов (неудачно)
This commit is contained in:
parent
62d5bd2394
commit
4b9638ad2f
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -9,6 +9,7 @@ public class CommentDto {
|
||||
private String Text;
|
||||
private Post post;
|
||||
private User user;
|
||||
public CommentDto(){}
|
||||
public CommentDto(Comment comment)
|
||||
{
|
||||
this.Text=comment.getText();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.ulstu.is.sbapp.Post.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.Post.service.PostService;
|
||||
import ru.ulstu.is.sbapp.User.controller.UserDto;
|
||||
@ -25,9 +26,8 @@ public class PostController {
|
||||
.toList();
|
||||
}
|
||||
@PostMapping
|
||||
public PostDto createPost(@RequestParam("Heading") String Heading,
|
||||
@RequestParam("Content") String Content){
|
||||
return new PostDto(postService.addPost(Heading, Content));
|
||||
public PostDto createPost(@RequestBody @Valid PostDto postDto){
|
||||
return new PostDto(postService.addPost(postDto));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
|
@ -21,6 +21,7 @@ public class PostDto {
|
||||
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
public PostDto(){}
|
||||
public PostDto(Post post)
|
||||
{
|
||||
this.Heading = post.getHeading();
|
||||
|
@ -33,11 +33,6 @@ public class Post {
|
||||
private List<Comment> comments=new ArrayList<>();
|
||||
|
||||
public Post(){}
|
||||
public Post(String Heading, String Content)
|
||||
{
|
||||
this.Heading = Heading;
|
||||
this.Content = Content;
|
||||
}
|
||||
public Post(String Heading, String Content,byte[] image)
|
||||
{
|
||||
this.Heading = Heading;
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.Comment.model.Comment;
|
||||
import ru.ulstu.is.sbapp.Comment.repository.CommentRepository;
|
||||
import ru.ulstu.is.sbapp.Post.controller.PostDto;
|
||||
import ru.ulstu.is.sbapp.Post.model.Post;
|
||||
import ru.ulstu.is.sbapp.Post.repository.PostRepository;
|
||||
import ru.ulstu.is.sbapp.User.model.User;
|
||||
@ -27,8 +28,8 @@ public class PostService {
|
||||
this.validatorUtil=validatorUtil;
|
||||
}
|
||||
@Transactional
|
||||
public Post addPost(String Heading, String Content) {
|
||||
final Post post = new Post(Heading,Content);
|
||||
public Post addPost(PostDto postDto) {
|
||||
final Post post = new Post(postDto);
|
||||
validatorUtil.validate(post);
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ public class UserDto {
|
||||
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
public UserDto(){}
|
||||
public UserDto(User user) {
|
||||
this.id=user.getId();
|
||||
this.firstName = user.getFirstName();
|
||||
|
Loading…
Reference in New Issue
Block a user