Skip to content

Commit

Permalink
remove NoResults status code
Browse files Browse the repository at this point in the history
  • Loading branch information
CathLass committed Aug 7, 2024
1 parent dd41b7d commit 9ba669e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ public sealed class SearchByKeywordResponse
/// <summary>
/// The readonly collection of T:Dfe.Data.SearchPrototype.Search.Establishment search results.
/// </summary>
public IReadOnlyCollection<Establishment>? EstablishmentResults { get;}
public IReadOnlyCollection<Establishment> EstablishmentResults { get;}
public SearchResponseStatus Status { get; set; }

/// <summary>
/// Default constructor
/// </summary>
public SearchByKeywordResponse()
{
EstablishmentResults = new List<Establishment>();
}

/// <summary>
/// The following argument is passed via the constructor and is not changeable
/// once an instance is created, this ensures we preserve immutability.
/// </summary>
/// <param name="establishments">
/// The readonly collection of T:Dfe.Data.SearchPrototype.Search.Establishment search results.
/// </param>
public SearchByKeywordResponse(IReadOnlyCollection<Establishment>? establishments)
public SearchByKeywordResponse(IReadOnlyCollection<Establishment> establishments)
{
EstablishmentResults = establishments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ public async Task<SearchByKeywordResponse> 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)

Check warning on line 65 in Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 65 in Dfe.Data.SearchPrototype/SearchForEstablishments/SearchByKeywordUseCase.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public enum SearchResponseStatus
{
Success,
NoResults,
InvalidRequest,
SearchServiceError,
DataFormatError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void MapFrom_ValidInput_ReturnsCorrectResponse()
}

[Fact]
public void MapFrom_NullInput_ThrowsException()
public void MapFrom_NullInput_ReturnsErrorResponse()
{
// arrange.
IMapper<EstablishmentResults, SearchByKeywordResponse> mapper = new ResultsToResponseMapper();
Expand All @@ -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);
}
}

0 comments on commit 9ba669e

Please sign in to comment.