82 lines
1.8 KiB
Java
82 lines
1.8 KiB
Java
package com.webproglabs.lab1.lab34.model;
|
|
|
|
import javax.persistence.*;
|
|
import java.util.Objects;
|
|
|
|
@Entity
|
|
public class Comment {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
private Long id;
|
|
|
|
private String text;
|
|
|
|
@ManyToOne()
|
|
private Profile owner;
|
|
|
|
@ManyToOne()
|
|
private Post post;
|
|
|
|
public Comment(){};
|
|
public Comment(String text, Profile owner, Post post) {
|
|
this.text = text;
|
|
this.owner = owner;
|
|
this.post = post;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getText() {
|
|
return text;
|
|
}
|
|
|
|
public void setText(String text) {
|
|
this.text = text;
|
|
}
|
|
|
|
public Profile getOwner() {
|
|
return owner;
|
|
}
|
|
public void setOwner(Profile owner) {
|
|
this.owner.getComments().remove(this);
|
|
this.owner = owner;
|
|
if (!owner.getComments().contains(this)) {
|
|
owner.getComments().add(this);
|
|
}
|
|
}
|
|
|
|
public Post getPost() {return post; }
|
|
|
|
public void setPost(Post post) {
|
|
this.post.getComments().remove(this);
|
|
this.post = post;
|
|
if (!post.getComments().contains(this)) {
|
|
post.getComments().add(this);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
Comment comment = (Comment) o;
|
|
return Objects.equals(id, comment.id);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(id);
|
|
}
|
|
|
|
public String ToString() {
|
|
return "Comment{" +
|
|
"id=" + id +
|
|
", text='" + text + '\'' +
|
|
", owner='" + owner.ToString() + '\'' +
|
|
", post='" + post.ToString() + '\'' +
|
|
'}';
|
|
}
|
|
}
|