From 9ba669e2f9dc50b696870f1e598dc703641728cb Mon Sep 17 00:00:00 2001 From: CLAWLOR Date: Wed, 7 Aug 2024 14:31:06 +0100 Subject: [PATCH] remove NoResults status code --- .../ResultsToResponseMapper.cs | 7 ++----- .../SearchByKeywordResponse.cs | 12 ++++++++++-- .../SearchByKeywordUseCase.cs | 5 ++--- .../SearchForEstablishments/SearchResponseStatus.cs | 1 - .../ResultsToResponseMapperTests.cs | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/ResultsToResponseMapper.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/ResultsToResponseMapper.cs index a981a29..1a4a61d 100644 --- a/Dfe.Data.SearchPrototype/SearchForEstablishments/ResultsToResponseMapper.cs +++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/ResultsToResponseMapper.cs @@ -24,11 +24,8 @@ public SearchByKeywordResponse MapFrom(EstablishmentResults input) { if(input == null) { - return new(null) { Status = SearchResponseStatus.NoResults }; + return new() { Status = SearchResponseStatus.SearchServiceError }; } - return new(input.Establishments) - { - Status = SearchResponseStatus.Success - }; + else return new(input.Establishments) { Status = SearchResponseStatus.Success }; } } diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordResponse.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordResponse.cs index 23e0672..369f384 100644 --- a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordResponse.cs +++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordResponse.cs @@ -12,9 +12,17 @@ public sealed class SearchByKeywordResponse /// /// The readonly collection of T:Dfe.Data.SearchPrototype.Search.Establishment search results. /// - public IReadOnlyCollection? EstablishmentResults { get;} + public IReadOnlyCollection EstablishmentResults { get;} public SearchResponseStatus Status { get; set; } + /// + /// Default constructor + /// + public SearchByKeywordResponse() + { + EstablishmentResults = new List(); + } + /// /// The following argument is passed via the constructor and is not changeable /// once an instance is created, this ensures we preserve immutability. @@ -22,7 +30,7 @@ public sealed class SearchByKeywordResponse /// /// The readonly collection of T:Dfe.Data.SearchPrototype.Search.Establishment search results. /// - public SearchByKeywordResponse(IReadOnlyCollection? establishments) + public SearchByKeywordResponse(IReadOnlyCollection establishments) { EstablishmentResults = establishments; } diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs index 308ee54..9aac8be 100644 --- a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs +++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs @@ -54,14 +54,13 @@ public async Task HandleRequest(SearchByKeywordRequest Status = SearchResponseStatus.InvalidRequest }; }; - //ArgumentNullException.ThrowIfNull(request, nameof(SearchByKeywordRequest)); - //ArgumentNullException.ThrowIfNull(request.Context, nameof(SearchContext)); + try { EstablishmentResults establishmentResults = await _searchServiceAdapter.SearchAsync(request.Context); return _resultsToResponseMapper.MapFrom(establishmentResults); } - catch (Exception ex) + catch (Exception) // something catastrophic went wrong in the infrastructure { return new SearchByKeywordResponse(null) { diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchResponseStatus.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchResponseStatus.cs index 43cfa3e..85be510 100644 --- a/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchResponseStatus.cs +++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/SearchResponseStatus.cs @@ -3,7 +3,6 @@ public enum SearchResponseStatus { Success, - NoResults, InvalidRequest, SearchServiceError, DataFormatError diff --git a/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ResultsToResponseMapperTests.cs b/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ResultsToResponseMapperTests.cs index 926ff4c..efbe368 100644 --- a/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ResultsToResponseMapperTests.cs +++ b/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ResultsToResponseMapperTests.cs @@ -28,7 +28,7 @@ public void MapFrom_ValidInput_ReturnsCorrectResponse() } [Fact] - public void MapFrom_NullInput_ThrowsException() + public void MapFrom_NullInput_ReturnsErrorResponse() { // arrange. IMapper mapper = new ResultsToResponseMapper(); @@ -37,6 +37,6 @@ public void MapFrom_NullInput_ThrowsException() SearchByKeywordResponse response = mapper.MapFrom(null!); // assert - response.Status.Should().Be(SearchResponseStatus.NoResults); + response.Status.Should().Be(SearchResponseStatus.SearchServiceError); } }