Skip to content

Commit

Permalink
Merge pull request #537 from DFE-Digital/feature/173335-grouping-proj…
Browse files Browse the repository at this point in the history
…ects

Split Set Project Group endpoint into Assign user and update Project Group's Conversion Project Endpoints
  • Loading branch information
paullocknimble authored Aug 2, 2024
2 parents a12ce45 + a1af7bc commit 1a6c908
Show file tree
Hide file tree
Showing 42 changed files with 3,162 additions and 394 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Dfe.Academies.Academisation.Data.Migrations
{
/// <inheritdoc />
public partial class addprojectgroupextrafields : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "TrustName",
schema: "academisation",
table: "ProjectGroups",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");

migrationBuilder.AddColumn<string>(
name: "TrustUkprn",
schema: "academisation",
table: "ProjectGroups",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TrustName",
schema: "academisation",
table: "ProjectGroups");

migrationBuilder.DropColumn(
name: "TrustUkprn",
schema: "academisation",
table: "ProjectGroups");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
Expand Down Expand Up @@ -768,10 +768,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("ReferenceNumber")
.HasColumnType("nvarchar(max)");

b.Property<string>("TrustName")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("TrustReference")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("TrustUkprn")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("ProjectGroups", "academisation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public ConversionProjectRepository(AcademisationContext context, IMapper mapper)
return (projects, totalProjects);
}

public async Task<IEnumerable<IProject>?> GetProjectsByProjectGroupAsync(List<int> projectGroupIds, CancellationToken cancellationToken)
{
return await _context.Projects
.Where(p => projectGroupIds.Contains(p.ProjectGroupId.GetValueOrDefault()))
.ToListAsync(cancellationToken);
}

public async Task<ProjectFilterParameters> GetFilterParameters()
{
var advisoryBoardDates = await dbSet
Expand Down Expand Up @@ -96,6 +89,13 @@ private static IQueryable<Project> FilterFormAMAT(IQueryable<Project> queryable)
return queryable;
}

private static IQueryable<Project> FilterGroupedProjects(IQueryable<Project> queryable)
{
queryable = queryable.Where(p => p.ProjectGroupId != null);

return queryable;
}

public async Task<IEnumerable<IProject>?> GetIncompleteProjects()
{
var createdProjectState = await _context.Projects
Expand Down Expand Up @@ -243,6 +243,25 @@ private IQueryable<Project> DefaultIncludes()
return (projects, totalProjects);
}

public async Task<(IEnumerable<IProject> projects, int totalCount)> SearchGroupedProjects(IEnumerable<string>? states, string? title, IEnumerable<string>? deliveryOfficers, IEnumerable<string>? regions, IEnumerable<string>? localAuthorities, IEnumerable<string>? advisoryBoardDates)
{
IQueryable<Project> queryable = dbSet;

queryable = FilterGroupedProjects(queryable);
queryable = FilterByRegion(regions, queryable);
queryable = FilterByStatus(states, queryable);
queryable = FilterByKeyword(title, queryable);
queryable = FilterByDeliveryOfficer(deliveryOfficers, queryable);
queryable = FilterByLocalAuthority(localAuthorities, queryable);
queryable = FilterByAdvisoryBoardDates(advisoryBoardDates, queryable);

var totalProjects = queryable.Select(p => p.ProjectGroupId).Distinct().Count();
var projects = await queryable
.OrderByDescending(acp => acp.CreatedOn).ToListAsync();

return (projects, totalProjects);
}

private IQueryable<Project> FilterByAdvisoryBoardDates(IEnumerable<string>? advisoryBoardDates, IQueryable<Project> queryable)
{
if (advisoryBoardDates != null && advisoryBoardDates.Any())
Expand All @@ -255,7 +274,7 @@ private IQueryable<Project> FilterByAdvisoryBoardDates(IEnumerable<string>? advi
return queryable;
}

private static IQueryable<Project> FilterByLocalAuthority(IEnumerable<string> localAuthorities, IQueryable<Project> queryable)
private static IQueryable<Project> FilterByLocalAuthority(IEnumerable<string>? localAuthorities, IQueryable<Project> queryable)
{
if (localAuthorities != null && localAuthorities.Any())
{
Expand Down Expand Up @@ -283,19 +302,36 @@ public async Task<IEnumerable<IProject>> GetConversionProjectsByFormAMatIds(IEnu
return await dbSet.Where(x => formAMatProjectIds.Contains(x.FormAMatProjectId)).ToListAsync(cancellationToken).ConfigureAwait(false);
}

public async Task<IEnumerable<IProject>> GetConversionProjectsForGroup(string trustReferenceNumber, CancellationToken cancellationToken)
public async Task<IEnumerable<IProject>> GetConversionProjectsByProjectIds(IEnumerable<int> ids, CancellationToken cancellationToken)
{
var projectIds = ids.ToList();

return await dbSet.Where(x => projectIds.Contains(x.Id)).ToListAsync(cancellationToken).ConfigureAwait(false);
}

public async Task<IEnumerable<IProject>> GetConversionProjectsForNewGroup(string trustReferenceNumber, CancellationToken cancellationToken)
{
var projects = await this.dbSet.Where(x => x.Details.TrustReferenceNumber == trustReferenceNumber &&
var projects = await dbSet.Where(x => x.Details.TrustReferenceNumber == trustReferenceNumber &&
x.Details.ProjectStatus == "Converter Pre-AO (C)" && x.ProjectGroupId == null).ToListAsync(cancellationToken);

return projects;
}

public async Task<IEnumerable<IProject>> GetConversionProjectsByIds(IEnumerable<int> urns, CancellationToken cancellationToken)
// Project Groups


public async Task<IEnumerable<IProject>> GetConversionProjectsByProjectGroupIdAsync(int? projectGroupId, CancellationToken cancellationToken)
{
var projects = await this.dbSet.Where(x => urns.Contains(x.Id)).ToListAsync(cancellationToken);
var projects = await dbSet.Where(x => x.ProjectGroupId == projectGroupId).ToListAsync(cancellationToken);

return projects;
}

public async Task<IEnumerable<IProject>> GetProjectsByProjectGroupIdsAsync(IEnumerable<int> projectGroupIds, CancellationToken cancellationToken)
{
return await dbSet
.Where(p => projectGroupIds.Contains(p.ProjectGroupId.GetValueOrDefault()))
.ToListAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public void Insert(TEntity obj)
dbSet.Add(obj);
}

public Task<IEnumerable<TEntity>> GetAll()
public async Task<IEnumerable<TEntity>> GetAll()
{
throw new NotImplementedException();
return await dbSet.ToListAsync().ConfigureAwait(false);
}

public async Task<TEntity> GetById(int id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dfe.Academies.Academisation.Domain.ProjectGroupsAggregate;
using Dfe.Academies.Academisation.Domain.SeedWork;
using Dfe.Academies.Academisation.IDomain.FormAMatProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectGroupAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -28,39 +29,35 @@ private IQueryable<ProjectGroup> DefaultIncludes()
public async Task<ProjectGroup?> GetByReferenceNumberAsync(string referenceNumber, CancellationToken cancellationToken)
=> await DefaultIncludes().SingleOrDefaultAsync(x => x.ReferenceNumber == referenceNumber, cancellationToken);

public async Task<(IEnumerable<IProjectGroup>, int totalcount)> SearchProjectGroups(int page, int count, string? referenceNumber, IEnumerable<string?>? trustReferences, CancellationToken cancellationToken)
public async Task<IEnumerable<IProjectGroup>> SearchProjectGroups(string searchTerm, CancellationToken cancellationToken)
{
IQueryable<ProjectGroup> queryable = DefaultIncludes();
queryable = FilterByReferenceNumber(referenceNumber, queryable);
queryable = FilterByTrust(trustReferences, queryable);
queryable = FilterBySearchTerm(searchTerm, queryable);

var totalProjectGroups = queryable.Count();
var projects = await queryable
.OrderByDescending(acp => acp.CreatedOn)
.Skip((page - 1) * count)
.Take(count).ToListAsync(cancellationToken);
.ToListAsync(cancellationToken);

return (projects, totalProjectGroups);
return projects;
}

private static IQueryable<ProjectGroup> FilterByReferenceNumber(string? referenceNumber, IQueryable<ProjectGroup> queryable)
private static IQueryable<ProjectGroup> FilterBySearchTerm(string searchTerm, IQueryable<ProjectGroup> queryable)
{
if (!referenceNumber.IsNullOrEmpty())
if (!searchTerm.IsNullOrEmpty())
{
queryable = queryable.Where(p => p.ReferenceNumber == referenceNumber);
searchTerm = searchTerm.ToLower();
queryable = queryable.Where(p => (p.ReferenceNumber != null && p.ReferenceNumber.ToLower().Contains(searchTerm)) ||
p.TrustReference.ToLower().Contains(searchTerm) ||
p.TrustUkprn.ToLower().Contains(searchTerm) ||
p.TrustName.ToLower().Contains(searchTerm));
}

return queryable;
}

private IQueryable<ProjectGroup> FilterByTrust(IEnumerable<string> trustReferences, IQueryable<ProjectGroup> queryable)
public async Task<IEnumerable<IProjectGroup>> GetByIds(IEnumerable<int?> projectGroupIds, CancellationToken cancellationToken)
{
if (trustReferences.IsNullOrEmpty())
{
queryable = queryable.Where(p => trustReferences.Contains(p.TrustReference));
}

return queryable;
return await this.dbSet.Where(x => projectGroupIds.Contains(x.Id)).Cast<IProjectGroup>().ToListAsync(cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public void Create_JoinAMatApplicationType___ReturnsCreateSuccessResult()
() => Assert.Equal(ToYesNoString(school.Details.LandAndBuildings!.PartOfPfiScheme), project.Details.PartOfPfiScheme),
() => Assert.Equal("Yes", project.Details.FinancialDeficit),
() => Assert.Equal(school.Details.SchoolConversionReasonsForJoining, project.Details.RationaleForTrust),
() => Assert.Equal(school.Details.CurrentFinancialYear.FinancialYearEndDate, project.Details.EndOfCurrentFinancialYear),
() => Assert.Equal(school.Details.NextFinancialYear.FinancialYearEndDate, project.Details.EndOfNextFinancialYear),
() => Assert.Equal(school.Details.CurrentFinancialYear.Revenue * -1.0M, project.Details.RevenueCarryForwardAtEndMarchCurrentYear),
() => Assert.Equal(school.Details.NextFinancialYear.Revenue, project.Details.ProjectedRevenueBalanceAtEndMarchNextYear),
() => Assert.Equal(school.Details.CurrentFinancialYear.CapitalCarryForward * -1.0M, project.Details.CapitalCarryForwardAtEndMarchCurrentYear),
() => Assert.Equal(school.Details.NextFinancialYear.CapitalCarryForward, project.Details.CapitalCarryForwardAtEndMarchNextYear),
() => Assert.Equal(school.Details.CurrentFinancialYear!.FinancialYearEndDate, project.Details.EndOfCurrentFinancialYear),
() => Assert.Equal(school.Details.NextFinancialYear!.FinancialYearEndDate, project.Details.EndOfNextFinancialYear),
() => Assert.Equal(school.Details.CurrentFinancialYear!.Revenue * -1.0M, project.Details.RevenueCarryForwardAtEndMarchCurrentYear),
() => Assert.Equal(school.Details.NextFinancialYear!.Revenue, project.Details.ProjectedRevenueBalanceAtEndMarchNextYear),
() => Assert.Equal(school.Details.CurrentFinancialYear!.CapitalCarryForward * -1.0M, project.Details.CapitalCarryForwardAtEndMarchCurrentYear),
() => Assert.Equal(school.Details.NextFinancialYear!.CapitalCarryForward, project.Details.CapitalCarryForwardAtEndMarchNextYear),
() => Assert.Equal(school.Details.ProjectedPupilNumbersYear1, project.Details.YearOneProjectedPupilNumbers),
() => Assert.Equal(school.Details.ProjectedPupilNumbersYear2, project.Details.YearTwoProjectedPupilNumbers),
() => Assert.Equal(school.Details.ProjectedPupilNumbersYear3, project.Details.YearThreeProjectedPupilNumbers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void SetExternalApplicationForm_StateUnderTest_ExpectedBehavior()
// Arrange
var project = this.CreateProject();
bool ExternalApplicationFormSaved = false;
string ExternalApplicationFormUrl = null;
var ExternalApplicationFormUrl = _fixture.Create<string>();

// Act
project.SetExternalApplicationForm(
Expand Down
Loading

0 comments on commit 1a6c908

Please sign in to comment.