package ru.mtuci.messenger.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.UUID; @Entity @Table(name = "sessions") public class SessionEntity { @Id private UUID id; @Column(name = "token_hash", nullable = false, unique = true, length = 64) private String tokenHash; @Column(name = "user_id", nullable = false) private UUID userId; @Column(name = "expires_at", nullable = false) private Instant expiresAt; @Column(name = "revoked_at") private Instant revokedAt; @Column(name = "created_at", nullable = false) private Instant createdAt; protected SessionEntity() { } public SessionEntity(String tokenHash, UUID userId, Duration ttl) { this.id = UUID.randomUUID(); this.tokenHash = tokenHash; this.userId = userId; this.createdAt = Instant.now().truncatedTo(ChronoUnit.MICROS); this.expiresAt = createdAt.plus(ttl); } public UUID getUserId() { return userId; } public Instant getExpiresAt() { return expiresAt; } }