-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSessionEntity.cs
More file actions
41 lines (29 loc) · 934 Bytes
/
SessionEntity.cs
File metadata and controls
41 lines (29 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using FluentValidation;
using System;
using Uuids;
namespace MangoAPI.Domain.Entities;
public sealed class SessionEntity
{
public Guid Id { get; private set; }
public Guid UserId { get; private set; }
public DateTime CreatedAt { get; private set; }
public DateTime ExpiresAt { get; private set; }
public bool IsExpired => DateTime.UtcNow >= ExpiresAt;
public UserEntity UserEntity { get; private set; }
private SessionEntity()
{
}
private SessionEntity(Guid userId, DateTime expiresAt)
{
Id = Uuid.NewMySqlOptimized().ToGuidByteLayout();
CreatedAt = DateTime.UtcNow;
UserId = userId;
ExpiresAt = expiresAt;
new SessionEntityValidator().ValidateAndThrow(this);
}
public static SessionEntity Create(Guid userId, DateTime expiresAt)
{
var session = new SessionEntity(userId, expiresAt);
return session;
}
}