43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
using Heimdall.Domain.Entities;
|
|||
|
|
using Heimdall.Infrastructure.Data.Interceptors;
|
||
|
|
using Microsoft.AspNetCore.Identity;
|
||
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
namespace Heimdall.Infrastructure.Data;
|
||
|
|
|
||
|
|
public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>
|
||
|
|
{
|
||
|
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||
|
|
|
||
|
|
// Domain entities
|
||
|
|
public DbSet<Site> Sites => Set<Site>();
|
||
|
|
public DbSet<Agent> Agents => Set<Agent>();
|
||
|
|
public DbSet<Camera> Cameras => Set<Camera>();
|
||
|
|
public DbSet<CameraCredentials> CameraCredentials => Set<CameraCredentials>();
|
||
|
|
public DbSet<CameraDetectionProfile> CameraDetectionProfiles => Set<CameraDetectionProfile>();
|
||
|
|
public DbSet<UserSite> UserSites => Set<UserSite>();
|
||
|
|
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
|
||
|
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
||
|
|
|
||
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
||
|
|
{
|
||
|
|
base.OnModelCreating(builder);
|
||
|
|
|
||
|
|
builder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
|
||
|
|
|
||
|
|
// Global soft-delete filter
|
||
|
|
builder.Entity<Site>().HasQueryFilter(e => !e.IsDeleted);
|
||
|
|
builder.Entity<Agent>().HasQueryFilter(e => !e.IsDeleted);
|
||
|
|
builder.Entity<Camera>().HasQueryFilter(e => !e.IsDeleted);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||
|
|
{
|
||
|
|
optionsBuilder.AddInterceptors(
|
||
|
|
new AuditInterceptor(),
|
||
|
|
new SoftDeleteInterceptor());
|
||
|
|
|
||
|
|
base.OnConfiguring(optionsBuilder);
|
||
|
|
}
|
||
|
|
}
|