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

Now using V4 endpoints #935

Merged
merged 8 commits into from
Nov 14, 2023
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 @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoFixture.AutoMoq" Version="4.17.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.17.0" />
<PackageReference Include="Dfe.Academies.Contracts" Version="1.0.4" />
<PackageReference Include="FluentAssertions" Version="6.9.0" />
<PackageReference Include="MELT" Version="0.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task Should_search_by_urn(

// Assert
httpService.Verify(m => m.Get<IEnumerable<EstablishmentSearchResponse>>(
It.IsAny<HttpClient>(), $"establishments?urn={urn}"), Times.Once);
It.IsAny<HttpClient>(), $"/v4/establishments?urn={urn}"), Times.Once);
}

[Theory]
Expand All @@ -78,7 +78,7 @@ public async Task Should_search_by_name(

// Assert
httpService.Verify(m => m.Get<IEnumerable<EstablishmentSearchResponse>>(
It.IsAny<HttpClient>(), $"establishments?name={name}"), Times.Once);
It.IsAny<HttpClient>(), $"/v4/establishments?name={name}"), Times.Once);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task Should_get_school_performance_by_urn(AcademyConversionProject
establishmentMockData.MisEstablishment.InspectionEndDate = "15/01/2020";
establishmentMockData.MisEstablishment.DateOfLatestSection8Inspection = "15/01/2020";
_mockHandler
.Expect($"/establishment/urn/{project.Urn}")
.Expect($"/v4/establishment/urn/{project.Urn}")
.Respond("application/json", JsonConvert.SerializeObject(establishmentMockData));

SchoolPerformance schoolPerformance = await _schoolPerformanceService.GetSchoolPerformanceByUrn(project.Urn.ToString());
Expand All @@ -67,7 +67,7 @@ public async Task Should_get_school_performance_by_urn(AcademyConversionProject
public async Task Should_log_warning_when_school_performance_not_found(AcademyConversionProject project)
{
_mockHandler
.Expect($"/establishment/urn/{project.Urn}")
.Expect($"/v4/establishment/urn/{project.Urn}")
.Respond(HttpStatusCode.NotFound);

await _schoolPerformanceService.GetSchoolPerformanceByUrn(project.Urn.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class TrustsRespositoryTests
[AutoMoqData]
public async Task SearchTrusts_ReturnsTrusts(
[Frozen] Mock<IHttpClientService> httpService,
TrustSummaryResponse expectedResponse,
TrustDtoResponse expectedResponse,
MockHttpMessageHandler mockHandler,
string name)
{
// Arrange
TrustsRepository sut = new(new DfeHttpClientFactory(new MockHttpClientFactory(mockHandler), new CorrelationContext()), httpService.Object);
httpService.Setup(m => m.Get<TrustSummaryResponse>(It.IsAny<HttpClient>(), It.IsAny<string>()))
.ReturnsAsync(new ApiResponse<TrustSummaryResponse>(HttpStatusCode.OK, expectedResponse));
httpService.Setup(m => m.Get<TrustDtoResponse>(It.IsAny<HttpClient>(), It.IsAny<string>()))
.ReturnsAsync(new ApiResponse<TrustDtoResponse>(HttpStatusCode.OK, expectedResponse));

// Act
TrustSummaryResponse results = await sut.SearchTrusts(name);
TrustDtoResponse results = await sut.SearchTrusts(name);

// Assert
Assert.Equivalent(expectedResponse, results);
Expand All @@ -41,14 +41,14 @@ public async Task SearchTrusts_ReturnsTrusts(
[AutoMoqData]
public async Task Should_throw_exception(
[Frozen] Mock<IHttpClientService> httpService,
TrustSummaryResponse expectedResponse,
TrustDtoResponse expectedResponse,
MockHttpMessageHandler mockHandler,
string name)
{
// Arrange
TrustsRepository sut = new(new DfeHttpClientFactory(new MockHttpClientFactory(mockHandler), new CorrelationContext()), httpService.Object);
httpService.Setup(m => m.Get<TrustSummaryResponse>(It.IsAny<HttpClient>(), It.IsAny<string>()))
.ReturnsAsync(new ApiResponse<TrustSummaryResponse>(HttpStatusCode.InternalServerError, expectedResponse));
httpService.Setup(m => m.Get<TrustDtoResponse>(It.IsAny<HttpClient>(), It.IsAny<string>()))
.ReturnsAsync(new ApiResponse<TrustDtoResponse>(HttpStatusCode.InternalServerError, expectedResponse));

// Act
ApiResponseException ex = await Assert.ThrowsAsync<ApiResponseException>(() => sut.SearchTrusts(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Dfe.Academies.Contracts" Version="1.0.4" />
<PackageReference Include="Dfe.Academisation.CorrelationIdMiddleware" Version="2.0.2" />
<PackageReference Include="Dfe.Academisation.ExtensionMethods" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
// Following the fields used by the front end
Application.Application academiesApplication = PopulateOverview(academisationApplication, out School academisationApplicationSchool, out ApplyingSchool academiesApplicationSchool, schoolName);
if(academiesApplication.ApplicationType.Equals(GlobalStrings.FormAMat)) PopulateFormAMatTrustInformation(academiesApplication, academisationApplication);
if (academiesApplication.ApplicationType.Equals(GlobalStrings.FormAMat)) PopulateFormAMatTrustInformation(academiesApplication, academisationApplication);
PopulateSchoolDetails(academiesApplicationSchool, academisationApplicationSchool);
PopulateFurtherInformation(academiesApplicationSchool, academisationApplicationSchool);
PopulateSchoolFinances(academiesApplicationSchool, academisationApplicationSchool);
Expand Down Expand Up @@ -63,7 +63,7 @@
School academisationApplicationSchool)
{
academiesApplicationSchool.DeclarationBodyAgree = academisationApplicationSchool.DeclarationBodyAgree;

}

public static void PopulateConsultation(ApplyingSchool academiesApplicationSchool,
Expand Down Expand Up @@ -92,7 +92,7 @@
academisationApplicationSchool.LandAndBuildings.FacilitiesSharedExplained;
academiesApplicationSchool.SchoolBuildLandGrants = academisationApplicationSchool.LandAndBuildings.Grants;
academiesApplicationSchool.SchoolBuildLandGrantsExplained =
academisationApplicationSchool.LandAndBuildings.GrantsAwardingBodies;
academisationApplicationSchool.LandAndBuildings.GrantsAwardingBodies;
academiesApplicationSchool.SchoolBuildLandPFIScheme =
academisationApplicationSchool.LandAndBuildings.PartOfPfiScheme;
academiesApplicationSchool.SchoolBuildLandPFISchemeType =
Expand Down Expand Up @@ -130,7 +130,7 @@
public static void PopulateSchoolLeases(ApplyingSchool academiesApplicationSchool,
School academisationApplicationSchool)
{
if (academisationApplicationSchool.Leases.IsNullOrEmpty() is false)

Check warning on line 133 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/AcademisationApplication/AcademisationApplication.cs

View workflow job for this annotation

GitHub Actions / build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
foreach (Lease lease in academisationApplicationSchool.Leases)
{
Expand All @@ -152,7 +152,7 @@
public static void PopulateSchoolLoans(ApplyingSchool academiesApplicationSchool,
School academisationApplicationSchool)
{
if (academisationApplicationSchool.Loans.IsNullOrEmpty() is false)

Check warning on line 155 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/AcademisationApplication/AcademisationApplication.cs

View workflow job for this annotation

GitHub Actions / build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
foreach (Loan loan in academisationApplicationSchool.Loans)
{
Expand Down Expand Up @@ -225,31 +225,31 @@
// Further Information
academiesApplicationSchool.SchoolAdSchoolContributionToTrust =
academisationApplicationSchool
.TrustBenefitDetails;
academiesApplicationSchool.SchoolAdInspectedButReportNotPublished = !academisationApplicationSchool.OfstedInspectionDetails.IsNullOrEmpty();
.TrustBenefitDetails;
academiesApplicationSchool.SchoolAdInspectedButReportNotPublished = !academisationApplicationSchool.OfstedInspectionDetails.IsNullOrEmpty();
academiesApplicationSchool.SchoolAdInspectedButReportNotPublishedExplain =
academisationApplicationSchool.OfstedInspectionDetails;
academiesApplicationSchool.SchoolOngoingSafeguardingInvestigations =
academisationApplicationSchool.Safeguarding;
academisationApplicationSchool.Safeguarding;
// Questions regarding the below are outstanding
// academiesApplicationSchool.SchoolOngoingSafeguardingDetails = academisationApplicationSchool.SafeguardingDetails;

Check warning on line 235 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/AcademisationApplication/AcademisationApplication.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
academiesApplicationSchool.SchoolPartOfLaReorganizationPlan =
!academisationApplicationSchool.LocalAuthorityReorganisationDetails
.IsNullOrEmpty();
.IsNullOrEmpty();
academiesApplicationSchool.SchoolLaReorganizationDetails =
academisationApplicationSchool.LocalAuthorityReorganisationDetails;
academiesApplicationSchool.SchoolPartOfLaClosurePlan =
!academisationApplicationSchool.LocalAuthorityClosurePlanDetails.IsNullOrEmpty();
academiesApplicationSchool.SchoolLaClosurePlanDetails =
academisationApplicationSchool
.LocalAuthorityClosurePlanDetails;
.LocalAuthorityClosurePlanDetails;
academiesApplicationSchool.SchoolFaithSchool =
!academisationApplicationSchool.DioceseName
.IsNullOrEmpty();
.IsNullOrEmpty();
academiesApplicationSchool.SchoolFaithSchoolDioceseName = academisationApplicationSchool.DioceseName;
academiesApplicationSchool.SchoolIsPartOfFederation = academisationApplicationSchool.PartOfFederation;
academiesApplicationSchool.SchoolIsSupportedByFoundation =
!academisationApplicationSchool.FoundationTrustOrBodyName.IsNullOrEmpty();
!academisationApplicationSchool.FoundationTrustOrBodyName.IsNullOrEmpty();
academiesApplicationSchool.SchoolSupportedFoundationBodyName =
academisationApplicationSchool.FoundationTrustOrBodyName;
if (academisationApplicationSchool.ExemptionEndDate is not null)
Expand All @@ -268,9 +268,9 @@
_ => string.Empty
};
academiesApplicationSchool.SchoolAdditionalInformationAdded =
!academisationApplicationSchool.FurtherInformation.IsNullOrEmpty();
!academisationApplicationSchool.FurtherInformation.IsNullOrEmpty();
academiesApplicationSchool.SchoolAdditionalInformation =
academisationApplicationSchool.FurtherInformation;
academisationApplicationSchool.FurtherInformation;
}

public static void PopulateSchoolDetails(ApplyingSchool academiesApplicationSchool,
Expand Down Expand Up @@ -318,7 +318,7 @@
academisationApplication!.Contributors ??= new List<Contributor>();
// Filter the schools by name if schoolName is not null, otherwise use the first school
academisationApplicationSchool = schoolName != null
? academisationApplication.Schools.FirstOrDefault(s => s.SchoolName == schoolName)

Check warning on line 321 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/AcademisationApplication/AcademisationApplication.cs

View workflow job for this annotation

GitHub Actions / build

"Find" method should be used instead of the "FirstOrDefault" extension method. (https://rules.sonarsource.com/csharp/RSPEC-6602)
: academisationApplication.Schools.FirstOrDefault();

academiesApplication.ApplyingSchools = new List<ApplyingSchool> { new() };
Expand All @@ -336,7 +336,7 @@
academiesApplication.ApplicationId =
academisationApplication.ApplicationReference;
Contributor academisationContributors = academisationApplication.Contributors.FirstOrDefault();
if (academisationContributors?.FirstName.IsNullOrEmpty() is false && academisationContributors.LastName.IsNullOrEmpty() is false)

Check warning on line 339 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/AcademisationApplication/AcademisationApplication.cs

View workflow job for this annotation

GitHub Actions / build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
academiesApplication.ApplicationLeadAuthorName =
academisationApplication.Contributors.FirstOrDefault()!.FirstName + " " + academisationApplication.Contributors.FirstOrDefault()!.LastName;
Expand All @@ -355,8 +355,8 @@
academiesApplication.ChangesToLaGovernanceExplained =
academisationApplication.JoinTrustDetails.ChangesToLaGovernanceExplained;
}


return academiesApplication;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Dfe.PrepareConversions.Data.Models.Establishment;

/// <remarks>
/// Copy of TramsDataApi.ResponseModels.EstablishmentResponse with most properties omitted
/// Copy of TramsDataApi.ResponseModels.EstablishmentDto with most properties omitted
/// </remarks>
public class EstablishmentResponse
{
Expand All @@ -10,23 +10,23 @@ public class EstablishmentResponse
public string LocalAuthorityCode { get; set; }
public string LocalAuthorityName { get; set; }
public string EstablishmentNumber { get; set; }
public string EstablishmentName { get; set; }
public NameAndCodeResponse EstablishmentType { get; set; }
public NameAndCodeResponse PhaseOfEducation { get; set; }
public NameAndCodeResponse ReligiousCharacter { get; set; }
public string Name { get; set; }
public NameAndCodeDto EstablishmentType { get; set; }
public NameAndCodeDto PhaseOfEducation { get; set; }
public NameAndCodeDto ReligiousCharacter { get; set; }
public string OfstedRating { get; set; }
public string OfstedLastInspection { get; set; }
public string StatutoryLowAge { get; set; }
public string StatutoryHighAge { get; set; }
public NameAndCodeResponse Diocese { get; set; }
public NameAndCodeDto Diocese { get; set; }
public string SchoolCapacity { get; set; }
public CensusResponse Census { get; set; }
public NameAndCodeResponse ParliamentaryConstituency { get; set; }
public NameAndCodeDto ParliamentaryConstituency { get; set; }
public MisEstablishmentResponse MISEstablishment { get; set; }
public AddressResponse Address { get; set; }
public ViewAcademyConversion ViewAcademyConversion { get; set; }
public string OpenDate { get; set; }

public Region Gor { get; set; }

public class Region
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Dfe.PrepareConversions.Data.Models.Establishment;

public class NameAndCodeResponse
public class NameAndCodeDto
{
public string Name { get; set; }
public string Code { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
using System.Collections.Generic;

namespace Dfe.PrepareConversions.Data.Models.Trust;

public class TrustDetailResponse
{
public List<TrustDetail> Data { get; set; }
}
namespace Dfe.PrepareConversions.Data.Models.Trust;

public class TrustDetail
{
public GiasData GiasData { get; set; }
}

public class GiasData
{
public string GroupId { get; set; }
public string GroupName { get; set; }
public string ReferenceNumber { get; set; }
public string Name { get; set; }
public string GroupType { get; set; }
public int CompaniesHouseNumber { get; set; }
public string CompaniesHouseNumber { get; set; }
public string Ukprn { get; set; }
}

dneed-nimble marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
using System.Collections.Generic;
using Dfe.Academies.Contracts.V4.Trusts;
using System.Collections.Generic;

namespace Dfe.PrepareConversions.Data.Models.Trust;

public class TrustSummaryResponse
public class TrustDtoResponse
{
public List<TrustSummary> Data { get; set; }
}

public class TrustSummary
{
public string Ukprn { get; set; }
public string GroupName { get; set; }
public string CompaniesHouseNumber { get; set; }
public string TrustType { get; set; }
public TrustAddress TrustAddress { get; set; }
public List<EstablishmentDetail> Establishments { get; set; }
}

public class TrustAddress
{
public string Street { get; set; }
public string Locality { get; set; }
public string AdditionalLine { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string Postcode { get; set; }
}

public class EstablishmentDetail
{
public string Urn { get; set; }
public string Name { get; set; }
public string Ukprn { get; set; }
}
public List<TrustDto> Data { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using EstablishmentDto = Dfe.Academies.Contracts.V4.Establishments.EstablishmentDto;

namespace Dfe.PrepareConversions.Data.Services;

Expand All @@ -24,27 +25,27 @@
_httpClientService = httpClientService;
}

public async Task<EstablishmentResponse> GetEstablishmentByUrn(string urn)
public async Task<EstablishmentDto> GetEstablishmentByUrn(string urn)
{
HttpResponseMessage response = await _httpClient.GetAsync($"/establishment/urn/{urn}");
HttpResponseMessage response = await _httpClient.GetAsync($"/v4/establishment/urn/{urn}");
if (!response.IsSuccessStatusCode)
{
_logger.LogWarning("Unable to get establishment data for establishment with URN: {urn}", urn);
return new EstablishmentResponse();
return new EstablishmentDto();
}

return await response.Content.ReadFromJsonAsync<EstablishmentResponse>();
return await response.Content.ReadFromJsonAsync<EstablishmentDto>();
}

public async Task<IEnumerable<EstablishmentSearchResponse>> SearchEstablishments(string searchQuery)
{
string path = int.TryParse(searchQuery, out int urn)
? $"establishments?urn={urn}"
: $"establishments?name={searchQuery}";
? $"/v4/establishments?urn={urn}"
: $"/v4/establishments?name={searchQuery}";

ApiResponse<IEnumerable<EstablishmentSearchResponse>> result = await _httpClientService.Get<IEnumerable<EstablishmentSearchResponse>>(_httpClient, path);

if (result.Success is false) throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}");

Check warning on line 48 in Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/EstablishmentService.cs

View workflow job for this annotation

GitHub Actions / build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)

return result.Body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Dfe.PrepareConversions.Data.Services;

public interface IGetEstablishment
{
Task<EstablishmentResponse> GetEstablishmentByUrn(string urn);
Task<Academies.Contracts.V4.Establishments.EstablishmentDto> GetEstablishmentByUrn(string urn);
Task<IEnumerable<EstablishmentSearchResponse>> SearchEstablishments(string searchQuery);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Dfe.PrepareConversions.Data.Models.Trust;
using Dfe.Academies.Contracts.V4.Trusts;
using Dfe.PrepareConversions.Data.Models.Trust;
using System.Threading.Tasks;

namespace Dfe.PrepareConversions.Data.Services.Interfaces;

public interface ITrustsRepository
{
Task<TrustSummaryResponse> SearchTrusts(string searchQuery);
Task<TrustDtoResponse> SearchTrusts(string searchQuery);

Task<TrustDetail> GetTrustByUkprn(string ukprn);
Task<TrustDto> GetTrustByUkprn(string ukprn);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Dfe.PrepareConversions.Data.Models;
using Dfe.PrepareConversions.Data.Models.Establishment;
using Dfe.Academies.Contracts.V4.Establishments;
using Dfe.PrepareConversions.Data.Models;
using System;
using System.Threading.Tasks;

Expand All @@ -16,7 +16,7 @@ public SchoolOverviewService(IGetEstablishment getEstablishment)

public async Task<SchoolOverview> GetSchoolOverviewByUrn(string urn)
{
EstablishmentResponse establishment = await _getEstablishment.GetEstablishmentByUrn(urn);
EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn);
SchoolOverview schoolOverview = new()
{
SchoolPostcode = establishment.Address?.Postcode,
Expand All @@ -34,7 +34,7 @@ public async Task<SchoolOverview> GetSchoolOverviewByUrn(string urn)
return schoolOverview;
}

private static string IsPartOfADiocesanTrust(NameAndCodeResponse nameAndCode)
private static string IsPartOfADiocesanTrust(NameAndCodeDto nameAndCode)
{
if (nameAndCode == null)
{
Expand Down
Loading
Loading