Skip to content

Commit

Permalink
Merge pull request #518 from DFE-Digital/governance-in-sat
Browse files Browse the repository at this point in the history
Governance in sat
  • Loading branch information
dneed-nimble authored Sep 26, 2024
2 parents 460888e + af58072 commit ca3380a
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 166 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added

- Run migrations for FIAT database on application container startup
- Governance pages will now have relevant data for SATs, using the URN as an alternative to the trust UID
- Contacts pages will now have relevant data for SATs, using the URN as an alternative to the trust UID
- All Trust contacts now have the internal data that pertains to their email addresses, where present in our unpublished GIAS data.

## [Release-7][release-7] (production-2024-09-23.3213)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mstr;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mstr;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Contexts;

Expand All @@ -27,4 +27,4 @@ protected static void OnModelCreatingMstrTrusts(ModelBuilder modelBuilder)
.HasColumnName("GORregion");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Tad;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Contexts;

public partial class AcademiesDbContext
{
public DbSet<TadTrustGovernance> TadTrustGovernances { get; set; }

[ExcludeFromCodeCoverage]
protected static void OnModelCreatingTadTrustGovernances(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TadTrustGovernance>(entity =>
{
entity.HasNoKey().ToTable("TrustGovernance", "tad");
entity.Property(e => e.Email)
.IsUnicode(false);
entity.Property(e => e.Gid)
.IsUnicode(false)
.HasColumnName("GID");
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Cdm;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Cdm;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Gias;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mis;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mstr;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Ops;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Tad;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Contexts;

Expand All @@ -19,7 +20,7 @@ public interface IAcademiesDbContext
DbSet<MisEstablishment> MisEstablishments { get; }
DbSet<MisFurtherEducationEstablishment> MisFurtherEducationEstablishments { get; }
DbSet<CdmSystemuser> CdmSystemusers { get; }
DbSet<MstrTrustGovernance> MstrTrustGovernances { get; }
DbSet<TadTrustGovernance> TadTrustGovernances { get; }
DbSet<ApplicationEvent> ApplicationEvents { get; }
DbSet<ApplicationSetting> ApplicationSettings { get; }
}
Expand All @@ -46,7 +47,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
OnModelCreatingMisEstablishment(modelBuilder);
OnModelCreatingCdmSystemusers(modelBuilder);
OnModelCreatingMisFurtherEducationEstablishments(modelBuilder);
OnModelCreatingMstrTrustGovernances(modelBuilder);
OnModelCreatingTadTrustGovernances(modelBuilder);
OnModelCreatingMstrTrusts(modelBuilder);
OnModelCreatingApplicationSettings(modelBuilder);
OnModelCreatingApplicationEvents(modelBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DfE.FindInformationAcademiesTrusts.Data\DfE.FindInformationAcademiesTrusts.Data.csproj"/>
<ProjectReference Include="..\DfE.FindInformationAcademiesTrusts.Data\DfE.FindInformationAcademiesTrusts.Data.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Extensions;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Gias;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mstr;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Tad;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Factories;

public interface IGovernorFactory
{
Governor CreateFrom(GiasGovernance giasGovernance, MstrTrustGovernance mstrGovernance);
Governor CreateFrom(GiasGovernance giasGovernance, TadTrustGovernance tadGovernance);
}

public class GovernorFactory : IGovernorFactory
{
public Governor CreateFrom(GiasGovernance giasGovernance, MstrTrustGovernance mstrGovernance)
public Governor CreateFrom(GiasGovernance giasGovernance, TadTrustGovernance tadGovernance)
{
return new Governor(
giasGovernance.Gid!,
Expand All @@ -21,7 +21,7 @@ public Governor CreateFrom(GiasGovernance giasGovernance, MstrTrustGovernance ms
giasGovernance.AppointingBody!,
giasGovernance.DateOfAppointment.ParseAsNullableDate(),
giasGovernance.DateTermOfOfficeEndsEnded.ParseAsNullableDate(),
mstrGovernance.Email
tadGovernance.Email
);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Diagnostics.CodeAnalysis;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Tad;

[ExcludeFromCodeCoverage] // Database model POCO
public class TadTrustGovernance
{
public string? Gid { get; set; }

public string? Email { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Contexts;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Extensions;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Gias;
using DfE.FindInformationAcademiesTrusts.Data.Repositories.Trust;
using Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -58,31 +59,47 @@ public async Task<TrustDetails> GetTrustDetailsAsync(string uid)
return trustDetailsDto;
}

public async Task<TrustGovernance> GetTrustGovernanceAsync(string uid)
public async Task<TrustGovernance> GetTrustGovernanceAsync(string uid, string? urn = null)
{
var governors = await academiesDbContext.GiasGovernances
.Where(g => g.Uid == uid)
.Select(governance => new Governor(governance.Gid!, governance.Uid!,
IQueryable<GiasGovernance> query = academiesDbContext.GiasGovernances;

var governors = await FilterBySatOrMat(uid, urn, query)
.Select(governance => new Governor(
governance.Gid!,
governance.Uid!,
GetFullName(governance.Forename1!, governance.Forename2!, governance.Surname!),
governance.Role!, governance.AppointingBody!, governance.DateOfAppointment.ParseAsNullableDate(),
governance.DateTermOfOfficeEndsEnded.ParseAsNullableDate(), null))
governance.Role!,
governance.AppointingBody!,
governance.DateOfAppointment.ParseAsNullableDate(),
governance.DateTermOfOfficeEndsEnded.ParseAsNullableDate(),
null))
.ToArrayAsync();

var governersDto = new TrustGovernance(
governors.Where(governor => governor is { IsCurrentGovernor: true, HasRoleLeadership: true }).ToArray(),
governors.Where(governor => governor is { IsCurrentGovernor: true, HasRoleMemeber: true })
.ToArray(),
governors.Where(governor => governor is { IsCurrentGovernor: true, HasRoleTrustee: true })
.ToArray(),
governors.Where(governor => governor.IsCurrentGovernor is false).ToArray()
governors.Where(g => g.IsCurrentGovernor && g.HasRoleLeadership).ToArray(),
governors.Where(g => g.IsCurrentGovernor && g.HasRoleMember).ToArray(),
governors.Where(g => g.IsCurrentGovernor && g.HasRoleTrustee).ToArray(),
governors.Where(g => !g.IsCurrentGovernor).ToArray()
);

return governersDto;
}
public static IQueryable<GiasGovernance> FilterBySatOrMat(string uid, string? urn, IQueryable<GiasGovernance> query)
{
if (!string.IsNullOrEmpty(urn))
{
// Use urn if it's provided as that means this is a Single Academy Trust (SAT)
return query.Where(g => g.Urn == urn);
}

return query.Where(g => g.Uid == uid);
}

public async Task<TrustContacts> GetTrustContactsAsync(string uid)
public async Task<TrustContacts> GetTrustContactsAsync(string uid, string? urn = null)
{
var trm = await GetTrustRelationshipManagerLinkedTo(uid);
var sfso = await GetSfsoLeadLinkedTo(uid);
var governanceContacts = await GetGovernanceContactsAsync(uid);
var governanceContacts = await GetGovernanceContactsAsync(uid, urn);

return new TrustContacts(
trm,
Expand All @@ -92,6 +109,7 @@ public async Task<TrustContacts> GetTrustContactsAsync(string uid)
governanceContacts.GetValueOrDefault("Chief Financial Officer"));
}


private async Task<string> GetRegionAndTerritoryAsync(string uid)
{
return await academiesDbContext.MstrTrusts
Expand Down Expand Up @@ -133,11 +151,16 @@ private static string GetFullName(string forename1, string forename2, string sur
.SingleOrDefaultAsync();
}

private async Task<Dictionary<string, Person>> GetGovernanceContactsAsync(string uid)
private async Task<Dictionary<string, Person>> GetGovernanceContactsAsync(string uid, string? urn = null)
{
string[] roles = ["Chair of Trustees", "Accounting Officer", "Chief Financial Officer"];
var governors = (await academiesDbContext.GiasGovernances
.Where(governance => governance.Uid == uid && roles.Contains(governance.Role))
string[] roles = { "Chair of Trustees", "Accounting Officer", "Chief Financial Officer" };

IQueryable<GiasGovernance> query = academiesDbContext.GiasGovernances;

query = FilterBySatOrMat(uid, urn, query);

var governors = (await query
.Where(governance => roles.Contains(governance.Role))
.Select(governance => new
{
governance.Gid,
Expand All @@ -150,9 +173,9 @@ private async Task<Dictionary<string, Person>> GetGovernanceContactsAsync(string

var gids = governors.Select(g => g.Gid).ToArray();

var governorEmails = await academiesDbContext.MstrTrustGovernances
.Where(mstrTrustGovernance => gids.Contains(mstrTrustGovernance.Gid))
.Select(mstrTrustGovernance => new { mstrTrustGovernance.Gid, mstrTrustGovernance.Email }).ToArrayAsync();
var governorEmails = await academiesDbContext.TadTrustGovernances
.Where(tadTrustGovernance => gids.Contains(tadTrustGovernance.Gid))
.Select(tadTrustGovernance => new { tadTrustGovernance.Gid, tadTrustGovernance.Email }).ToArrayAsync();

return governors.ToDictionary(
governor => governor.Role,
Expand All @@ -161,4 +184,5 @@ private async Task<Dictionary<string, Person>> GetGovernanceContactsAsync(string
governorEmails.SingleOrDefault(governorEmail => governorEmail.Gid == governor.Gid)?.Email)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private async Task<Governor[]> GetGovernorsLinkedTo(string uid)
{
return await academiesDbContext.GiasGovernances
.Where(g => g.Uid == uid)
.Join(academiesDbContext.MstrTrustGovernances,
.Join(academiesDbContext.TadTrustGovernances,
gg => gg.Gid!,
mtg => mtg.Gid,
(gg, mtg) => governorFactory.CreateFrom(gg, mtg))
Expand Down
2 changes: 1 addition & 1 deletion DfE.FindInformationAcademiesTrusts.Data/Governor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record Governor(
HasRoleAccountingOfficer || HasRoleChiefFinancialOfficer ||
HasRoleChairOfTrustees;

public bool HasRoleMemeber => Role == "Member";
public bool HasRoleMember => Role == "Member";

public bool HasRoleTrustee => Role == "Trustee";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public interface ITrustRepository
{
Task<TrustSummary?> GetTrustSummaryAsync(string uid);
Task<TrustDetails> GetTrustDetailsAsync(string uid);
Task<TrustGovernance> GetTrustGovernanceAsync(string uid);
Task<TrustContacts> GetTrustContactsAsync(string uid);
Task<TrustGovernance> GetTrustGovernanceAsync(string uid, string? urn = null);
Task<TrustContacts> GetTrustContactsAsync(string uid, string? urn = null);
}
17 changes: 12 additions & 5 deletions DfE.FindInformationAcademiesTrusts/Services/Trust/TrustService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,25 @@ public async Task<TrustDetailsServiceModel> GetTrustDetailsAsync(string uid)

return trustDetailsDto;
}

public async Task<TrustGovernanceServiceModel> GetTrustGovernanceAsync(string uid)
{
var (trustLeadership, members, trustees, historicMembers) = await trustRepository.GetTrustGovernanceAsync(uid);
var governanceDto = new TrustGovernanceServiceModel(trustLeadership, members, trustees, historicMembers);
return governanceDto;
var urn = await academyRepository.GetSingleAcademyTrustAcademyUrnAsync(uid);

var trustGovernance = await trustRepository.GetTrustGovernanceAsync(uid, urn);

return new TrustGovernanceServiceModel(
trustGovernance.TrustLeadership,
trustGovernance.Members,
trustGovernance.Trustees,
trustGovernance.HistoricMembers);
}

public async Task<TrustContactsServiceModel> GetTrustContactsAsync(string uid)
{
var urn = await academyRepository.GetSingleAcademyTrustAcademyUrnAsync(uid);

var (trustRelationshipManager, sfsoLead, accountingOfficer, chairOfTrustees, chiefFinancialOfficer) =
await trustRepository.GetTrustContactsAsync(uid);
await trustRepository.GetTrustContactsAsync(uid, urn);

return new TrustContactsServiceModel(trustRelationshipManager, sfsoLead, accountingOfficer, chairOfTrustees,
chiefFinancialOfficer);
Expand Down
Loading

0 comments on commit ca3380a

Please sign in to comment.