feat: add EF Core layer with entities, configurations and DbContext
- Directory.Packages.props and Directory.Build.props for central package management - TemplateEntity, ProviderEntity, ProviderUsageEntity (internal to DAL.EF) - TemplateEntityConfiguration: composite unique index (service_name, key, language_code), Variables as JSON column - ProviderEntityConfiguration: settings stored as jsonb, index on (service_name, priority) - ProviderUsageEntityConfiguration: composite unique index (provider_id, date) - All entities map Id column explicitly as 'id' (snake_case) - NotificationDbContext with ApplyConfigurationsFromAssembly Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
<Project>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Entity Framework Core -->
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.5" />
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
|
||||
<!-- MediatR -->
|
||||
<PackageVersion Include="MediatR" Version="12.4.1" />
|
||||
<PackageVersion Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" />
|
||||
|
||||
<!-- Microsoft.Extensions -->
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.6" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.6" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.6" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.6" />
|
||||
|
||||
<!-- HrynCo shared packages -->
|
||||
<PackageVersion Include="HrynCo.RabbitMq" Version="1.0.11" />
|
||||
|
||||
<!-- Testing -->
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageVersion Include="xunit" Version="2.9.3" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
<PackageVersion Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.6.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -8,10 +8,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
<PackageReference Include="coverlet.collector" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Configurations;
|
||||
|
||||
internal class ProviderEntityConfiguration : IEntityTypeConfiguration<ProviderEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProviderEntity> builder)
|
||||
{
|
||||
builder.ToTable("providers");
|
||||
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.ServiceName)
|
||||
.HasColumnName("service_name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.HasIndex(x => new { x.ServiceName, x.Priority });
|
||||
|
||||
builder.Property(x => x.Priority).HasColumnName("priority");
|
||||
|
||||
builder.Property(x => x.ProviderType).HasColumnName("provider_type");
|
||||
|
||||
builder.Property(x => x.SettingsJson)
|
||||
.HasColumnName("settings")
|
||||
.HasColumnType("jsonb")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.DailyLimit).HasColumnName("daily_limit");
|
||||
builder.Property(x => x.MonthlyLimit).HasColumnName("monthly_limit");
|
||||
builder.Property(x => x.WarnThresholdPercent).HasColumnName("warn_threshold_percent");
|
||||
builder.Property(x => x.IsActive).HasColumnName("is_active");
|
||||
builder.Property(x => x.Created).HasColumnName("created");
|
||||
builder.Property(x => x.Updated).HasColumnName("updated");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Configurations;
|
||||
|
||||
internal class ProviderUsageEntityConfiguration : IEntityTypeConfiguration<ProviderUsageEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProviderUsageEntity> builder)
|
||||
{
|
||||
builder.ToTable("provider_usage");
|
||||
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.ProviderId).HasColumnName("provider_id");
|
||||
|
||||
builder.HasIndex(x => new { x.ProviderId, x.Date }).IsUnique();
|
||||
|
||||
builder.Property(x => x.Date).HasColumnName("date");
|
||||
builder.Property(x => x.SentCount).HasColumnName("sent_count");
|
||||
builder.Property(x => x.Created).HasColumnName("created");
|
||||
builder.Property(x => x.Updated).HasColumnName("updated");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Configurations;
|
||||
|
||||
internal class TemplateEntityConfiguration : IEntityTypeConfiguration<TemplateEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<TemplateEntity> builder)
|
||||
{
|
||||
builder.ToTable("templates");
|
||||
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.ServiceName)
|
||||
.HasColumnName("service_name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(x => x.Key)
|
||||
.HasColumnName("key")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(x => x.LanguageCode)
|
||||
.HasColumnName("language_code")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.HasIndex(x => new { x.ServiceName, x.Key, x.LanguageCode })
|
||||
.IsUnique();
|
||||
|
||||
builder.Property(x => x.Subject)
|
||||
.HasColumnName("subject")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.HtmlBody)
|
||||
.HasColumnName("html_body")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.TextBody)
|
||||
.HasColumnName("text_body")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Created).HasColumnName("created");
|
||||
builder.Property(x => x.Updated).HasColumnName("updated");
|
||||
|
||||
builder.OwnsMany(x => x.Variables, v =>
|
||||
{
|
||||
v.ToJson("variables");
|
||||
v.Property(x => x.Name).HasJsonPropertyName("name");
|
||||
v.Property(x => x.Required).HasJsonPropertyName("required");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using HrynCo.NotificationService.DAL.Abstract.Providers;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
internal class ProviderEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string ServiceName { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public ProviderType ProviderType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Provider-specific credentials and settings stored as JSONB.
|
||||
/// Deserialized based on <see cref="ProviderType"/> in the repository.
|
||||
/// </summary>
|
||||
public required string SettingsJson { get; set; }
|
||||
|
||||
public int? DailyLimit { get; set; }
|
||||
public int? MonthlyLimit { get; set; }
|
||||
public int WarnThresholdPercent { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public DateTimeOffset Created { get; set; }
|
||||
public DateTimeOffset? Updated { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
internal class ProviderUsageEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ProviderId { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public int SentCount { get; set; }
|
||||
public DateTimeOffset Created { get; set; }
|
||||
public DateTimeOffset? Updated { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
internal class TemplateEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string ServiceName { get; set; }
|
||||
public required string Key { get; set; }
|
||||
public required string LanguageCode { get; set; }
|
||||
public required string Subject { get; set; }
|
||||
public required string HtmlBody { get; set; }
|
||||
public required string TextBody { get; set; }
|
||||
public List<TemplateVariableData> Variables { get; set; } = [];
|
||||
public DateTimeOffset Created { get; set; }
|
||||
public DateTimeOffset? Updated { get; set; }
|
||||
}
|
||||
|
||||
internal class TemplateVariableData
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public bool Required { get; set; }
|
||||
}
|
||||
@@ -4,6 +4,16 @@
|
||||
<ProjectReference Include="..\HrynCo.NotificationService.DAL.Abstract\HrynCo.NotificationService.DAL.Abstract.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF;
|
||||
|
||||
public class NotificationDbContext : DbContext
|
||||
{
|
||||
public NotificationDbContext(DbContextOptions<NotificationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
internal DbSet<TemplateEntity> Templates => Set<TemplateEntity>();
|
||||
internal DbSet<ProviderEntity> Providers => Set<ProviderEntity>();
|
||||
internal DbSet<ProviderUsageEntity> ProviderUsage => Set<ProviderUsageEntity>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(NotificationDbContext).Assembly);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -8,10 +8,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
<PackageReference Include="coverlet.collector" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user