48 lines
1.1 KiB
Java
48 lines
1.1 KiB
Java
|
|
package com.gcsc.guide.entity;
|
||
|
|
|
||
|
|
import jakarta.persistence.*;
|
||
|
|
import lombok.Getter;
|
||
|
|
import lombok.NoArgsConstructor;
|
||
|
|
|
||
|
|
import java.time.LocalDateTime;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Entity
|
||
|
|
@Table(name = "roles")
|
||
|
|
@Getter
|
||
|
|
@NoArgsConstructor
|
||
|
|
public class Role {
|
||
|
|
|
||
|
|
@Id
|
||
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||
|
|
private Long id;
|
||
|
|
|
||
|
|
@Column(nullable = false, unique = true, length = 50)
|
||
|
|
private String name;
|
||
|
|
|
||
|
|
@Column(length = 255)
|
||
|
|
private String description;
|
||
|
|
|
||
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
||
|
|
private LocalDateTime createdAt;
|
||
|
|
|
||
|
|
@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
|
||
|
|
private List<RoleUrlPattern> urlPatterns = new ArrayList<>();
|
||
|
|
|
||
|
|
public Role(String name, String description) {
|
||
|
|
this.name = name;
|
||
|
|
this.description = description;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void update(String name, String description) {
|
||
|
|
this.name = name;
|
||
|
|
this.description = description;
|
||
|
|
}
|
||
|
|
|
||
|
|
@PrePersist
|
||
|
|
protected void onCreate() {
|
||
|
|
this.createdAt = LocalDateTime.now();
|
||
|
|
}
|
||
|
|
}
|