This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package ru.soune.nocopy.entity.user;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "protect_check")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class ProtectedFileCheck {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", unique = true, nullable = false)
|
||||
private User user;
|
||||
|
||||
@Column(nullable = false)
|
||||
@ColumnDefault(value = "10")
|
||||
@Builder.Default
|
||||
private Integer limitCheck = 10;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Builder.Default
|
||||
private Integer countChecked = 0;
|
||||
|
||||
@Column(name = "last_check_at")
|
||||
private LocalDateTime lastCheckAt;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public boolean incrementCheck() {
|
||||
if (this.limitCheck <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.countChecked++;
|
||||
this.limitCheck--;
|
||||
this.lastCheckAt = LocalDateTime.now();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -83,4 +83,9 @@ public class User {
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private List<Violation> violations = new ArrayList<>();}
|
||||
private List<Violation> violations = new ArrayList<>();
|
||||
|
||||
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
private ProtectedFileCheck protectedFileCheck;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user