- Domain: GroupCameraAccess entity with IAuditableEntity - Group entity: added GroupCameraAccesses navigation collection - Camera entity: added GroupCameraAccesses navigation collection - Infrastructure: DbSet, configuration with unique constraint on (GroupId, CameraId) - Application: CQRS commands/queries for group camera access - AddCameraToGroupCommand / RemoveCameraFromGroupCommand - GetCamerasByGroupQuery - DTOs: GroupCameraAccessResponse, CreateGroupCameraAccessRequest, DeleteGroupCameraAccessRequest - Web: GroupCamerasController with REST endpoints - All 1700+ tests pass
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Heimdall.Domain.Primitives;
|
|
|
|
namespace Heimdall.Domain.Entities;
|
|
|
|
/// <summary>
|
|
/// Represents a user group for organizing and managing access permissions.
|
|
/// </summary>
|
|
public class Group : Entity<Guid>, IAuditableEntity, ISoftDeletable
|
|
{
|
|
public string Name { get; private set; } = string.Empty;
|
|
public string? Description { get; private set; }
|
|
|
|
// IAuditableEntity
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
|
// ISoftDeletable
|
|
public bool IsDeleted { get; private set; }
|
|
public DateTime? DeletedAt { get; private set; }
|
|
|
|
// Navigation
|
|
private readonly List<UserGroup> _userGroups = [];
|
|
public IReadOnlyCollection<UserGroup> UserGroups => _userGroups.AsReadOnly();
|
|
|
|
private readonly List<GroupCameraAccess> _groupCameraAccesses = [];
|
|
public IReadOnlyCollection<GroupCameraAccess> GroupCameraAccesses => _groupCameraAccesses.AsReadOnly();
|
|
|
|
private Group() { } // EF Core
|
|
|
|
public Group(string name, string? description)
|
|
: base(Guid.NewGuid())
|
|
{
|
|
SetName(name);
|
|
Description = description;
|
|
}
|
|
|
|
/// <summary>Updates the group's name and description.</summary>
|
|
public void Update(string name, string? description)
|
|
{
|
|
SetName(name);
|
|
Description = description;
|
|
}
|
|
|
|
/// <summary>Validates and sets the group name.</summary>
|
|
public void SetName(string name)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
throw new ArgumentException("Group name is required", nameof(name));
|
|
Name = name.Trim();
|
|
}
|
|
|
|
public void SoftDelete()
|
|
{
|
|
IsDeleted = true;
|
|
DeletedAt = DateTime.UtcNow;
|
|
}
|
|
}
|