From d24a20b4970fc80e7f991f057c91f3454f2cac62 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Thu, 22 Oct 2026 20:12:25 +0200 Subject: [PATCH] fix(events): filter person history by identity --- docs/audits/2026-10-20-audit-complet.md | 5 ++- .../DTOs/CameraEventDto.cs | 4 +- .../CreateEvent/CreateEventCommand.cs | 3 +- .../CreateEvent/CreateEventHandler.cs | 13 ++++++- .../Queries/GetEvent/GetEventHandler.cs | 2 +- .../Queries/GetEvents/GetEventsHandler.cs | 5 ++- .../Queries/GetEvents/GetEventsQuery.cs | 3 +- .../GetRecentByCameraHandler.cs | 2 +- .../Queries/GetVehicles/GetVehiclesQuery.cs | 5 ++- src/Heimdall.Domain/Entities/CameraEvent.cs | 4 ++ .../CameraEventConfiguration.cs | 1 + ...2003000_AddPersonIdentityToCameraEvents.cs | 35 +++++++++++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 5 +++ .../Components/Pages/PersonDetailPage.razor | 39 +++++++++++++------ .../Controllers/EventsController.cs | 5 ++- .../Controllers/VehiclesController.cs | 4 +- .../Services/HeimdallApiClient.cs | 9 +++-- .../Components/Pages/DashboardTests.cs | 2 +- .../HeimdallApiClientCoverageTests.cs | 2 +- 19 files changed, 118 insertions(+), 30 deletions(-) create mode 100644 src/Heimdall.Infrastructure/Migrations/20261022003000_AddPersonIdentityToCameraEvents.cs diff --git a/docs/audits/2026-10-20-audit-complet.md b/docs/audits/2026-10-20-audit-complet.md index 75c48e9..dea1ea6 100644 --- a/docs/audits/2026-10-20-audit-complet.md +++ b/docs/audits/2026-10-20-audit-complet.md @@ -4,7 +4,7 @@ Date de l’audit initial : 20 octobre 2026. Révision initiale : `7792353`. La ## État des corrections au 21 octobre 2026 -La revue initiale ci-dessous décrit les constats à la révision `7792353`. Les constats restent utiles pour comprendre le défaut, mais leur état opérationnel est désormais celui de cette matrice. Au 22 octobre, `main` inclut les PR #2–#47. Les PR #38–#44 durcissent le diagnostic et l’enrôlement agent, les mises à jour, l’image depuis Central, les rapports de statut et le tri des utilisateurs. La PR #45 traite PIPE-10, la #46 raccorde les détections aux notifications, et la #47 rend la rétention des recordings idempotente côté stockage et route par provider enregistré. Le run #144 a révélé une variable d’image manquante dans la validation Compose et le #145 une erreur de compilation dans la reprise idempotente; ces deux défauts ont été corrigés. Les runs #146–#150 ont ensuite échoué sur l’accès réseau à `sources.tordais.cc` ou le daemon Docker en lecture seule, avant de valider les changements complets. La compilation locale Domain/Application passe sur SDK 10.0.112, tandis que le dépôt exige 10.0.402; Infrastructure et les suites des PR récentes restent donc non certifiées. Les PR antérieures et leurs résultats restent détaillés ci-dessous; la publication d’une release n’a pas été exercée. +La revue initiale ci-dessous décrit les constats à la révision `7792353`. Les constats restent utiles pour comprendre le défaut, mais leur état opérationnel est désormais celui de cette matrice. Au 22 octobre, `main` inclut les PR #2–#49. Les PR #38–#44 durcissent le diagnostic et l’enrôlement agent, les mises à jour, l’image depuis Central, les rapports de statut et le tri des utilisateurs. La PR #45 traite PIPE-10, la #46 raccorde les détections aux notifications, la #47 sécurise la rétention des recordings et la #49 persiste leur destination historique. Le run #155 a compilé les projets et révélé sept erreurs héritées dans les notifications, l’agent Docker et le spool SQLite; elles ont été corrigées dans la PR #49. Les essais #156–#157 ont échoué au checkout faute de connexion à `sources.tordais.cc`, avant de valider ces corrections. Domain compile localement avec SDK 10.0.112; les tests et la compilation complète restent à confirmer sur un runner fonctionnel. Les PR antérieures et leurs résultats restent détaillés ci-dessous; la publication d’une release n’a pas été exercée. | État | Constats | Preuve / réserve | |---|---|---| @@ -17,7 +17,8 @@ La revue initiale ci-dessous décrit les constats à la révision `7792353`. Les | Corrigé et validé CI | OPS-05 | PR #18, run #64 vert sur `0bde726` : manifeste accessible par identité agent, ordre manuel ciblé via ConfigHub, traitement natif/Docker. | | Corrigé et fusionné | AGENT-01 à AGENT-07, PIPE-10, FEAT-05, OPS-01 (recordings) | PR #38–#43, #45–#47. PIPE-10 utilise un spool SQLite stable; FEAT-05 crée une alerte par destinataire caméra autorisé et enfile les canaux externes; OPS-01 supprime les objets avant leurs références SQL. Les runs récents n’ont pas pu valider ces changements à cause des runners. | | Partiellement corrigé | OPS-02 | PR #49 capture provider, bucket/endpoint S3 ou racine locale sur les nouveaux recordings et route leur rétention avec cette destination. Les anciennes lignes ne contiennent pas cette provenance et sont conservées; le pipeline d’enregistrement vidéo n’écrit actuellement aucun objet et devra renseigner cette métadonnée à son raccordement. | -| Ouvert sur `main` | PIPE-01, PIPE-02, PIPE-09, OPS-02 (médias hors recordings et lignes historiques), UI-02, FEAT-01, FEAT-02, FEAT-03, QA-01, DOC-01, AGENT-08 à AGENT-10 | Parcours incomplets, références de stockage historiques impossibles à reconstituer pour les anciennes lignes et intégration de la provenance aux futurs uploads de médias; validations nécessitant des intégrations, du matériel ou de l’exploitation. | +| Partiellement corrigé | UI-02 | PR #50 ajoute PersonId aux événements, filtre l’historique et les véhicules côté API et charge l’historique par pages. Le détecteur biométrique FEAT-03 devra renseigner PersonId lors de la création des événements pour que les nouvelles détections apparaissent par identité. | +| Ouvert sur `main` | PIPE-01, PIPE-02, PIPE-09, OPS-02 (médias hors recordings et lignes historiques), UI-02 (liaison FEAT-03), FEAT-01, FEAT-02, FEAT-03, QA-01, DOC-01, AGENT-08 à AGENT-10 | Parcours incomplets, références de stockage historiques impossibles à reconstituer pour les anciennes lignes et intégration de la provenance aux futurs uploads de médias; validations nécessitant des intégrations, du matériel ou de l’exploitation. | | Corrigé et fusionné | UI-03 | PR #36, commit `56a6177` : digests quotidiens/hebdomadaires bornés en UTC sur `OccurredAt`, filtrés avec la politique caméra complète. Les tests Infrastructure passent (307/307); le build et les tests post-fusion #114 passent, ainsi que les archives, images et contrôles de sécurité. | | À valider hors CI | Vérifications complémentaires § ci-dessous | Caméras réelles, réseau/TURN, SMTP/ntfy, S3, charge et restauration de sauvegarde ne sont pas certifiés par le run automatisé. | diff --git a/src/Heimdall.Application/DTOs/CameraEventDto.cs b/src/Heimdall.Application/DTOs/CameraEventDto.cs index f356492..51e65e8 100644 --- a/src/Heimdall.Application/DTOs/CameraEventDto.cs +++ b/src/Heimdall.Application/DTOs/CameraEventDto.cs @@ -7,6 +7,7 @@ public record CameraEventResponse( Guid CameraId, Guid SiteId, Guid? AgentId, + Guid? PersonId, EventType Type, double Confidence, string? Label, @@ -23,7 +24,8 @@ public record CreateCameraEventRequest( string? Label, string? MetadataJson, DateTime? OccurredAt, - Guid? EventId = null); + Guid? EventId = null, + Guid? PersonId = null); public record CameraEventFilterRequest( Guid? CameraId, diff --git a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventCommand.cs b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventCommand.cs index 18273b8..3041301 100644 --- a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventCommand.cs +++ b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventCommand.cs @@ -12,4 +12,5 @@ public record CreateEventCommand( string? Label, string? MetadataJson, DateTime? OccurredAt, - Guid? EventId = null) : IRequest>; + Guid? EventId = null, + Guid? PersonId = null) : IRequest>; diff --git a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs index 35a092f..ccf1a13 100644 --- a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs +++ b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs @@ -27,6 +27,15 @@ public class CreateEventHandler : IRequestHandler.NotFound("Camera not found"); + if (request.PersonId.HasValue) + { + var personExists = await _context.Persons + .AnyAsync(p => p.Id == request.PersonId.Value, ct) + .ConfigureAwait(false); + if (!personExists) + return ServiceResult.Failure("Person not found", 400); + } + var eventId = request.EventId ?? Guid.NewGuid(); if (request.EventId.HasValue) { @@ -45,6 +54,8 @@ public class CreateEventHandler : IRequestHandler new( - e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.Type, e.Confidence, + e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.PersonId, e.Type, e.Confidence, e.Label, e.SnapshotUrl, e.SnapshotThumbUrl, e.MetadataJson, e.OccurredAt, e.CreatedAt); } diff --git a/src/Heimdall.Application/Events/Queries/GetEvent/GetEventHandler.cs b/src/Heimdall.Application/Events/Queries/GetEvent/GetEventHandler.cs index dd0cedc..d92812a 100644 --- a/src/Heimdall.Application/Events/Queries/GetEvent/GetEventHandler.cs +++ b/src/Heimdall.Application/Events/Queries/GetEvent/GetEventHandler.cs @@ -43,7 +43,7 @@ public class GetEventHandler : IRequestHandler new( - e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.Type, e.Confidence, + e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.PersonId, e.Type, e.Confidence, e.Label, e.SnapshotUrl, e.SnapshotThumbUrl, e.MetadataJson, e.OccurredAt, e.CreatedAt); } diff --git a/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsHandler.cs b/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsHandler.cs index 0fb7bf2..764ede4 100644 --- a/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsHandler.cs +++ b/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsHandler.cs @@ -44,6 +44,9 @@ public class GetEventsHandler : IRequestHandler e.Type == request.Type.Value); + if (request.PersonId.HasValue) + query = query.Where(e => e.PersonId == request.PersonId.Value); + if (request.From.HasValue) query = query.Where(e => e.OccurredAt >= request.From.Value); @@ -81,7 +84,7 @@ public class GetEventsHandler : IRequestHandler new( - e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.Type, e.Confidence, + e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.PersonId, e.Type, e.Confidence, e.Label, e.SnapshotUrl, e.SnapshotThumbUrl, e.MetadataJson, e.OccurredAt, e.CreatedAt); } diff --git a/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsQuery.cs b/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsQuery.cs index 39bc76d..5dccbcf 100644 --- a/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsQuery.cs +++ b/src/Heimdall.Application/Events/Queries/GetEvents/GetEventsQuery.cs @@ -16,4 +16,5 @@ public record GetEventsQuery( int PageSize = 50, string? Search = null, Guid? UserId = null, - bool HasSnapshot = false) : IRequest>>; + bool HasSnapshot = false, + Guid? PersonId = null) : IRequest>>; diff --git a/src/Heimdall.Application/Events/Queries/GetRecentByCamera/GetRecentByCameraHandler.cs b/src/Heimdall.Application/Events/Queries/GetRecentByCamera/GetRecentByCameraHandler.cs index e4cf4de..fba28b7 100644 --- a/src/Heimdall.Application/Events/Queries/GetRecentByCamera/GetRecentByCameraHandler.cs +++ b/src/Heimdall.Application/Events/Queries/GetRecentByCamera/GetRecentByCameraHandler.cs @@ -43,7 +43,7 @@ public class GetRecentByCameraHandler : IRequestHandler new( - e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.Type, e.Confidence, + e.Id, e.CameraId, e.Camera.SiteId, e.AgentId, e.PersonId, e.Type, e.Confidence, e.Label, e.SnapshotUrl, e.SnapshotThumbUrl, e.MetadataJson, e.OccurredAt, e.CreatedAt); } diff --git a/src/Heimdall.Application/Vehicles/Queries/GetVehicles/GetVehiclesQuery.cs b/src/Heimdall.Application/Vehicles/Queries/GetVehicles/GetVehiclesQuery.cs index 2912366..e84983e 100644 --- a/src/Heimdall.Application/Vehicles/Queries/GetVehicles/GetVehiclesQuery.cs +++ b/src/Heimdall.Application/Vehicles/Queries/GetVehicles/GetVehiclesQuery.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore; namespace Heimdall.Application.Vehicles.Queries.GetVehicles; -public record GetVehiclesQuery(string? Search = null, int Page = 1, int PageSize = 50) +public record GetVehiclesQuery(string? Search = null, int Page = 1, int PageSize = 50, Guid? PersonId = null) : IRequest>>; public class GetVehiclesQueryHandler : IRequestHandler>> @@ -21,6 +21,9 @@ public class GetVehiclesQueryHandler : IRequestHandler v.Person) .AsNoTracking(); + if (request.PersonId.HasValue) + query = query.Where(v => v.PersonId == request.PersonId.Value); + // Search by license plate (case-insensitive contains) if (!string.IsNullOrWhiteSpace(request.Search)) { diff --git a/src/Heimdall.Domain/Entities/CameraEvent.cs b/src/Heimdall.Domain/Entities/CameraEvent.cs index e5e4d68..4f27949 100644 --- a/src/Heimdall.Domain/Entities/CameraEvent.cs +++ b/src/Heimdall.Domain/Entities/CameraEvent.cs @@ -23,6 +23,9 @@ public class CameraEvent : Entity, IAuditableEntity /// Vehicle linked to this event (Event → Vehicle N:1). public Guid? VehicleId { get; private set; } + /// Known person linked by face recognition; kept as an application-level reference because the table is partitioned. + public Guid? PersonId { get; private set; } + /// Recording segment linked to this event (Event → Recording N:1). public Guid? RecordingId { get; private set; } @@ -89,6 +92,7 @@ public class CameraEvent : Entity, IAuditableEntity public void AssignAgent(Guid agentId) => AgentId = agentId; public void AssignVehicle(Guid vehicleId) => VehicleId = vehicleId; + public void AssignPerson(Guid personId) => PersonId = personId; public void AssignRecording(Guid recordingId) => RecordingId = recordingId; public void AssignParentEvent(Guid parentEventId) => ParentEventId = parentEventId; public void SetTrackId(string trackId) => TrackId = trackId; diff --git a/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs index 032cd2c..2cc1cf7 100644 --- a/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs +++ b/src/Heimdall.Infrastructure/Data/Configurations/CameraEventConfiguration.cs @@ -69,6 +69,7 @@ public class CameraEventConfiguration : IEntityTypeConfiguration builder.HasIndex(e => e.DetectionHash); builder.HasIndex(e => e.ParentEventId); builder.HasIndex(e => e.VehicleId); + builder.HasIndex(e => new { e.PersonId, e.OccurredAt }); builder.HasIndex(e => e.RecordingId); // GIN index for JSONB metadata queries (spec 2.3) diff --git a/src/Heimdall.Infrastructure/Migrations/20261022003000_AddPersonIdentityToCameraEvents.cs b/src/Heimdall.Infrastructure/Migrations/20261022003000_AddPersonIdentityToCameraEvents.cs new file mode 100644 index 0000000..75c5bfe --- /dev/null +++ b/src/Heimdall.Infrastructure/Migrations/20261022003000_AddPersonIdentityToCameraEvents.cs @@ -0,0 +1,35 @@ +using Heimdall.Infrastructure.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Heimdall.Infrastructure.Migrations; + +[DbContext(typeof(AppDbContext))] +[Migration("20261022003000_AddPersonIdentityToCameraEvents")] +public partial class AddPersonIdentityToCameraEvents : Migration +{ + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PersonId", + table: "camera_events", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_PersonId_OccurredAt", + table: "camera_events", + columns: new[] { "PersonId", "OccurredAt" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_camera_events_PersonId_OccurredAt", + table: "camera_events"); + + migrationBuilder.DropColumn(name: "PersonId", table: "camera_events"); + } +} diff --git a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index 496eecc..538c393 100644 --- a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -1136,6 +1136,9 @@ namespace Heimdall.Infrastructure.Migrations b.Property("ParentEventId") .HasColumnType("uuid"); + b.Property("PersonId") + .HasColumnType("uuid"); + b.Property("RecordingId") .HasColumnType("uuid"); @@ -1178,6 +1181,8 @@ namespace Heimdall.Infrastructure.Migrations b.HasIndex("ParentEventId"); + b.HasIndex("PersonId", "OccurredAt"); + b.HasIndex("RecordingId"); b.HasIndex("TrackId"); diff --git a/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor b/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor index 590ab0d..25739de 100644 --- a/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor +++ b/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor @@ -220,6 +220,13 @@ else + @if (_events.Count < _eventsTotalCount) + { + + Load more (@_events.Count / @_eventsTotalCount) + + } } @@ -268,6 +275,9 @@ else private List _faces = []; private List _vehicles = []; private List _events = []; + private int _eventsTotalCount; + private int _eventsPage = 1; + private const int EventsPageSize = 50; private bool _loading = true; private bool _facesLoading = true; @@ -319,30 +329,37 @@ else _vehiclesLoading = true; try { - var all = await Api.GetVehiclesAsync(); - _vehicles = (all?.Where(v => v.PersonId == Id).ToList()) ?? []; + _vehicles = await Api.GetVehiclesAsync(Id) ?? []; } catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); } finally { _vehiclesLoading = false; } } - private async Task LoadEvents() + private async Task LoadEvents(bool append = false) { _eventsLoading = true; try { - var result = await Api.GetEventsAsync(null, null, page: 1, pageSize: 50, - type: "FaceRecognized", from: _eventsSince); - var all = result?.Items ?? []; - var name = _person?.DisplayName; - _events = string.IsNullOrEmpty(name) - ? all - : all.Where(e => e.Label?.Contains(name, StringComparison.OrdinalIgnoreCase) == true).ToList(); + if (!append) + { + _eventsPage = 1; + _events = []; + } + var result = await Api.GetEventsAsync(null, null, page: _eventsPage, pageSize: EventsPageSize, + type: "FaceRecognized", from: _eventsSince, personId: Id); + if (result is not null) + { + _eventsTotalCount = result.TotalCount; + _events.AddRange(result.Items); + _eventsPage++; + } } catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); } finally { _eventsLoading = false; } } + private Task LoadMoreEvents() => LoadEvents(append: true); + private async Task OnPersonUpdated(PersonClientItem person) { _person = person; @@ -383,4 +400,4 @@ else "unknown" => "Unknown", _ => "—" }; -} \ No newline at end of file +} diff --git a/src/Heimdall.Web/Controllers/EventsController.cs b/src/Heimdall.Web/Controllers/EventsController.cs index e8c1231..496d285 100644 --- a/src/Heimdall.Web/Controllers/EventsController.cs +++ b/src/Heimdall.Web/Controllers/EventsController.cs @@ -35,7 +35,7 @@ public class EventsController : ControllerBase [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task Create([FromBody] CreateCameraEventRequest request, CancellationToken ct) { - var command = new CreateEventCommand(request.CameraId, request.Type, request.Confidence, request.Label, request.MetadataJson, request.OccurredAt, request.EventId); + var command = new CreateEventCommand(request.CameraId, request.Type, request.Confidence, request.Label, request.MetadataJson, request.OccurredAt, request.EventId, request.PersonId); var result = await _mediator.Send(command, ct); return result.IsSuccess ? Ok(result.Data) @@ -71,6 +71,7 @@ public class EventsController : ControllerBase [FromQuery] bool hasSnapshot = false, [FromQuery] int page = 1, [FromQuery] int pageSize = 50, + [FromQuery] Guid? personId = null, CancellationToken ct = default) { EventType? parsedType = null; @@ -78,7 +79,7 @@ public class EventsController : ControllerBase parsedType = t; var userId = GetUserId(); - var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q, userId, hasSnapshot), ct); + var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q, userId, hasSnapshot, personId), ct); return Ok(result.Data); } diff --git a/src/Heimdall.Web/Controllers/VehiclesController.cs b/src/Heimdall.Web/Controllers/VehiclesController.cs index 027ac07..ab230f1 100644 --- a/src/Heimdall.Web/Controllers/VehiclesController.cs +++ b/src/Heimdall.Web/Controllers/VehiclesController.cs @@ -23,9 +23,9 @@ public class VehiclesController : ControllerBase [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleRead)] [HttpGet] - public async Task GetAll([FromQuery] string? search, [FromQuery] int page = 1, [FromQuery] int pageSize = 50, CancellationToken ct = default) + public async Task GetAll([FromQuery] string? search, [FromQuery] int page = 1, [FromQuery] int pageSize = 50, [FromQuery] Guid? personId = null, CancellationToken ct = default) { - var result = await _mediator.Send(new GetVehiclesQuery(search, page, pageSize), ct); + var result = await _mediator.Send(new GetVehiclesQuery(search, page, pageSize, personId), ct); return Ok(result.Data); } diff --git a/src/Heimdall.Web/Services/HeimdallApiClient.cs b/src/Heimdall.Web/Services/HeimdallApiClient.cs index bf96396..cf8ce66 100644 --- a/src/Heimdall.Web/Services/HeimdallApiClient.cs +++ b/src/Heimdall.Web/Services/HeimdallApiClient.cs @@ -856,22 +856,24 @@ public class HeimdallApiClient : IDisposable // ─── Vehicles (filtered client-side by PersonId) ────────────────── - public async Task?> GetVehiclesAsync() + public async Task?> GetVehiclesAsync(Guid? personId = null) { var client = CreateClient(); - return await client.GetFromJsonAsync>("api/vehicles", Json); + var query = personId.HasValue ? $"?personId={personId.Value}" : string.Empty; + return await client.GetFromJsonAsync>($"api/vehicles{query}", Json); } // ─── Events ──────────────────────────────────────────────────────── public async Task GetEventsAsync(Guid? cameraId, Guid? siteId, int page = 1, int pageSize = 50, - string? q = null, string? type = null, DateTime? from = null, DateTime? to = null, bool hasSnapshot = false) + string? q = null, string? type = null, DateTime? from = null, DateTime? to = null, bool hasSnapshot = false, Guid? personId = null) { var client = CreateClient(); var query = $"page={page}&pageSize={pageSize}"; if (cameraId.HasValue) query += $"&cameraId={cameraId}"; if (siteId.HasValue) query += $"&siteId={siteId}"; if (hasSnapshot) query += "&hasSnapshot=true"; + if (personId.HasValue) query += $"&personId={personId.Value}"; if (!string.IsNullOrWhiteSpace(q)) query += $"&q={Uri.EscapeDataString(q)}"; if (!string.IsNullOrWhiteSpace(type)) query += $"&type={Uri.EscapeDataString(type)}"; if (from.HasValue) query += $"&from={Uri.EscapeDataString(from.Value.ToString("O", System.Globalization.CultureInfo.InvariantCulture))}"; @@ -1203,6 +1205,7 @@ public record SetAgentSettingRequest( public record EventItem( [property: JsonPropertyName("id")] Guid Id, [property: JsonPropertyName("cameraId")] Guid CameraId, + [property: JsonPropertyName("personId")] Guid? PersonId, [property: JsonPropertyName("type")] string Type, [property: JsonPropertyName("confidence")] double Confidence, [property: JsonPropertyName("label")] string? Label, diff --git a/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs index fe607c9..44c2bea 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/DashboardTests.cs @@ -49,7 +49,7 @@ public class DashboardTests : PageTestBase Handler.OnGet("api/events", new EventPageResult( [new EventItem( - Guid.NewGuid(), CameraId, "PersonDetected", 0.87, "Personne", + Guid.NewGuid(), CameraId, null, "PersonDetected", 0.87, "Personne", "/snapshots/1.jpg", "/snapshots/1-thumb.jpg", DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow)], 1, 1, 10)); diff --git a/tests/Heimdall.Web.Tests/Services/HeimdallApiClientCoverageTests.cs b/tests/Heimdall.Web.Tests/Services/HeimdallApiClientCoverageTests.cs index cfbd554..3ddfc64 100644 --- a/tests/Heimdall.Web.Tests/Services/HeimdallApiClientCoverageTests.cs +++ b/tests/Heimdall.Web.Tests/Services/HeimdallApiClientCoverageTests.cs @@ -575,7 +575,7 @@ public sealed class HeimdallApiClientCoverageTests : IDisposable SetAuthToken(); var id = Guid.NewGuid(); _handler.QueueResponse(HttpStatusCode.OK, new EventItem( - id, Guid.NewGuid(), "Motion", 0.95, "person", null, null, + id, Guid.NewGuid(), null, "Motion", 0.95, "person", null, null, DateTime.UtcNow, DateTime.UtcNow)); var result = await _sut.GetEventAsync(id); -- 2.54.1