Add Post module

This commit is contained in:
Tim
2025-06-30 19:00:43 +08:00
parent fe894834b7
commit d419b45515
5 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
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 = "posts")
public class Post {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String title;
@Column(nullable = false, columnDefinition = "TEXT")
private String content;
@Column(nullable = false)
private LocalDateTime createdAt;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
private User author;
@Column(nullable = false)
private long views = 0;
@PrePersist
protected void onCreate() {
this.createdAt = LocalDateTime.now();
}
}