feat(mvp): complete MVP hardening — API, Web, config system, SignalR, tests
This commit is contained in:
1 parent
3fc42be4b2
commit
c2837af089
59 files changed
+4920
-81
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Heimdall.Application.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// A global application setting visible to all agents unless overridden.
|
||||
/// </summary>
|
||||
public sealed record AppSettingDto(
|
||||
[property: JsonPropertyName("id")] Guid Id,
|
||||
[property: JsonPropertyName("key")] string Key,
|
||||
[property: JsonPropertyName("value")] string Value,
|
||||
[property: JsonPropertyName("description")] string? Description,
|
||||
[property: JsonPropertyName("category")] string Category,
|
||||
[property: JsonPropertyName("valueType")] string ValueType,
|
||||
[property: JsonPropertyName("allowedValues")] string? AllowedValues,
|
||||
[property: JsonPropertyName("updatedAt")] DateTime UpdatedAt
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Per-agent setting override.
|
||||
/// </summary>
|
||||
public sealed record AgentSettingDto(
|
||||
[property: JsonPropertyName("id")] Guid Id,
|
||||
[property: JsonPropertyName("agentId")] Guid AgentId,
|
||||
[property: JsonPropertyName("key")] string Key,
|
||||
[property: JsonPropertyName("value")] string Value,
|
||||
[property: JsonPropertyName("updatedAt")] DateTime UpdatedAt
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Request to create a new global setting.
|
||||
/// </summary>
|
||||
public sealed record CreateAppSettingRequest(
|
||||
[property: JsonPropertyName("key")] string Key,
|
||||
[property: JsonPropertyName("value")] string Value,
|
||||
[property: JsonPropertyName("category")] string Category = "General",
|
||||
[property: JsonPropertyName("description")] string? Description = null,
|
||||
[property: JsonPropertyName("valueType")] string ValueType = "string",
|
||||
[property: JsonPropertyName("allowedValues")] string? AllowedValues = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Request to update an existing global setting value.
|
||||
/// </summary>
|
||||
public sealed record UpdateAppSettingRequest(
|
||||
[property: JsonPropertyName("value")] string Value,
|
||||
[property: JsonPropertyName("description")] string? Description = null,
|
||||
[property: JsonPropertyName("category")] string? Category = null,
|
||||
[property: JsonPropertyName("valueType")] string? ValueType = null,
|
||||
[property: JsonPropertyName("allowedValues")] string? AllowedValues = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Request to set a per-agent setting override.
|
||||
/// </summary>
|
||||
public sealed record SetAgentSettingRequest(
|
||||
[property: JsonPropertyName("key")] string Key,
|
||||
[property: JsonPropertyName("value")] string Value
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
using Heimdall.Application.Common;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Manages global settings and per-agent setting overrides.
|
||||
/// All changes are broadcast to connected agents via SignalR in real-time.
|
||||
/// </summary>
|
||||
public interface ISettingService
|
||||
{
|
||||
// Global settings
|
||||
Task<ServiceResult<List<AppSettingDto>>> GetAllSettingsAsync(CancellationToken ct = default);
|
||||
Task<ServiceResult<AppSettingDto>> GetSettingByKeyAsync(string key, CancellationToken ct = default);
|
||||
Task<ServiceResult<AppSettingDto>> CreateSettingAsync(CreateAppSettingRequest request, CancellationToken ct = default);
|
||||
Task<ServiceResult<AppSettingDto>> UpdateSettingAsync(string key, UpdateAppSettingRequest request, CancellationToken ct = default);
|
||||
Task<ServiceResult> DeleteSettingAsync(string key, CancellationToken ct = default);
|
||||
|
||||
// Agent-specific overrides
|
||||
Task<ServiceResult<List<AgentSettingDto>>> GetAgentSettingsAsync(Guid agentId, CancellationToken ct = default);
|
||||
Task<ServiceResult<AgentSettingDto>> SetAgentSettingAsync(Guid agentId, SetAgentSettingRequest request, CancellationToken ct = default);
|
||||
Task<ServiceResult> RemoveAgentSettingAsync(Guid agentId, string key, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the effective configuration for an agent: global defaults merged with
|
||||
/// per-agent overrides. Used by agents to fetch their full config on connect.
|
||||
/// </summary>
|
||||
Task<ServiceResult<Dictionary<string, string>>> GetEffectiveAgentConfigAsync(Guid agentId, CancellationToken ct = default);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class CreateAppSettingValidator : AbstractValidator<CreateAppSettingRequest>
|
||||
{
|
||||
public CreateAppSettingValidator()
|
||||
{
|
||||
RuleFor(x => x.Key).NotEmpty().MaximumLength(200)
|
||||
.Matches(@"^[a-z0-9][a-z0-9._-]*[a-z0-9]$")
|
||||
.WithMessage("Key must start and end with a lowercase alphanumeric character, and contain only lowercase letters, digits, dots, hyphens, or underscores");
|
||||
RuleFor(x => x.Value).NotNull();
|
||||
RuleFor(x => x.Category).NotEmpty().MaximumLength(100);
|
||||
RuleFor(x => x.ValueType).Must(t => t is "string" or "int" or "bool" or "double" or "select")
|
||||
.WithMessage("ValueType must be one of: string, int, bool, double, select");
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateAppSettingValidator : AbstractValidator<UpdateAppSettingRequest>
|
||||
{
|
||||
public UpdateAppSettingValidator()
|
||||
{
|
||||
RuleFor(x => x.Value).NotEmpty();
|
||||
When(x => x.Category is not null, () =>
|
||||
RuleFor(x => x.Category!).MaximumLength(100));
|
||||
When(x => x.ValueType is not null, () =>
|
||||
RuleFor(x => x.ValueType!).Must(t => t is "string" or "int" or "bool" or "double" or "select")
|
||||
.WithMessage("ValueType must be one of: string, int, bool, double, select"));
|
||||
}
|
||||
}
|
||||
|
||||
public class SetAgentSettingValidator : AbstractValidator<SetAgentSettingRequest>
|
||||
{
|
||||
public SetAgentSettingValidator()
|
||||
{
|
||||
RuleFor(x => x.Key).NotEmpty().MaximumLength(200);
|
||||
RuleFor(x => x.Value).NotNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class CreateCameraValidator : AbstractValidator<CreateCameraRequest>
|
||||
{
|
||||
public CreateCameraValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(200);
|
||||
RuleFor(x => x.RtspUrl).NotEmpty().Must(uri => Uri.TryCreate(uri, UriKind.Absolute, out _))
|
||||
.WithMessage("RTSP URL must be a valid absolute URI");
|
||||
RuleFor(x => x.SiteId).NotEmpty();
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
|
||||
|
||||
RuleFor(x => x.Password)
|
||||
.NotEmpty()
|
||||
.MinimumLength(8)
|
||||
.MinimumLength(12)
|
||||
.MaximumLength(200);
|
||||
|
||||
RuleFor(x => x.DisplayName)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class CreateUserValidator : AbstractValidator<CreateUserRequest>
|
||||
{
|
||||
public CreateUserValidator()
|
||||
{
|
||||
RuleFor(x => x.Email).NotEmpty().EmailAddress().MaximumLength(256);
|
||||
RuleFor(x => x.DisplayName).NotEmpty().MaximumLength(100);
|
||||
RuleFor(x => x.Password).NotEmpty().MinimumLength(12)
|
||||
.WithMessage("Password must be at least 12 characters");
|
||||
When(x => x.Roles is not null, () =>
|
||||
RuleFor(x => x.Roles!)
|
||||
.Must(roles => roles.All(r => r is "Admin" or "Supervisor" or "Viewer"))
|
||||
.WithMessage("Roles must be Admin, Supervisor, or Viewer"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class UpdateCameraValidator : AbstractValidator<UpdateCameraRequest>
|
||||
{
|
||||
public UpdateCameraValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(200);
|
||||
RuleFor(x => x.RtspUrl).NotEmpty().Must(uri => Uri.TryCreate(uri, UriKind.Absolute, out _))
|
||||
.WithMessage("RTSP URL must be a valid absolute URI");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class UpdateSiteValidator : AbstractValidator<UpdateSiteRequest>
|
||||
{
|
||||
public UpdateSiteValidator()
|
||||
{
|
||||
When(x => x.Name is not null, () =>
|
||||
RuleFor(x => x.Name!).MaximumLength(200));
|
||||
When(x => x.Address is not null, () =>
|
||||
RuleFor(x => x.Address!).MaximumLength(500));
|
||||
When(x => x.Timezone is not null, () =>
|
||||
RuleFor(x => x.Timezone!).MaximumLength(100));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using FluentValidation;
|
||||
using Heimdall.Application.DTOs;
|
||||
|
||||
namespace Heimdall.Application.Validators;
|
||||
|
||||
public class UpdateUserValidator : AbstractValidator<UpdateUserRequest>
|
||||
{
|
||||
public UpdateUserValidator()
|
||||
{
|
||||
When(x => x.DisplayName is not null, () =>
|
||||
RuleFor(x => x.DisplayName!).MaximumLength(100));
|
||||
When(x => x.Theme is not null, () =>
|
||||
RuleFor(x => x.Theme!).Must(t => t is "light" or "dark")
|
||||
.WithMessage("Theme must be 'light' or 'dark'"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user