4 lab прикол

This commit is contained in:
Павел Сорокин 2023-04-07 12:00:07 +04:00
parent eecfe393e4
commit 1335f82494
2 changed files with 23 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import ru.ulstu.is.sbapp.Comment.model.Comment;
import ru.ulstu.is.sbapp.Post.model.Post;
import ru.ulstu.is.sbapp.User.model.User;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -16,12 +17,15 @@ public class PostDto {
private User user;
private String image;
private List<Comment> comments = new ArrayList<>();
public PostDto(Post post)
{
this.Heading = post.getHeading();
this.Content = post.getContent();
this.image = new String(post.getImage(), StandardCharsets.UTF_8);
}
@ -41,6 +45,9 @@ public class PostDto {
{
return user;
}
public String getImage() {
return image;
}
public List<Comment> getComments()
{
return comments;

View File

@ -18,10 +18,12 @@ public class Post {
@Column
@NotBlank(message = "Heading cannot be null")
private String Heading;
@NotBlank(message = "Content cannot be null")
private String Content;
@Lob
private byte[] image;
@ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.MERGE)
private User user;
@ -36,6 +38,13 @@ public class Post {
this.Heading = Heading;
this.Content = Content;
}
public Post(String Heading, String Content,byte[] image)
{
this.Heading = Heading;
this.Content = Content;
this.image=image;
}
public Long getId()
{
return id;
@ -62,7 +71,13 @@ public class Post {
{
return user;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public void deleteUser() {
this.user = null;