feat(persons): add person manager with known face registry and CRUD API
This commit is contained in:
1 parent
c5728fa810
commit
129a6148f5
15 files changed
+2404
-63
No files matched your search
@@ -0,0 +1,82 @@
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Services;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
||||
namespace Heimdall.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/persons")]
|
||||
[EnableRateLimiting("Api")]
|
||||
public class PersonsController : ControllerBase
|
||||
{
|
||||
private readonly IPersonService _personService;
|
||||
|
||||
public PersonsController(IPersonService personService) => _personService = personService;
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreatePersonRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.CreateAsync(request, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdatePersonRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.UpdateAsync(id, request, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)]
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.GetByIdAsync(id, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] string? category, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.GetAllAsync(category, ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.DeleteAsync(id, ct);
|
||||
return result.IsSuccess ? Ok() : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)]
|
||||
[HttpPost("{personId:guid}/faces")]
|
||||
public async Task<IActionResult> RegisterFace(Guid personId, [FromBody] RegisterFaceRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.RegisterFaceAsync(request with { PersonId = personId }, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)]
|
||||
[HttpGet("{personId:guid}/faces")]
|
||||
public async Task<IActionResult> GetFaces(Guid personId, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.GetFacesAsync(personId, ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)]
|
||||
[HttpDelete("faces/{faceId:guid}")]
|
||||
public async Task<IActionResult> DeleteFace(Guid faceId, CancellationToken ct)
|
||||
{
|
||||
var result = await _personService.DeleteFaceAsync(faceId, ct);
|
||||
return result.IsSuccess ? Ok() : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Heimdall.Application.DTOs;
|
||||
|
||||
public record PersonResponse(
|
||||
Guid Id, string DisplayName, string? Notes, string? PhotoUrl,
|
||||
string? Category, bool IsWatchlisted, int FaceCount, DateTime CreatedAt);
|
||||
|
||||
public record CreatePersonRequest(string DisplayName, string? Category, string? Notes, bool IsWatchlisted = false);
|
||||
|
||||
public record UpdatePersonRequest(string DisplayName, string? Notes, string? Category, bool IsWatchlisted);
|
||||
|
||||
public record KnownFaceResponse(Guid Id, Guid PersonId, string? ThumbnailUrl, string? SourceEventId);
|
||||
|
||||
public record RegisterFaceRequest(Guid PersonId, float[] Embedding, string? ThumbnailUrl = null, string? SourceEventId = null);
|
||||
@@ -0,0 +1,16 @@
|
||||
using Heimdall.Application.Common;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Services;
|
||||
|
||||
public interface IPersonService
|
||||
{
|
||||
Task<ServiceResult<PersonResponse>> CreateAsync(CreatePersonRequest request, CancellationToken ct);
|
||||
Task<ServiceResult<PersonResponse>> UpdateAsync(Guid id, UpdatePersonRequest request, CancellationToken ct);
|
||||
Task<ServiceResult<PersonResponse>> GetByIdAsync(Guid id, CancellationToken ct);
|
||||
Task<ServiceResult<List<PersonResponse>>> GetAllAsync(string? category, CancellationToken ct);
|
||||
Task<ServiceResult> DeleteAsync(Guid id, CancellationToken ct);
|
||||
Task<ServiceResult<KnownFaceResponse>> RegisterFaceAsync(RegisterFaceRequest request, CancellationToken ct);
|
||||
Task<ServiceResult<List<KnownFaceResponse>>> GetFacesAsync(Guid personId, CancellationToken ct);
|
||||
Task<ServiceResult> DeleteFaceAsync(Guid faceId, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using Heimdall.Domain.Primitives;
|
||||
|
||||
namespace Heimdall.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// A person of interest — known individual monitored by the system.
|
||||
/// Can be a family member, employee, or person on a watchlist.
|
||||
/// Associated with detection events via face recognition (EventType.FaceRecognized).
|
||||
/// </summary>
|
||||
public class Person : Entity<Guid>, IAuditableEntity
|
||||
{
|
||||
public string DisplayName { get; private set; } = string.Empty;
|
||||
public string? Notes { get; private set; }
|
||||
public string? PhotoUrl { get; private set; } // Main portrait photo
|
||||
public string? Category { get; private set; } // family, employee, watchlist, unknown
|
||||
public bool IsWatchlisted { get; private set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
private readonly List<KnownFace> _faces = [];
|
||||
public IReadOnlyCollection<KnownFace> Faces => _faces.AsReadOnly();
|
||||
|
||||
private Person() { } // EF Core
|
||||
|
||||
public Person(string displayName, string? category = null)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Category = category;
|
||||
}
|
||||
|
||||
public void Update(string displayName, string? notes, string? category, bool isWatchlisted)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Notes = notes;
|
||||
Category = category;
|
||||
IsWatchlisted = isWatchlisted;
|
||||
}
|
||||
|
||||
public void SetPhoto(string photoUrl) => PhotoUrl = photoUrl;
|
||||
|
||||
public void AddFace(KnownFace face) => _faces.Add(face);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A registered face encoding for a known person.
|
||||
/// Stored as a float array (128-d embedding from a face recognition model).
|
||||
/// </summary>
|
||||
public class KnownFace : Entity<Guid>
|
||||
{
|
||||
public Guid PersonId { get; private set; }
|
||||
public string? ThumbnailUrl { get; private set; }
|
||||
public float[] Embedding { get; private set; } = [];
|
||||
public string? SourceEventId { get; private set; }
|
||||
|
||||
// Navigation
|
||||
public Person Person { get; private set; } = null!;
|
||||
|
||||
private KnownFace() { } // EF Core
|
||||
|
||||
public KnownFace(Guid personId, float[] embedding, string? thumbnailUrl = null, string? sourceEventId = null)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
PersonId = personId;
|
||||
Embedding = embedding;
|
||||
ThumbnailUrl = thumbnailUrl;
|
||||
SourceEventId = sourceEventId;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,10 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>
|
||||
// Event entities
|
||||
public DbSet<CameraEvent> CameraEvents => Set<CameraEvent>();
|
||||
|
||||
// Person entities
|
||||
public DbSet<Person> Persons => Set<Person>();
|
||||
public DbSet<KnownFace> KnownFaces => Set<KnownFace>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class KnownFaceConfiguration : IEntityTypeConfiguration<KnownFace>
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new();
|
||||
|
||||
public void Configure(EntityTypeBuilder<KnownFace> builder)
|
||||
{
|
||||
builder.ToTable("known_faces");
|
||||
|
||||
builder.HasKey(f => f.Id);
|
||||
|
||||
builder.Property(f => f.ThumbnailUrl)
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(f => f.SourceEventId)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
|
||||
// Store float[] as JSONB
|
||||
builder.Property(f => f.Embedding)
|
||||
.HasColumnType("jsonb")
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonOptions),
|
||||
v => JsonSerializer.Deserialize<float[]>(v, JsonOptions) ?? Array.Empty<float>());
|
||||
|
||||
builder.HasIndex(f => f.PersonId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class PersonConfiguration : IEntityTypeConfiguration<Person>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Person> builder)
|
||||
{
|
||||
builder.ToTable("persons");
|
||||
|
||||
builder.HasKey(p => p.Id);
|
||||
|
||||
builder.Property(p => p.DisplayName)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(p => p.Notes)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.Property(p => p.PhotoUrl)
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(p => p.Category)
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.HasIndex(p => p.DisplayName);
|
||||
builder.HasIndex(p => p.Category);
|
||||
builder.HasIndex(p => p.IsWatchlisted);
|
||||
|
||||
// OwnsMany for KnownFace (stored as JSONB or separate table)
|
||||
builder.HasMany(p => p.Faces)
|
||||
.WithOne(f => f.Person)
|
||||
.HasForeignKey(f => f.PersonId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,7 @@ public static class DependencyInjection
|
||||
|
||||
// Event services
|
||||
services.AddScoped<ICameraEventService, CameraEventService>();
|
||||
services.AddScoped<IPersonService, PersonService>();
|
||||
services.AddSingleton<ISnapshotService, SnapshotService>();
|
||||
|
||||
// HTTP client for snapshot uploads (no default timeout)
|
||||
|
||||
+1548
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Heimdall.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPersonsAndKnownFaces : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "persons",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DisplayName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
||||
Notes = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
||||
PhotoUrl = table.Column<string>(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true),
|
||||
Category = table.Column<string>(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true),
|
||||
IsWatchlisted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_persons", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "known_faces",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
PersonId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
ThumbnailUrl = table.Column<string>(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true),
|
||||
Embedding = table.Column<string>(type: "jsonb", nullable: false),
|
||||
SourceEventId = table.Column<string>(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_known_faces", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_known_faces_persons_PersonId",
|
||||
column: x => x.PersonId,
|
||||
principalTable: "persons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_known_faces_PersonId",
|
||||
table: "known_faces",
|
||||
column: "PersonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_persons_Category",
|
||||
table: "persons",
|
||||
column: "Category");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_persons_DisplayName",
|
||||
table: "persons",
|
||||
column: "DisplayName");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_persons_IsWatchlisted",
|
||||
table: "persons",
|
||||
column: "IsWatchlisted");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "known_faces");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "persons");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -997,6 +997,81 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.ToTable("groups", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Embedding")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<Guid>("PersonId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("SourceEventId")
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("ThumbnailUrl")
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("known_faces", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Person", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Category")
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("character varying(200)");
|
||||
|
||||
b.Property<bool>("IsWatchlisted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<string>("PhotoUrl")
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Category");
|
||||
|
||||
b.HasIndex("DisplayName");
|
||||
|
||||
b.HasIndex("IsWatchlisted");
|
||||
|
||||
b.ToTable("persons", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Site", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -1324,6 +1399,17 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.Navigation("DiscoveryResult");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Person", "Person")
|
||||
.WithMany("Faces")
|
||||
.HasForeignKey("PersonId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Group", "Group")
|
||||
@@ -1442,6 +1528,11 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.Navigation("UserGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Person", b =>
|
||||
{
|
||||
b.Navigation("Faces");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Site", b =>
|
||||
{
|
||||
b.Navigation("Agents");
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
using Heimdall.Application.Common;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Services;
|
||||
using Heimdall.Domain.Entities;
|
||||
using Heimdall.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Heimdall.Infrastructure.Services;
|
||||
|
||||
public sealed class PersonService : IPersonService
|
||||
{
|
||||
private readonly IDbContextFactory<AppDbContext> _dbFactory;
|
||||
private readonly ILogger<PersonService> _logger;
|
||||
|
||||
public PersonService(IDbContextFactory<AppDbContext> dbFactory, ILogger<PersonService> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<PersonResponse>> CreateAsync(CreatePersonRequest request, CancellationToken ct)
|
||||
{
|
||||
var person = new Person(request.DisplayName, request.Category);
|
||||
if (request.Notes is not null) person.Update(request.DisplayName, request.Notes, request.Category, request.IsWatchlisted);
|
||||
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
db.Persons.Add(person);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
_logger.LogInformation("Person created: {PersonId} ({Name})", person.Id, person.DisplayName);
|
||||
return ServiceResult<PersonResponse>.Success(Map(person));
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<PersonResponse>> UpdateAsync(Guid id, UpdatePersonRequest request, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var person = await db.Persons.FindAsync([id], ct);
|
||||
if (person is null) return ServiceResult<PersonResponse>.NotFound("Person not found");
|
||||
|
||||
person.Update(request.DisplayName, request.Notes, request.Category, request.IsWatchlisted);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
return ServiceResult<PersonResponse>.Success(Map(person));
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<PersonResponse>> GetByIdAsync(Guid id, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == id, ct);
|
||||
return person is null
|
||||
? ServiceResult<PersonResponse>.NotFound("Person not found")
|
||||
: ServiceResult<PersonResponse>.Success(Map(person));
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<List<PersonResponse>>> GetAllAsync(string? category, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var query = db.Persons.Include(p => p.Faces).AsNoTracking();
|
||||
if (!string.IsNullOrEmpty(category))
|
||||
query = query.Where(p => p.Category == category);
|
||||
|
||||
var persons = await query.OrderBy(p => p.DisplayName).ToListAsync(ct);
|
||||
return ServiceResult<List<PersonResponse>>.Success(persons.Select(Map).ToList());
|
||||
}
|
||||
|
||||
public async Task<ServiceResult> DeleteAsync(Guid id, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var person = await db.Persons.FindAsync([id], ct);
|
||||
if (person is null) return ServiceResult.NotFound("Person not found");
|
||||
|
||||
db.Persons.Remove(person);
|
||||
await db.SaveChangesAsync(ct);
|
||||
return ServiceResult.Success();
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<KnownFaceResponse>> RegisterFaceAsync(RegisterFaceRequest request, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == request.PersonId, ct);
|
||||
if (person is null) return ServiceResult<KnownFaceResponse>.NotFound("Person not found");
|
||||
|
||||
var face = new KnownFace(request.PersonId, request.Embedding, request.ThumbnailUrl, request.SourceEventId);
|
||||
person.AddFace(face);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
return ServiceResult<KnownFaceResponse>.Success(MapFace(face));
|
||||
}
|
||||
|
||||
public async Task<ServiceResult<List<KnownFaceResponse>>> GetFacesAsync(Guid personId, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var faces = await db.KnownFaces
|
||||
.AsNoTracking()
|
||||
.Where(f => f.PersonId == personId)
|
||||
.ToListAsync(ct);
|
||||
|
||||
return ServiceResult<List<KnownFaceResponse>>.Success(faces.Select(MapFace).ToList());
|
||||
}
|
||||
|
||||
public async Task<ServiceResult> DeleteFaceAsync(Guid faceId, CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var face = await db.KnownFaces.FindAsync([faceId], ct);
|
||||
if (face is null) return ServiceResult.NotFound("Face not found");
|
||||
|
||||
db.KnownFaces.Remove(face);
|
||||
await db.SaveChangesAsync(ct);
|
||||
return ServiceResult.Success();
|
||||
}
|
||||
|
||||
private static PersonResponse Map(Person p) => new(
|
||||
p.Id, p.DisplayName, p.Notes, p.PhotoUrl,
|
||||
p.Category, p.IsWatchlisted, p.Faces.Count, p.CreatedAt);
|
||||
|
||||
private static KnownFaceResponse MapFace(KnownFace f) => new(
|
||||
f.Id, f.PersonId, f.ThumbnailUrl, f.SourceEventId);
|
||||
}
|
||||
@@ -8,41 +8,64 @@
|
||||
@inject IJSRuntime JsRuntime
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraSmall" Class="mt-16">
|
||||
<MudPaper Elevation="5" Class="pa-8" Style="border-radius: 16px;">
|
||||
<MudText Typo="Typo.h4" Align="Align.Center" Class="mb-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Shield" Size="Size.Large" Color="Color.Primary" />
|
||||
Heimdall
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2" Align="Align.Center" Color="Color.Secondary" Class="mb-8">
|
||||
Plateforme de surveillance vidéo
|
||||
</MudText>
|
||||
<div class="auth-page">
|
||||
<div class="auth-card">
|
||||
<div class="auth-header">
|
||||
<div class="auth-icon">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Shield" Size="Size.Large" />
|
||||
</div>
|
||||
<h1>Heimdall</h1>
|
||||
<p>Plateforme de surveillance vidéo</p>
|
||||
</div>
|
||||
|
||||
<form @onsubmit="LoginAsync" method="post">
|
||||
<MudTextField @bind-Value="_email" Label="Email" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true" />
|
||||
<MudTextField @bind-Value="_password" Label="Mot de passe" Variant="Variant.Outlined"
|
||||
InputType="InputType.Password" Class="mb-6" Required="true" Immediate="true"
|
||||
Autocomplete="current-password" />
|
||||
<div class="auth-form">
|
||||
<form @onsubmit="LoginAsync" method="post">
|
||||
<MudTextField @bind-Value="_email"
|
||||
Label="Email"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-4"
|
||||
Required="true"
|
||||
Immediate="true"
|
||||
Autocomplete="email" />
|
||||
<MudTextField @bind-Value="_password"
|
||||
Label="Mot de passe"
|
||||
Variant="Variant.Outlined"
|
||||
InputType="InputType.Password"
|
||||
Class="mb-4"
|
||||
Required="true"
|
||||
Immediate="true"
|
||||
Autocomplete="current-password" />
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_errorMessage</MudAlert>
|
||||
}
|
||||
<div class="auth-error">
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">@_errorMessage</MudAlert>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
||||
ButtonType="ButtonType.Submit" Disabled="@_loading" Class="mb-4">
|
||||
@if (_loading) { <MudProgressCircular Size="Size.Small" Class="mr-2" /> }
|
||||
Se connecter
|
||||
</MudButton>
|
||||
</form>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
FullWidth="true"
|
||||
ButtonType="ButtonType.Submit"
|
||||
Disabled="@_loading"
|
||||
Class="mud-button-submit">
|
||||
@if (_loading)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Class="mr-2" Color="Color.Inherit" />
|
||||
}
|
||||
@(_loading ? "Connexion en cours…" : "Se connecter")
|
||||
</MudButton>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<MudText Typo="Typo.body2" Align="Align.Center">
|
||||
Pas encore de compte ?
|
||||
<MudLink Href="/register">Créer un compte</MudLink>
|
||||
</MudText>
|
||||
</MudPaper>
|
||||
</MudContainer>
|
||||
<div class="auth-footer">
|
||||
<p>
|
||||
Pas encore de compte ?
|
||||
<a href="/register">Créer un compte</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string _email = "";
|
||||
|
||||
@@ -7,40 +7,72 @@
|
||||
@inject HeimdallAuthStateProvider AuthStateProvider
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraSmall" Class="mt-16">
|
||||
<MudPaper Elevation="5" Class="pa-8" Style="border-radius: 16px;">
|
||||
<MudText Typo="Typo.h5" Align="Align.Center" Class="mb-6">Créer un compte</MudText>
|
||||
<div class="auth-page">
|
||||
<div class="auth-card">
|
||||
<div class="auth-header">
|
||||
<div class="auth-icon">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Shield" Size="Size.Large" />
|
||||
</div>
|
||||
<h1>Créer un compte</h1>
|
||||
<p>Rejoignez la plateforme Heimdall</p>
|
||||
</div>
|
||||
|
||||
<form @onsubmit="RegisterAsync" method="post">
|
||||
<MudTextField @bind-Value="_displayName" Label="Nom d'affichage" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true"
|
||||
Autocomplete="name" />
|
||||
<MudTextField @bind-Value="_email" Label="Email" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true"
|
||||
Autocomplete="email" />
|
||||
<MudTextField @bind-Value="_password" Label="Mot de passe" Variant="Variant.Outlined"
|
||||
InputType="InputType.Password" Class="mb-6" Required="true" Immediate="true"
|
||||
HelperText="Minimum 12 caractères"
|
||||
Autocomplete="new-password" />
|
||||
<div class="auth-form">
|
||||
<form @onsubmit="RegisterAsync" method="post">
|
||||
<MudTextField @bind-Value="_displayName"
|
||||
Label="Nom d'affichage"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-4"
|
||||
Required="true"
|
||||
Immediate="true"
|
||||
Autocomplete="name" />
|
||||
<MudTextField @bind-Value="_email"
|
||||
Label="Email"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-4"
|
||||
Required="true"
|
||||
Immediate="true"
|
||||
Autocomplete="email" />
|
||||
<MudTextField @bind-Value="_password"
|
||||
Label="Mot de passe"
|
||||
Variant="Variant.Outlined"
|
||||
InputType="InputType.Password"
|
||||
Class="mb-4"
|
||||
Required="true"
|
||||
Immediate="true"
|
||||
HelperText="Minimum 12 caractères"
|
||||
Autocomplete="new-password" />
|
||||
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_errorMessage</MudAlert>
|
||||
}
|
||||
<div class="auth-error">
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">@_errorMessage</MudAlert>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
||||
ButtonType="ButtonType.Submit" Disabled="@_loading" Class="mb-4">
|
||||
@if (_loading) { <MudProgressCircular Size="Size.Small" Class="mr-2" /> }
|
||||
S'inscrire
|
||||
</MudButton>
|
||||
</form>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
FullWidth="true"
|
||||
ButtonType="ButtonType.Submit"
|
||||
Disabled="@_loading"
|
||||
Class="mud-button-submit">
|
||||
@if (_loading)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Class="mr-2" Color="Color.Inherit" />
|
||||
}
|
||||
@(_loading ? "Création en cours…" : "S'inscrire")
|
||||
</MudButton>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<MudText Typo="Typo.body2" Align="Align.Center">
|
||||
Déjà un compte ?
|
||||
<MudLink Href="/login">Se connecter</MudLink>
|
||||
</MudText>
|
||||
</MudPaper>
|
||||
</MudContainer>
|
||||
<div class="auth-footer">
|
||||
<p>
|
||||
Déjà un compte ?
|
||||
<a href="/login">Se connecter</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string _email = "";
|
||||
|
||||
@@ -103,11 +103,194 @@ code {
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
/* ─── Dark mode ────────────────────────────────────────────────── */
|
||||
/* ─── Auth pages (Login / Register) ─────────────────────────────── */
|
||||
|
||||
.auth-page {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
padding: 1.5rem;
|
||||
background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Decorative background circles */
|
||||
.auth-page::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -25%;
|
||||
right: -15%;
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.auth-page::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -20%;
|
||||
left: -10%;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(168, 85, 247, 0.1) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
background: rgba(255, 255, 255, 0.98);
|
||||
border-radius: 20px;
|
||||
padding: 2.5rem 2rem;
|
||||
box-shadow:
|
||||
0 25px 50px -12px rgba(0, 0, 0, 0.25),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.05);
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
animation: auth-card-enter 0.4s ease-out;
|
||||
}
|
||||
|
||||
@keyframes auth-card-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(16px) scale(0.98);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.auth-header .auth-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 16px;
|
||||
background: linear-gradient(135deg, #6366f1, #8b5cf6);
|
||||
color: #fff;
|
||||
margin-bottom: 1rem;
|
||||
box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
margin: 0 0 0.25rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
font-size: 0.875rem;
|
||||
color: #64748b;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.auth-form .mud-input-outlined {
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.auth-form .mud-button-submit {
|
||||
height: 48px;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
border-radius: 12px;
|
||||
text-transform: none;
|
||||
letter-spacing: 0.01em;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.auth-error {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
text-align: center;
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1.25rem;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.auth-footer p {
|
||||
font-size: 0.875rem;
|
||||
color: #64748b;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: #6366f1;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.auth-footer a:hover {
|
||||
color: #4f46e5;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* ─── Dark mode for auth pages ──────────────────────────────────── */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.auth-card {
|
||||
background: rgba(30, 41, 59, 0.98);
|
||||
box-shadow:
|
||||
0 25px 50px -12px rgba(0, 0, 0, 0.5),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.auth-form .mud-input-outlined {
|
||||
background: #1e293b;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
border-top-color: #334155;
|
||||
}
|
||||
|
||||
.auth-footer p {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: #818cf8;
|
||||
}
|
||||
|
||||
.auth-footer a:hover {
|
||||
color: #a5b4fc;
|
||||
}
|
||||
}
|
||||
|
||||
/* ─── Dark mode (general) ──────────────────────────────────────── */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html, body {
|
||||
background-color: #1e1e2e;
|
||||
background-color: #0f172a;
|
||||
}
|
||||
|
||||
#blazor-error-ui {
|
||||
|
||||
Reference in new issue
Block a user