-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDailySnapshot.cs
More file actions
39 lines (30 loc) · 1.04 KB
/
DailySnapshot.cs
File metadata and controls
39 lines (30 loc) · 1.04 KB
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
using Taskdeck.Domain.Common;
using Taskdeck.Domain.Exceptions;
namespace Taskdeck.Domain.Entities;
public class DailySnapshot : Entity
{
public Guid UserId { get; private set; }
public DateOnly Date { get; private set; }
public DateTimeOffset? SealedAt { get; private set; }
public bool IsSealed => SealedAt.HasValue;
private DailySnapshot() { } // EF Core
public DailySnapshot(Guid userId, DateOnly date, DateTimeOffset now)
{
if (userId == Guid.Empty)
throw new DomainException(ErrorCodes.ValidationError, "UserId cannot be empty");
if (date > DateOnly.FromDateTime(now.UtcDateTime))
throw new DomainException(ErrorCodes.ValidationError, "Date must not be in the future");
UserId = userId;
Date = date;
}
/// <summary>
/// Seals the day's snapshot. Idempotent: if already sealed, this is a no-op.
/// </summary>
public void Seal(DateTimeOffset now)
{
if (IsSealed)
return;
SealedAt = now;
Touch();
}
}