2025-11-24 10:26:19 +07:00
|
|
|
package ru.soune.no_copy.entity;
|
|
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
import jakarta.validation.constraints.Size;
|
2025-11-24 10:26:19 +07:00
|
|
|
import lombok.*;
|
2025-11-24 12:29:32 +07:00
|
|
|
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
|
2025-11-24 12:29:32 +07:00
|
|
|
@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 12:29:32 +07:00
|
|
|
|
2025-11-24 10:26:19 +07:00
|
|
|
@Id
|
2025-11-24 12:29:32 +07:00
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
2025-11-24 10:26:19 +07:00
|
|
|
private Long userId;
|
|
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
@Size(max = 64)
|
2025-11-26 15:49:51 +07:00
|
|
|
@Column(name = "first_name", nullable = false, length = 64)
|
2025-11-24 12:29:32 +07:00
|
|
|
private String firstName;
|
|
|
|
|
|
|
|
|
|
@Size(max = 64)
|
2025-11-26 15:49:51 +07:00
|
|
|
@Column(name = "last_name", nullable = false, length = 64)
|
2025-11-24 12:29:32 +07:00
|
|
|
private String lastName;
|
|
|
|
|
|
|
|
|
|
@Size(max = 64)
|
2025-11-26 15:49:51 +07:00
|
|
|
@Column(name = "second_name", length = 64)
|
2025-11-24 12:29:32 +07:00
|
|
|
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;
|
2025-11-24 12:29:32 +07:00
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
|
2025-11-24 12:29:32 +07:00
|
|
|
@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
|
|
|
}
|