Skip to content

Commit

Permalink
Merge pull request #935 from DFE-Digital/feature/v4-endpoints
Browse files Browse the repository at this point in the history
Now using V4 endpoints
  • Loading branch information
dneed-nimble authored Nov 14, 2023
2 parents a33517d + 9417458 commit e14406d
Show file tree
Hide file tree
Showing 45 changed files with 229 additions and 286 deletions.
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 @@ public static Application.Application MapToApplication(AcademisationApplication
{
// 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 @@ public static void PopulateDeclaration(ApplyingSchool academiesApplicationSchool
School academisationApplicationSchool)
{
academiesApplicationSchool.DeclarationBodyAgree = academisationApplicationSchool.DeclarationBodyAgree;

}

public static void PopulateConsultation(ApplyingSchool academiesApplicationSchool,
Expand Down Expand Up @@ -92,7 +92,7 @@ public static void PopulateLandAndBuildings(ApplyingSchool academiesApplicationS
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 @@ -225,31 +225,31 @@ public static void PopulateFurtherInformation(ApplyingSchool academiesApplicatio
// 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 @@ public static void PopulateFurtherInformation(ApplyingSchool academiesApplicatio
_ => 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 @@ -355,8 +355,8 @@ public static Application.Application PopulateOverview(AcademisationApplication
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; }
}

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,23 +25,23 @@ public EstablishmentService(IDfeHttpClientFactory httpClientFactory,
_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);

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

0 comments on commit e14406d

Please sign in to comment.