2025-12-15 19:13:39 +00:00
|
|
|
package com.hitcommunications.servermanager.model;
|
|
|
|
|
|
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
import lombok.*;
|
|
|
|
|
import org.hibernate.annotations.CreationTimestamp;
|
|
|
|
|
import org.hibernate.annotations.UpdateTimestamp;
|
|
|
|
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
@Entity
|
|
|
|
|
@Table(name = "tab_users")
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
@Builder
|
|
|
|
|
public class Users {
|
|
|
|
|
|
|
|
|
|
@Id
|
|
|
|
|
@GeneratedValue(strategy = GenerationType.UUID)
|
|
|
|
|
@Column(updatable = false, nullable = false)
|
|
|
|
|
private UUID id;
|
|
|
|
|
|
|
|
|
|
@Column(nullable = false, unique = true)
|
|
|
|
|
private String username;
|
|
|
|
|
|
|
|
|
|
@Column(nullable = false, unique = true, length = 100)
|
|
|
|
|
private String email;
|
|
|
|
|
|
2025-12-16 13:23:28 +00:00
|
|
|
@Column(nullable = false, length = 120)
|
2025-12-15 19:13:39 +00:00
|
|
|
private String password;
|
|
|
|
|
|
|
|
|
|
@Column(nullable = false, length = 30)
|
|
|
|
|
private String firstName;
|
|
|
|
|
|
|
|
|
|
@Column(nullable = false, length = 30)
|
|
|
|
|
private String lastName;
|
|
|
|
|
|
|
|
|
|
@CreationTimestamp
|
|
|
|
|
@Column(nullable = false)
|
|
|
|
|
private Timestamp createdAt;
|
|
|
|
|
|
|
|
|
|
@UpdateTimestamp
|
|
|
|
|
@Column(nullable = false)
|
|
|
|
|
private Timestamp updatedAt;
|
|
|
|
|
|
|
|
|
|
private Timestamp lastLogin;
|
|
|
|
|
|
|
|
|
|
@PrePersist
|
|
|
|
|
private void prePersist() {
|
|
|
|
|
if (this.username == null) {
|
|
|
|
|
this.username = generateUsername();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String generateUsername() {
|
|
|
|
|
String firstPart = this.firstName != null && this.firstName.length() >= 3 ? this.firstName.substring(0, 3) : (this.firstName != null ? this.firstName : "");
|
|
|
|
|
String secondPart = this.lastName != null && this.lastName.length() >= 3 ? this.lastName.substring(0, 3) : (this.lastName != null ? this.lastName : "");
|
|
|
|
|
this.username = firstPart + secondPart;
|
2025-12-15 20:27:59 +00:00
|
|
|
return this.username.toLowerCase();
|
2025-12-15 19:13:39 +00:00
|
|
|
}
|
|
|
|
|
}
|