Add comment module

This commit is contained in:
Tim
2025-06-30 19:46:57 +08:00
parent 04e7aed9b8
commit ff64500ffd
6 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package com.openisle.model;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;
@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "comments")
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, columnDefinition = "TEXT")
private String content;
@Column(nullable = false)
private LocalDateTime createdAt;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "author_id")
private User author;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "post_id")
private Post post;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Comment parent;
@PrePersist
protected void onCreate() {
this.createdAt = LocalDateTime.now();
}
}