Лабораторная 2 на 5 готово
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Dmitry
2026-10-21 20:50:08 +03:00
parent 65003b6119
commit 5eb4db24a8
63 changed files with 2752 additions and 31 deletions
@@ -0,0 +1,53 @@
package org.example.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.*;
import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "sessions")
@Getter
@Setter
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Session {
@Id
private UUID id;
@Column(name = "user_id", nullable = false)
private UUID userId;
@Column(name = "token", nullable = false, unique = true, length = 64)
private String token;
@Column(name = "expires_at", nullable = false)
private Instant expiresAt;
@Column(name = "created_at", nullable = false)
private Instant createdAt;
@Column(name = "revoked_at")
private Instant revokedAt;
@PrePersist
void prePersist() {
if (id == null) {
id = UUID.randomUUID();
}
if (createdAt == null) {
createdAt = Instant.now();
}
}
public boolean isActive(Instant now) {
return revokedAt == null && expiresAt.isAfter(now);
}
}