Add category module and require post category

This commit is contained in:
Tim
2025-06-30 23:07:15 +08:00
parent 4f24934a45
commit 5dd29239c9
10 changed files with 163 additions and 7 deletions

View File

@@ -0,0 +1,20 @@
package com.openisle.model;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "categories")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String name;
}

View File

@@ -30,6 +30,10 @@ public class Post {
@JoinColumn(name = "author_id")
private User author;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;
@Column(nullable = false)
private long views = 0;