feat(domain): entités métier Vehicle/Recording/LicensePlate/StoragePolicy + relations Event→Vehicle/Recording, Camera→StoragePolicy (Fixes #6)

This commit is contained in:
Arnaud Dartois committed 2026-08-11 21:42:46 +02:00
1 parent 33a08f5ea0
commit 29ff980db5
19 files changed
+3658

No files matched your search

@@ -117,5 +117,13 @@ public class CameraConfiguration : IEntityTypeConfiguration<Camera>
.WithOne(dp => dp.Camera)
.HasForeignKey<CameraDetectionProfile>(dp => dp.CameraId)
.OnDelete(DeleteBehavior.Cascade);
// Storage policy (N:1 — plusieurs caméras partagent une politique)
builder.HasOne(c => c.StoragePolicy)
.WithMany()
.HasForeignKey(c => c.StoragePolicyId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasIndex(c => c.StoragePolicyId);
}
}
@@ -37,6 +37,17 @@ public class CameraEventConfiguration : IEntityTypeConfiguration<CameraEvent>
builder.Property(e => e.OccurredAt)
.IsRequired();
builder.Property(e => e.DetectionHash)
.HasMaxLength(128)
.IsUnicode(false);
builder.Property(e => e.TrackId)
.HasMaxLength(100)
.IsUnicode(false);
builder.Property(e => e.IsSuppressed)
.HasDefaultValue(false);
builder.Property(e => e.CreatedAt)
.HasDefaultValueSql("NOW()");
@@ -51,10 +62,32 @@ public class CameraEventConfiguration : IEntityTypeConfiguration<CameraEvent>
builder.HasIndex(e => e.OccurredAt);
// Indexes déduplication / relations (spec 2.3)
builder.HasIndex(e => e.TrackId);
builder.HasIndex(e => e.DetectionHash);
builder.HasIndex(e => e.ParentEventId);
builder.HasIndex(e => e.VehicleId);
builder.HasIndex(e => e.RecordingId);
// Relationships
builder.HasOne(e => e.Camera)
.WithMany()
.HasForeignKey(e => e.CameraId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(e => e.Vehicle)
.WithMany()
.HasForeignKey(e => e.VehicleId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne(e => e.Recording)
.WithMany()
.HasForeignKey(e => e.RecordingId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne(e => e.ParentEvent)
.WithMany()
.HasForeignKey(e => e.ParentEventId)
.OnDelete(DeleteBehavior.SetNull);
}
}
@@ -0,0 +1,48 @@
using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class LicensePlateConfiguration : IEntityTypeConfiguration<LicensePlate>
{
public void Configure(EntityTypeBuilder<LicensePlate> builder)
{
builder.ToTable("license_plates");
builder.HasKey(p => p.Id);
builder.Property(p => p.PlateText)
.HasMaxLength(20)
.IsRequired()
.IsUnicode(false);
builder.Property(p => p.Confidence)
.HasDefaultValue(0.0);
builder.Property(p => p.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(p => p.UpdatedAt)
.HasDefaultValueSql("NOW()");
// Indexes (spec 2.3) — GIN trigram pour recherche floue de plaque
builder.HasIndex(p => p.PlateText)
.HasMethod("gin")
.HasOperators("gin_trgm_ops");
builder.HasIndex(p => p.VehicleId);
builder.HasIndex(p => p.PersonId);
// Relationships
builder.HasOne(p => p.Vehicle)
.WithMany()
.HasForeignKey(p => p.VehicleId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne(p => p.Person)
.WithMany()
.HasForeignKey(p => p.PersonId)
.OnDelete(DeleteBehavior.SetNull);
}
}
@@ -0,0 +1,57 @@
using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class RecordingConfiguration : IEntityTypeConfiguration<Recording>
{
public void Configure(EntityTypeBuilder<Recording> builder)
{
builder.ToTable("recordings");
builder.HasKey(r => r.Id);
builder.Property(r => r.Timestamp)
.IsRequired();
builder.Property(r => r.DurationSeconds)
.HasDefaultValue(0.0);
builder.Property(r => r.StoragePath)
.HasMaxLength(2000)
.IsRequired()
.IsUnicode(false);
builder.Property(r => r.SizeBytes)
.IsRequired();
builder.Property(r => r.StorageProvider)
.HasConversion<string>()
.HasMaxLength(20)
.IsRequired()
.IsUnicode(false);
builder.Property(r => r.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(r => r.UpdatedAt)
.HasDefaultValueSql("NOW()");
// Indexes (spec 2.3)
builder.HasIndex(r => new { r.CameraId, r.Timestamp }); // timeline per camera
builder.HasIndex(r => r.StoragePath).IsUnique(); // storage dedup
builder.HasIndex(r => r.StoragePolicyId);
// Relationships
builder.HasOne(r => r.Camera)
.WithMany()
.HasForeignKey(r => r.CameraId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(r => r.StoragePolicy)
.WithMany()
.HasForeignKey(r => r.StoragePolicyId)
.OnDelete(DeleteBehavior.SetNull);
}
}
@@ -0,0 +1,35 @@
using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class StoragePolicyConfiguration : IEntityTypeConfiguration<StoragePolicy>
{
public void Configure(EntityTypeBuilder<StoragePolicy> builder)
{
builder.ToTable("storage_policies");
builder.HasKey(p => p.Id);
builder.Property(p => p.Name)
.HasMaxLength(100)
.IsRequired()
.IsUnicode(false);
builder.Property(p => p.RetentionDays)
.IsRequired();
builder.Property(p => p.StorageProvider)
.HasConversion<string>()
.HasMaxLength(20)
.IsRequired()
.IsUnicode(false);
builder.Property(p => p.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(p => p.UpdatedAt)
.HasDefaultValueSql("NOW()");
}
}
@@ -0,0 +1,47 @@
using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class VehicleConfiguration : IEntityTypeConfiguration<Vehicle>
{
public void Configure(EntityTypeBuilder<Vehicle> builder)
{
builder.ToTable("vehicles");
builder.HasKey(v => v.Id);
builder.Property(v => v.LicensePlate)
.HasMaxLength(20)
.IsUnicode(false);
builder.Property(v => v.Make)
.HasMaxLength(100)
.IsUnicode(false);
builder.Property(v => v.Model)
.HasMaxLength(100)
.IsUnicode(false);
builder.Property(v => v.Color)
.HasMaxLength(50)
.IsUnicode(false);
builder.Property(v => v.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(v => v.UpdatedAt)
.HasDefaultValueSql("NOW()");
// Indexes
builder.HasIndex(v => v.LicensePlate);
builder.HasIndex(v => v.PersonId);
// Relationships
builder.HasOne(v => v.Person)
.WithMany()
.HasForeignKey(v => v.PersonId)
.OnDelete(DeleteBehavior.SetNull);
}
}