Complete MVP implementation (Étape 1) covering: - Domain: primitives (Entity<TId>, ValueObject), 10 entities, 6 enums - EF Core: AppDbContext + Identity, 8 EntityTypeConfigurations, audit/soft-delete interceptors, initial migration - Application: service interfaces, DTOs, FluentValidation, ServiceResult pattern - Security: Identity + JWT + API Key multi-auth, role-based permissions, constant-time key validation - API: Auth/Sites/Agents controllers with explicit auth scheme policies - Workers: Hangfire PostgreSQL setup with schema isolation, HeartbeatMonitorJob - Agent: registration service + 30s heartbeat loop - Docker: multi-stage Dockerfiles for central + agent, docker-compose.yml - CI/CD: GitHub Actions pipeline with build+test and Docker build - Tests: 13 domain tests (Site, Agent, Camera entities) Architecture decisions per deliberation council: - API Key via AuthenticationHandler<T> (not middleware) - Explicit [Authorize(AuthenticationSchemes)] on all endpoints - Event/Recording/Person/Vehicle deferred from initial migration - Hangfire compatible with .NET 10 (v1.8.17)
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using Heimdall.Domain.Primitives;
|
|
|
|
namespace Heimdall.Domain.Entities;
|
|
|
|
public class Site : Entity<Guid>, IAuditableEntity, ISoftDeletable
|
|
{
|
|
public string Name { get; private set; } = string.Empty;
|
|
public string? Address { get; private set; }
|
|
public string Timezone { get; private set; } = "UTC";
|
|
public bool Enabled { get; private set; } = true;
|
|
|
|
/// <summary>Hashed registration token (SHA256) for agent enrollment.</summary>
|
|
public string? RegistrationTokenHash { get; private set; }
|
|
|
|
/// <summary>When the current registration token expires.</summary>
|
|
public DateTime? TokenExpiresAt { get; private set; }
|
|
|
|
// Audit
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
|
// Soft delete
|
|
public bool IsDeleted { get; private set; }
|
|
public DateTime? DeletedAt { get; private set; }
|
|
|
|
// Navigation
|
|
private readonly List<Agent> _agents = [];
|
|
public IReadOnlyCollection<Agent> Agents => _agents.AsReadOnly();
|
|
|
|
private readonly List<Camera> _cameras = [];
|
|
public IReadOnlyCollection<Camera> Cameras => _cameras.AsReadOnly();
|
|
|
|
private Site() { } // EF Core
|
|
|
|
public Site(string name, string? address = null, string? timezone = null)
|
|
: base(Guid.NewGuid())
|
|
{
|
|
Name = name;
|
|
Address = address;
|
|
Timezone = timezone ?? "UTC";
|
|
}
|
|
|
|
public void Update(string name, string? address, string? timezone)
|
|
{
|
|
Name = name;
|
|
Address = address;
|
|
Timezone = timezone ?? Timezone;
|
|
}
|
|
|
|
public void GenerateRegistrationToken(string tokenHash, DateTime expiresAt)
|
|
{
|
|
RegistrationTokenHash = tokenHash;
|
|
TokenExpiresAt = expiresAt;
|
|
}
|
|
|
|
public void ClearRegistrationToken()
|
|
{
|
|
RegistrationTokenHash = null;
|
|
TokenExpiresAt = null;
|
|
}
|
|
|
|
public void SetEnabled(bool enabled) => Enabled = enabled;
|
|
|
|
public void SoftDelete()
|
|
{
|
|
IsDeleted = true;
|
|
DeletedAt = DateTime.UtcNow;
|
|
}
|
|
}
|