dev add check limits logic
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-01-28 23:25:16 +07:00
parent 31fac0ab93
commit ec20d68261
12 changed files with 283 additions and 16 deletions
@@ -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;
}