Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Endpoint "getAssociatedPersonsWithtrust" #621

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public static IServiceCollection AddPersonsApiInfrastructureDependencyGroup(
services.AddScoped<ITrustRepository, TrustRepository>();
services.AddScoped<IEstablishmentRepository, EstablishmentRepository>();
services.AddScoped<IConstituencyRepository, ConstituencyRepository>();
services.AddScoped(typeof(IMstrRepository<,>), typeof(MstrRepository<,>));
services.AddScoped(typeof(IMopRepository<,>), typeof(MopRepository<,>));

// Query Services
services.AddScoped<IEstablishmentQueryService, EstablishmentQueryService>();
services.AddScoped<ITrustQueryService, TrustQueryService>();


//Cache service
services.Configure<CacheSettings>(config.GetSection("CacheSettings"));
Expand Down
16 changes: 0 additions & 16 deletions Dfe.Academies.Api.Infrastructure/MopRepository.cs

This file was deleted.

32 changes: 31 additions & 1 deletion Dfe.Academies.Api.Infrastructure/MstrContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public MstrContext(DbContextOptions<MstrContext> options) : base(options)
public DbSet<IfdPipeline> IfdPipelines { get; set; } = null!;
public DbSet<GovernanceRoleType> GovernanceRoleTypes { get; set; } = null!;
public DbSet<EducationEstablishmentGovernance> EducationEstablishmentGovernances { get; set; } = null!;
public DbSet<TrustGovernance> TrustGovernances { get; set; } = null!;


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down Expand Up @@ -57,6 +58,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<GovernanceRoleType>(ConfigureGovernanceRoleType);
modelBuilder.Entity<GovernanceRoleType>().Metadata.SetIsTableExcludedFromMigrations(false);

modelBuilder.Entity<TrustGovernance>(ConfigureTrustGovernance);
modelBuilder.Entity<TrustGovernance>().Metadata.SetIsTableExcludedFromMigrations(false);
}
else
{
Expand All @@ -65,6 +69,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<GovernanceRoleType>(ConfigureGovernanceRoleType);
modelBuilder.Entity<GovernanceRoleType>().Metadata.SetIsTableExcludedFromMigrations(true);

modelBuilder.Entity<TrustGovernance>(ConfigureTrustGovernance);
modelBuilder.Entity<TrustGovernance>().Metadata.SetIsTableExcludedFromMigrations(true);
}

base.OnModelCreating(modelBuilder);
Expand Down Expand Up @@ -338,7 +345,6 @@ private static void ConfigureEducationEstablishmentGovernance(EntityTypeBuilder<

}


private static void ConfigureGovernanceRoleType(EntityTypeBuilder<GovernanceRoleType> governanceRoleTypeConfiguration)
{
governanceRoleTypeConfiguration.HasKey(e => e.SK);
Expand All @@ -351,4 +357,28 @@ private static void ConfigureGovernanceRoleType(EntityTypeBuilder<GovernanceRole
governanceRoleTypeConfiguration.Property(e => e.ModifiedBy).HasColumnName("Modified By");

}

private static void ConfigureTrustGovernance(EntityTypeBuilder<TrustGovernance> trustGovernanceConfiguration)
{
trustGovernanceConfiguration.HasKey(e => e.SK);
trustGovernanceConfiguration.ToTable("TrustGovernance", DEFAULT_SCHEMA);
trustGovernanceConfiguration.Property(e => e.SK).HasColumnName("SK");
trustGovernanceConfiguration.Property(e => e.TrustId).HasColumnName("FK_Trust");
trustGovernanceConfiguration.Property(e => e.GovernanceRoleTypeId).HasColumnName("FK_GovernanceRoleType");
trustGovernanceConfiguration.Property(e => e.GID)
.HasColumnName("GID")
.IsRequired()
.HasMaxLength(100);

trustGovernanceConfiguration.Property(e => e.Title).HasColumnName("Title");
trustGovernanceConfiguration.Property(e => e.Forename1).HasColumnName("Forename1");
trustGovernanceConfiguration.Property(e => e.Forename2).HasColumnName("Forename2");
trustGovernanceConfiguration.Property(e => e.Surname).HasColumnName("Surname");
trustGovernanceConfiguration.Property(e => e.Email).HasColumnName("Email").HasMaxLength(200);
trustGovernanceConfiguration.Property(e => e.DateOfAppointment).HasColumnName("Date of appointment");
trustGovernanceConfiguration.Property(e => e.DateTermOfOfficeEndsOrEnded).HasColumnName("Date term of office ends/ended");
trustGovernanceConfiguration.Property(e => e.AppointingBody).HasColumnName("Appointing body");
trustGovernanceConfiguration.Property(e => e.Modified).HasColumnName("Modified");
trustGovernanceConfiguration.Property(e => e.ModifiedBy).HasColumnName("Modified By");
}
}
15 changes: 0 additions & 15 deletions Dfe.Academies.Api.Infrastructure/MstrRepository.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Dfe.Academies.Application.Common.Interfaces;
using Dfe.Academies.Infrastructure.Models;
using Dfe.Academies.Application.Common.Models;
using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Infrastructure.QueryServices
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Dfe.Academies.Application.Common.Interfaces;
using Dfe.Academies.Application.Common.Models;
using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Infrastructure.QueryServices
{
internal class TrustQueryService(MstrContext context) : ITrustQueryService
{
public IQueryable<TrustGovernanceQueryModel?>? GetTrustGovernanceByGroupIdOrUkprn(string? groupId, string? ukPrn)
{

// Check if the trust exists based on GroupID or UKPRN
var trustExists = context.Trusts.AsNoTracking().Any(t =>
(!string.IsNullOrEmpty(groupId) && t.GroupID == groupId) ||
(!string.IsNullOrEmpty(ukPrn) && t.UKPRN == ukPrn));

if (!trustExists)
{
return null;
}

var query = from t in context.Trusts.AsNoTracking()
join tg in context.TrustGovernances.AsNoTracking()
on t.SK equals tg.TrustId
join grt in context.GovernanceRoleTypes.AsNoTracking()
on tg.GovernanceRoleTypeId equals grt.SK
where (!string.IsNullOrEmpty(groupId) && t.GroupID == groupId) ||
(!string.IsNullOrEmpty(ukPrn) && t.UKPRN == ukPrn)
select new TrustGovernanceQueryModel(t, grt, tg);

return query;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Dfe.Academies.Domain.Establishment;
using Dfe.Academies.Domain.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
using Dfe.Academies.Infrastructure.Models;

namespace Dfe.Academies.Infrastructure.Repositories
{
Expand Down
194 changes: 0 additions & 194 deletions Dfe.Academies.Api.Infrastructure/Repositories/Repository.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ public static IServiceCollection AddApplicationDependencyGroup(
public static IServiceCollection AddPersonsApiApplicationDependencyGroup(
this IServiceCollection services, IConfiguration config)
{
var performanceLoggingEnabled = config.GetValue<bool>("Features:PerformanceLoggingEnabled");

services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());

services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));

if (performanceLoggingEnabled)
{
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
}
});

return services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dfe.Academies.Infrastructure.Models;
using Dfe.Academies.Application.Common.Models;

namespace Dfe.Academies.Application.Common.Interfaces
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Dfe.Academies.Application.Common.Models;

namespace Dfe.Academies.Application.Common.Interfaces
{
public interface ITrustQueryService
{
IQueryable<TrustGovernanceQueryModel?>? GetTrustGovernanceByGroupIdOrUkprn(string? groupId, string? ukPrn);
}
}
Loading
Loading