TaskManager/src/main/java/com/example/TaskManager/Models/User.java

63 lines
1.1 KiB
Java

package com.example.TaskManager.Models;
import java.time.LocalDateTime;
import jakarta.persistence.*;
import lombok.*;
@Entity
@Table(name = "users")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String username;
@Column(nullable = false)
private String password;
@Column(nullable = false, unique = true)
private String email;
@Column
private String firstName;
@Column
private String lastName;
@Column(unique = true)
private String phoneNumber;
@Column(nullable = false)
private LocalDateTime createdAt;
@Column(nullable = false)
private String createdBy;
@Column
private LocalDateTime updatedAt;
@Column
private String updatedBy;
@PrePersist
protected void onCreate() {
LocalDateTime now = LocalDateTime.now();
this.createdAt = now;
this.updatedAt = now;
}
@PreUpdate
protected void onUpdate() {
this.updatedAt = LocalDateTime.now();
}
}