-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #443 from DFE-Digital/feature/attendance-data
Feature/attendance data
- Loading branch information
Showing
18 changed files
with
283 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Dfe.Academies.Academisation.Data; | ||
using Dfe.Academies.Domain.EducationalPerformance; | ||
using Dfe.Academies.Domain.Establishment; | ||
using Dfe.Academies.Domain.Trust; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dfe.Academies.Infrastructure | ||
{ | ||
public class EdperfContext : DbContext | ||
{ | ||
const string DEFAULT_SCHEMA = "edperf"; | ||
|
||
public EdperfContext() | ||
{ | ||
|
||
} | ||
|
||
public EdperfContext(DbContextOptions<EdperfContext> options) : base(options) | ||
{ | ||
|
||
} | ||
|
||
public DbSet<SchoolAbsence> SchoolAbsences { get; set; } = null!; | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<SchoolAbsence>(ConfigureSchoolAbsence); | ||
|
||
|
||
base.OnModelCreating(modelBuilder); | ||
} | ||
|
||
private void ConfigureSchoolAbsence(EntityTypeBuilder<SchoolAbsence> schoolAbsenceConfiguration) | ||
{ | ||
schoolAbsenceConfiguration.ToTable("download_PUPILABSENCE_england_ALL", DEFAULT_SCHEMA); | ||
schoolAbsenceConfiguration.HasKey(e => new { e.DownloadYear, e.URN, e.LA, e.ESTAB }); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Dfe.Academies.Api.Infrastructure/Repositories/EducationalPerformanceRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Dfe.Academies.Domain.EducationalPerformance; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Dfe.Academies.Infrastructure.Repositories | ||
{ | ||
public class EducationalPerformanceRepository : IEducationalPerformanceRepository | ||
{ | ||
private EdperfContext _context; | ||
|
||
public EducationalPerformanceRepository(EdperfContext context) | ||
{ | ||
_context = context; | ||
} | ||
public async Task<List<SchoolAbsence>> GetSchoolAbsencesByURN(string urn, CancellationToken cancellationToken) | ||
{ | ||
var queryResult = await _context.SchoolAbsences.AsNoTracking().Where(r => r.URN == urn).ToListAsync(cancellationToken); | ||
|
||
if (queryResult == null) | ||
{ | ||
return new (); | ||
} | ||
|
||
return queryResult; | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...es.Application.Tests/Queries/EducationalPerformance/EducationalPerformanceQueriesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using AutoFixture; | ||
using Dfe.Academies.Application.EducationalPerformance; | ||
using Dfe.Academies.Contracts.V1.EducationalPerformance; | ||
using Dfe.Academies.Domain.EducationalPerformance; | ||
using FluentAssertions; | ||
using Moq; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Dfe.Academies.Application.Tests.Queries.EducationalPerformance | ||
{ | ||
public class EducationalPerformanceQueriesTests | ||
{ | ||
private Fixture _fixture = new Fixture(); | ||
|
||
private MockRepository mockRepository; | ||
|
||
private Mock<IEducationalPerformanceRepository> mockEducationalPerformanceRepository; | ||
|
||
public EducationalPerformanceQueriesTests() | ||
{ | ||
mockRepository = new MockRepository(MockBehavior.Strict); | ||
|
||
mockEducationalPerformanceRepository = mockRepository.Create<IEducationalPerformanceRepository>(); | ||
} | ||
|
||
private EducationalPerformanceQueries CreateEducationalPerformanceQueries() | ||
{ | ||
return new EducationalPerformanceQueries( | ||
mockEducationalPerformanceRepository.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAchoolAbsenceDataByUrn_WhenAbsenceDataExists_DtoListIsReturnedWithCorrectCount() | ||
{ | ||
// Arrange | ||
var urn = "100022"; | ||
var absenceData = _fixture.Create<List<SchoolAbsence>>(); | ||
mockEducationalPerformanceRepository.Setup(x => x.GetSchoolAbsencesByURN(It.Is<string>(y => y == urn), It.IsAny<CancellationToken>())).ReturnsAsync(absenceData); | ||
var educationalPerformanceQueries = CreateEducationalPerformanceQueries(); | ||
|
||
// Act | ||
var result = await educationalPerformanceQueries.GetSchoolAbsenceDataByUrn( | ||
urn, | ||
default); | ||
|
||
// Assert | ||
result.Count.Should().Be(absenceData.Count); | ||
mockRepository.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAchoolAbsenceDataByUrn_WhenAbsenceDataExists_DtoListIsReturnedAndDataIsMappedCorrectly() | ||
{ | ||
// Arrange | ||
var urn = "100022"; | ||
var absenceData = _fixture.Create<List<SchoolAbsence>>(); | ||
mockEducationalPerformanceRepository.Setup(x => x.GetSchoolAbsencesByURN(It.Is<string>(y => y == urn), It.IsAny<CancellationToken>())).ReturnsAsync(absenceData); | ||
var educationalPerformanceQueries = CreateEducationalPerformanceQueries(); | ||
|
||
// Act | ||
var result = await educationalPerformanceQueries.GetSchoolAbsenceDataByUrn( | ||
urn, | ||
default); | ||
|
||
// Assert | ||
foreach (var absence in absenceData) | ||
{ | ||
result.Should().ContainEquivalentOf(new SchoolAbsenceDataDto{ OverallAbsence = absence.PERCTOT, PersistentAbsence = absence.PPERSABS10, Year = absence.DownloadYear }); | ||
} | ||
|
||
mockRepository.VerifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Dfe.Academies.Application/EducationalPerformance/EducationalPerformanceQueries.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Dfe.Academies.Contracts.V1.EducationalPerformance; | ||
using Dfe.Academies.Domain.EducationalPerformance; | ||
|
||
namespace Dfe.Academies.Application.EducationalPerformance | ||
{ | ||
public class EducationalPerformanceQueries : IEducationalPerformanceQueries | ||
{ | ||
private readonly IEducationalPerformanceRepository _educationPerformanceRepository; | ||
|
||
public EducationalPerformanceQueries(IEducationalPerformanceRepository educationPerformanceRepository) | ||
{ | ||
this._educationPerformanceRepository = educationPerformanceRepository; | ||
} | ||
public async Task<List<SchoolAbsenceDataDto>> GetSchoolAbsenceDataByUrn(string urn, CancellationToken cancellationToken) | ||
{ | ||
var absenceData = await _educationPerformanceRepository.GetSchoolAbsencesByURN(urn, cancellationToken); | ||
|
||
if (absenceData == null) | ||
{ | ||
return new (); | ||
} | ||
|
||
return MapToSchoolAbsenceDataDto(absenceData); | ||
} | ||
|
||
private List<SchoolAbsenceDataDto> MapToSchoolAbsenceDataDto(List<SchoolAbsence> schoolAbsences) | ||
{ | ||
var schoolAbsenceDataDtos = new List<SchoolAbsenceDataDto>(); | ||
|
||
foreach (var schoolAbsence in schoolAbsences) | ||
{ | ||
schoolAbsenceDataDtos.Add(new SchoolAbsenceDataDto() | ||
{ | ||
OverallAbsence = schoolAbsence.PERCTOT, | ||
PersistentAbsence = schoolAbsence.PPERSABS10, | ||
Year = schoolAbsence.DownloadYear | ||
}); | ||
} | ||
|
||
return schoolAbsenceDataDtos; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Dfe.Academies.Application/EducationalPerformance/IEducationalPerformanceQueries.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Dfe.Academies.Contracts.V1.EducationalPerformance; | ||
|
||
namespace Dfe.Academies.Application.EducationalPerformance | ||
{ | ||
public interface IEducationalPerformanceQueries | ||
{ | ||
Task<List<SchoolAbsenceDataDto>> GetSchoolAbsenceDataByUrn(string urn, CancellationToken cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Dfe.Academies.Domain/EducationalPerformance/IEducationalPerformanceRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Dfe.Academies.Domain.Census; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dfe.Academies.Domain.EducationalPerformance | ||
{ | ||
public interface IEducationalPerformanceRepository | ||
{ | ||
public Task<List<SchoolAbsence>> GetSchoolAbsencesByURN(string urn, CancellationToken cancellationToken); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Dfe.Academies.Domain/EducationalPerformance/SchoolAbsence.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dfe.Academies.Domain.EducationalPerformance | ||
{ | ||
public class SchoolAbsence | ||
{ | ||
public string DownloadYear { get; set; } | ||
public DateTimeOffset DateAndTimeImported { get; set; } | ||
public string LA { get; set; } | ||
public string ESTAB { get; set; } | ||
public string URN { get; set; } | ||
public string PERCTOT { get; set; } | ||
public string PPERSABS10 { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.