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

Feature/establishment by ukprn v1 #401

Closed
wants to merge 6 commits into from
Closed
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
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dfe.Academies.Domain\Dfe.Academies.Domain.csproj" />
</ItemGroup>

</Project>
82 changes: 82 additions & 0 deletions Dfe.Academies.Api.Infrastructure/MstrContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

using Dfe.Academies.Domain.Trust;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Dfe.Academies.Academisation.Data;

public class MstrContext : DbContext
{
const string DEFAULT_SCHEMA = "mstr";
public MstrContext(DbContextOptions<MstrContext> options) : base(options)
{

}

public DbSet<Trust> Trusts { get; set; } = null!; // done


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Trust>(ConfigureTrust);

base.OnModelCreating(modelBuilder);
}

/// <summary>
/// New mapping for refactoring
/// </summary>
/// <param name="trustConfiguration"></param>

void ConfigureTrust(EntityTypeBuilder<Trust> trustConfiguration)
{
trustConfiguration.HasKey(e => e.SK).HasName("SK");

trustConfiguration.ToTable("Trust", DEFAULT_SCHEMA);

trustConfiguration.Property(e => e.TrustsTrustType).HasColumnName("FK_TrustType");
trustConfiguration.Property(e => e.Region).HasColumnName("FK_Region");
trustConfiguration.Property(e => e.TrustBanding).HasColumnName("FK_TrustBanding");
trustConfiguration.Property(e => e.FK_TrustStatus).HasColumnName("FK_TrustStatus");
trustConfiguration.Property(e => e.GroupUID).HasColumnName("Group UID").IsRequired();
trustConfiguration.Property(e => e.GroupID).HasColumnName("Group ID");
trustConfiguration.Property(e => e.RID).HasColumnName("RID");
trustConfiguration.Property(e => e.Name).HasColumnName("Name").IsRequired();
trustConfiguration.Property(e => e.CompaniesHouseNumber).HasColumnName("Companies House Number");
trustConfiguration.Property(e => e.ClosedDate).HasColumnName("Closed Date");
trustConfiguration.Property(e => e.TrustStatus).HasColumnName("Trust Status");
trustConfiguration.Property(e => e.JoinedDate).HasColumnName("Joined Date");
trustConfiguration.Property(e => e.MainPhone).HasColumnName("Main Phone");
trustConfiguration.Property(e => e.AddressLine1).HasColumnName("Address Line1");
trustConfiguration.Property(e => e.AddressLine2).HasColumnName("Address Line2");
trustConfiguration.Property(e => e.AddressLine3).HasColumnName("Address Line3");
trustConfiguration.Property(e => e.Town).HasColumnName("Town");
trustConfiguration.Property(e => e.County).HasColumnName("County");
trustConfiguration.Property(e => e.Postcode).HasColumnName("Postcode");
trustConfiguration.Property(e => e.PrioritisedForReview).HasColumnName("Prioritised for Review");
trustConfiguration.Property(e => e.CurrentSingleListGrouping).HasColumnName("Current Single List Grouping");
trustConfiguration.Property(e => e.DateOfGroupingDecision).HasColumnName("Date of Grouping Decision");
trustConfiguration.Property(e => e.DateEnteredOntoSingleList).HasColumnName("Date Entered Onto Single List");
trustConfiguration.Property(e => e.TrustReviewWriteUp).HasColumnName("Trust Review Write Up");
trustConfiguration.Property(e => e.DateOfTrustReviewMeeting).HasColumnName("Date of Trust Review Meeting");
trustConfiguration.Property(e => e.FollowUpLetterSent).HasColumnName("Follow Up Letter Sent");
trustConfiguration.Property(e => e.DateActionPlannedFor).HasColumnName("Date Action Planned For");
trustConfiguration.Property(e => e.WIPSummaryGoesToMinister).HasColumnName("WIP Summary Goes To Minister");
trustConfiguration.Property(e => e.ExternalGovernanceReviewDate).HasColumnName("External Governance Review Date");
trustConfiguration.Property(e => e.EfficiencyICFPReviewCompleted).HasColumnName("Efficiency ICFP Review Completed");
trustConfiguration.Property(e => e.EfficiencyICFPReviewOther).HasColumnName("Efficiency ICFP Review Other");
trustConfiguration.Property(e => e.LinkToWorkplaceForEfficiencyICFPReview).HasColumnName("Link To Workplace For Efficiency ICFP Review");
trustConfiguration.Property(e => e.NumberInTrust).HasColumnName("Number In Trust");
trustConfiguration.Property(e => e.Modified).HasColumnName("Modified");
trustConfiguration.Property(e => e.ModifiedBy).HasColumnName("Modified By");
trustConfiguration.Property(e => e.AMSDTerritory).HasColumnName("AMSD Territory");
trustConfiguration.Property(e => e.LeadAMSDTerritory).HasColumnName("Lead AMSD Territory");
trustConfiguration.Property(e => e.UKPRN).HasColumnName("UKPRN");
trustConfiguration.Property(e => e.TrustPerformanceAndRiskDateOfMeeting).HasColumnName("Trust Performance And Risk Date Of Meeting");
trustConfiguration.Property(e => e.UPIN).HasColumnName("UPIN");
trustConfiguration.Property(e => e.IncorporatedOnOpenDate).HasColumnName("Incorporated on (open date)");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Dfe.Academies.Academisation.Data;
using Dfe.Academies.Academisation.Data.Repositories;
using Dfe.Academies.Domain.Establishment;
using Dfe.Academies.Domain.Trust;
using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Infrastructure.Repositories
{
public class EstablishmentRepository : GenericRepository<Establishment>, IEstablishmentRepository
{
public EstablishmentRepository(MstrContext context) : base(context)
{
}

public async Task<Establishment?> GetEstablishmentByUkprn(string ukprn, CancellationToken cancellationToken)
{
var Establishment = await this.dbSet.SingleOrDefaultAsync(x => x.UKPRN == ukprn).ConfigureAwait(false);

return Establishment;
}
}
}
53 changes: 53 additions & 0 deletions Dfe.Academies.Api.Infrastructure/Repositories/GenericRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Dfe.Academies.Academisation.Domain.SeedWork;
using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Academisation.Data.Repositories
{
public abstract class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class
{
internal MstrContext context;
internal DbSet<TEntity> dbSet;

public GenericRepository(MstrContext context)
{
this.context = context;
dbSet = context.Set<TEntity>();
}

public void Insert(TEntity obj)
{
dbSet.Add(obj);
}

public Task<IEnumerable<TEntity>> GetAll()
{
throw new NotImplementedException();
}

public async Task<TEntity> GetById(int id)
{
return await dbSet.FindAsync(id).ConfigureAwait(false);
}

public void Delete(int id)
{
TEntity entityToDelete = dbSet.Find(id);
Delete(entityToDelete);
}

public void Delete(TEntity entityToDelete)
{
if (context.Entry(entityToDelete).State == EntityState.Detached)
{
dbSet.Attach(entityToDelete);
}
dbSet.Remove(entityToDelete);
}

public void Update(TEntity obj)
{
dbSet.Attach(obj);
context.Entry(obj).State = EntityState.Modified;
}
}
}
21 changes: 21 additions & 0 deletions Dfe.Academies.Api.Infrastructure/Repositories/TrustRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Dfe.Academies.Academisation.Data;
using Dfe.Academies.Academisation.Data.Repositories;
using Dfe.Academies.Domain.Trust;
using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Infrastructure.Repositories
{
public class TrustRepository : GenericRepository<Trust>, ITrustRepository
{
public TrustRepository(MstrContext context) : base(context)
{
}

public async Task<Trust?> GetTrustByUkprn(string ukprn, CancellationToken cancellationToken)
{
var trust = await this.dbSet.SingleOrDefaultAsync(x => x.UKPRN == ukprn).ConfigureAwait(false);

return trust;
}
}
}
41 changes: 41 additions & 0 deletions Dfe.Academies.Application/ApplicationServiceConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Dfe.Academies.Academisation.Data;
using Dfe.Academies.Application.Queries.Trust;
using Dfe.Academies.Domain.Establishment;
using Dfe.Academies.Domain.Trust;
using Dfe.Academies.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Extensions.DependencyInjection
{
public static class ApplicationServiceCollectionExtensions
{
//public static IServiceCollection AddConfig(
// this IServiceCollection services, IConfiguration config)
//{
// services.Configure<PositionOptions>(
// config.GetSection(PositionOptions.Position));
// services.Configure<ColorOptions>(
// config.GetSection(ColorOptions.Color));

// return services;
//}

public static IServiceCollection AddApplicationDependencyGroup(
this IServiceCollection services, IConfiguration config)
{
//Queries
services.AddScoped<ITrustQueries, TrustQueries>();

//Repos
services.AddScoped<ITrustRepository, TrustRepository>();
services.AddScoped<IEstablishmentRepository, EstablishmentRepository>();

//Db
services.AddDbContext<MstrContext>(options =>
options.UseSqlServer(config.GetConnectionString("DefaultConnection")));

return services;
}
}
}
20 changes: 20 additions & 0 deletions Dfe.Academies.Application/Dfe.Academies.Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dfe.Academies.Contracts" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dfe.Academies.Api.Infrastructure\Dfe.Academies.Infrastructure.csproj" />
<ProjectReference Include="..\Dfe.Academies.Domain\Dfe.Academies.Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Dfe.Academies.Contracts.Establishments;
using Dfe.Academies.Domain.Establishment;

namespace Dfe.Academies.Application.Queries.Establishment
{
public class EstablishmentQueries : IEstablishmentQueries
{
private readonly IEstablishmentRepository _establishmentRepository;

public EstablishmentQueries(IEstablishmentRepository establishmentRepository)
{
_establishmentRepository = establishmentRepository;
}
public async Task<EstablishmentDto?> GetByUkprn(string ukprn, CancellationToken cancellationToken)
{
var establishment = await _establishmentRepository.GetEstablishmentByUkprn(ukprn, cancellationToken).ConfigureAwait(false);

return establishment == null ? null : new EstablishmentDto()
{
Name = establishment.EstablishmentName,
Urn = establishment?.URN.ToString() ?? string.Empty, // To question
LocalAuthorityCode = establishment?.FK_LocalAuthority.ToString() ?? string.Empty, // To question
LocalAuthorityName = establishment?.FK_LocalAuthority.ToString() ?? string.Empty, // To question/we're missing it's name unless the above is it
OfstedRating = establishment.OfstedRating,
OfstedLastInspection = establishment.OfstedLastInspection,
StatutoryLowAge = establishment.StatutoryLowAge,
StatutoryHighAge = establishment.StatutoryHighAge,
SchoolCapacity = establishment.SchoolCapacity,
Pfi = establishment.SchoolCapacity, // Not available
EstablishmentNumber = establishment?.EstablishmentNumber.ToString() ?? string.Empty,
Diocese = new NameAndCodeDto
{
Name = establishment.Diocese,
Code = establishment.Diocese // No Code
},
// There is no type, just a FK to a type
//EstablishmentType = new NameAndCodeDto
//{
// Name = establishment.FK_EstablishmentType,
// Code = establishment.FK_EstablishmentType // No Code
//},
Gor = new NameAndCodeDto
{
Name = establishment.GORregion, // This is all we have, may or may not align
Code = establishment.GORregion // No Code
},
PhaseOfEducation = new NameAndCodeDto
{
Name = establishment.PhaseOfEducation,
Code = establishment.PhaseOfEducation // No Code
},
ReligiousCharacter = new NameAndCodeDto
{
Name = establishment.ReligiousCharacter,
Code = establishment.ReligiousCharacter // No Code
},
ParliamentaryConstituency = new NameAndCodeDto
{
Name = establishment.ParliamentaryConstituency,
Code = establishment.ParliamentaryConstituency // No Code
},
Census = new CensusDto
{
NumberOfPupils = establishment.NumberOfPupils,
PercentageFsm = establishment.PercentageFSM
},
MISEstablishment = new MisEstablishmentDto
{
DateOfLatestSection8Inspection = establishment.DateOfLatestShortInspection.ToString(), // May not be correct
InspectionEndDate = establishment.InspectionEndDate.ToString(),
OverallEffectiveness = establishment.OverallEffectiveness.ToString(),
QualityOfEducation = establishment.QualityOfEducation.ToString(),
BehaviourAndAttitudes = establishment.BehaviourAndAttitudes.ToString(),
PersonalDevelopment = establishment.PersonalDevelopment.ToString(),
EffectivenessOfLeadershipAndManagement = establishment.EffectivenessOfLeadershipAndManagement.ToString(),
EarlyYearsProvision = establishment.EarlyYearsProvisionWhereApplicable.ToString(),
SixthFormProvision = establishment.SixthFormProvisionWhereApplicable.ToString(),
Weblink = establishment.Website,
},
Address = new AddressDto()
{
Street = establishment.AddressLine1,
Town = establishment.Town,
Postcode = establishment.Postcode,
County = establishment.County,
Additional = establishment.AddressLine2,
Locality = establishment.AddressLine3
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Dfe.Academies.Contracts.Establishments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dfe.Academies.Application.Queries.Establishment
{
public interface IEstablishmentQueries
{
Task<EstablishmentDto?> GetByUkprn(string ukprn, CancellationToken cancellationToken);
}
}
14 changes: 14 additions & 0 deletions Dfe.Academies.Application/Queries/Trust/ITrustQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Dfe.Academies.Contracts.Trusts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dfe.Academies.Application.Queries.Trust
{
public interface ITrustQueries
{
Task<TrustDto?> GetByUkprn(string ukprn, CancellationToken cancellationToken);
}
}
Loading