Files
no-copy/src/main/java/ru/soune/no_copy/entity/User.java
T

94 lines
2.7 KiB
Java
Raw Normal View History

2025-11-24 10:26:19 +07:00
package ru.soune.no_copy.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
2025-11-24 10:26:19 +07:00
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
2025-11-24 10:26:19 +07:00
@Entity
@Table(name = "users")
2025-11-26 15:49:51 +07:00
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@EntityListeners(AuditingEntityListener.class)
2025-11-24 10:26:19 +07:00
public class User {
2025-11-24 10:26:19 +07:00
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
2025-11-24 10:26:19 +07:00
private Long userId;
@Size(max = 64)
2025-11-26 15:49:51 +07:00
@Column(name = "first_name", nullable = false, length = 64)
private String firstName;
@Size(max = 64)
2025-11-26 15:49:51 +07:00
@Column(name = "last_name", nullable = false, length = 64)
private String lastName;
@Size(max = 64)
2025-11-26 15:49:51 +07:00
@Column(name = "second_name", length = 64)
private String secondName;
@Size(max = 1024)
@Column(name = "email", nullable = false, length = 1024, unique = true)
private String email;
@Column(nullable = false)
@JsonIgnore
private String password;
2025-11-26 15:49:51 +07:00
@Enumerated(EnumType.STRING)
@Column(name = "subscription_type", nullable = false, length = 20)
private SubscriptionType subscriptionType = SubscriptionType.START;
@CreatedDate
@Column(name = "created_at", updatable = false, nullable = false)
private LocalDateTime createdAt;
2025-11-26 15:49:51 +07:00
@Column(name = "last_login_at")
private LocalDateTime lastLoginAt;
@Column(name = "is_active")
2025-11-26 11:33:33 +07:00
private Boolean isActive = true;
2025-11-24 10:26:19 +07:00
2025-11-26 15:49:51 +07:00
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@ToString.Exclude
private List<AuthToken> tokens = new ArrayList<>();
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@ToString.Exclude
private List<UserContent> userContents = new ArrayList<>();
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@ToString.Exclude
private List<UserAction> userActions = new ArrayList<>();
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@ToString.Exclude
private List<Violation> violations = new ArrayList<>();
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@ToString.Exclude
private List<ImageProtection> imageProtections = new ArrayList<>();
public String getFullName() {
if (secondName != null && !secondName.isBlank()) {
return String.format("%s %s %s", lastName, firstName, secondName);
}
return String.format("%s %s", lastName, firstName);
}
2025-11-24 10:26:19 +07:00
}