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

Account api gsi reversal v2 #83

Merged
merged 6 commits into from
Nov 25, 2021
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 @@ -14,9 +14,9 @@ public GetPersonListRequestValidatorTests()
_sut = new HousingSearchRequestValidator();
}

private static HousingSearchRequest CreateValidRequest()
private static GetPersonListRequest CreateValidRequest()
{
return new HousingSearchRequest()
return new GetPersonListRequest()
{
SearchText = "Some search text"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public GetTenureListControllerTests()
public async Task GetTenureListShouldCallGetTenureListUseCase()
{
// given
var request = new HousingSearchRequest();
var request = new GetAssetListRequest();
var response = new GetAssetListResponse();
_mockGetAssetListUseCase.Setup(x => x.ExecuteAsync(request)).ReturnsAsync(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GetAssetListControllerTests()
public async Task GetAssetListShouldCallGetAssetListUseCase()
{
// given
var request = new HousingSearchRequest();
var request = new GetAssetListRequest();
var response = new GetAssetListResponse();
_mockGetAssetListUseCase.Setup(x => x.ExecuteAsync(request)).ReturnsAsync(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PersonListSortFactoryTests()
public void ShouldNotSortAsDefault()
{
// Arrange + Act
var result = _sut.Create<QueryablePerson>(new HousingSearchRequest());
var result = _sut.Create<QueryablePerson, GetPersonListRequest>(new GetPersonListRequest());

// Assert
result.Should().BeOfType(typeof(DefaultSort<QueryablePerson>));
Expand All @@ -29,7 +29,7 @@ public void ShouldNotSortAsDefault()
public void ShouldReturnSurnameAscWhenRequestSurnameAndAsc()
{
// Arrange + Act
var result = _sut.Create<QueryablePerson>(new HousingSearchRequest { SortBy = "surname", IsDesc = false });
var result = _sut.Create<QueryablePerson, GetPersonListRequest>(new GetPersonListRequest { SortBy = "surname", IsDesc = false });

// Assert
result.Should().BeOfType(typeof(SurnameAsc));
Expand All @@ -39,7 +39,7 @@ public void ShouldReturnSurnameAscWhenRequestSurnameAndAsc()
public void ShouldReturnSurnameDescWhenRequestSurnameAndDesc()
{
// Arrange + Act
var result = _sut.Create<QueryablePerson>(new HousingSearchRequest { SortBy = "surname", IsDesc = true });
var result = _sut.Create<QueryablePerson, GetPersonListRequest>(new GetPersonListRequest { SortBy = "surname", IsDesc = true });

// Assert
result.Should().BeOfType(typeof(SurnameDesc));
Expand Down
6 changes: 4 additions & 2 deletions HousingSearchApi.Tests/V1/Helper/SearchPhraseTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using FluentAssertions;
using Hackney.Core.ElasticSearch;
using Hackney.Shared.HousingSearch.Gateways.Models.Persons;
Expand All @@ -24,10 +25,11 @@ public SearchPhraseTests()
public void ShouldReturnNullIfRequestTypeIsUnknown(string searchText)
{
// Arrange + Act
var result = _sut.Create(new HousingSearchRequest { SearchText = searchText }, new QueryContainerDescriptor<QueryablePerson>());
QueryContainer Func() => _sut.Create<HousingSearchRequest>(new GetAccountListRequest { SearchText = searchText }, new QueryContainerDescriptor<QueryablePerson>());

// Assert
result.Should().BeNull();
Exception ex = Assert.Throws<ArgumentNullException>((Func<QueryContainer>) Func);

}
}
}
2 changes: 1 addition & 1 deletion HousingSearchApi.Tests/V1/Interfaces/SortFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SortFactoryTests()
public void GivenARequestShouldReturnDefaultSortForUnknownType()
{
// Arrange + act
var result = _sut.Create<SomeUnknownType>(new HousingSearchRequest());
var result = _sut.Create<SomeUnknownType, GetPersonListRequest>(new GetPersonListRequest());

// Assert
result.Should().BeOfType<DefaultSort<SomeUnknownType>>();
Expand Down
24 changes: 0 additions & 24 deletions HousingSearchApi/V1/Boundary/Requests/AccountSearchRequest.cs

This file was deleted.

16 changes: 0 additions & 16 deletions HousingSearchApi/V1/Boundary/Requests/GetAccountListRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@ namespace HousingSearchApi.V1.Boundary.Requests
{
public class GetAccountListRequest : HousingSearchRequest
{
HHjolany marked this conversation as resolved.
Show resolved Hide resolved
/*private const int DefaultPageSize = 12;

[FromQuery(Name = "searchText")]
public string SearchText { get; set; }

[FromQuery(Name = "pageSize")]
public int PageSize { get; set; } = DefaultPageSize;

[FromQuery(Name = "pageNumber")]
public int PageNumber { get; set; } = 1;

[FromQuery(Name = "sortBy")]
[JsonConverter(typeof(StringEnumConverter))]
public AccountSortBy SortBy { get; set; }

[FromQuery(Name = "isDesc")]
public bool IsDesc { get; set; }*/
}
}
10 changes: 10 additions & 0 deletions HousingSearchApi/V1/Boundary/Requests/GetAssetListRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc;

namespace HousingSearchApi.V1.Boundary.Requests
{
public class GetAssetListRequest : HousingSearchRequest
{
[FromQuery(Name = "assetTypes")]
public string AssetTypes { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;

namespace HousingSearchApi.V1.Boundary.Requests
{
public class GetTenureListRequest : HousingSearchRequest
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace HousingSearchApi.V1.Boundary.Requests
{
public class HousingSearchRequest
public abstract class HousingSearchRequest
{
private const int DefaultPageSize = 12;

[FromQuery(Name = "searchText")]
public string SearchText { get; set; }

[FromQuery(Name = "assetTypes")]
public string AssetTypes { get; set; }

[FromQuery(Name = "pageSize")]
public int PageSize { get; set; } = DefaultPageSize;

Expand All @@ -24,7 +21,5 @@ public class HousingSearchRequest
[FromQuery(Name = "isDesc")]
public bool IsDesc { get; set; }

[FromQuery(Name = "propertyReference")]
public string PropertyReference { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;
using Hackney.Core.Validation;

namespace HousingSearchApi.V1.Boundary.Requests.Validation
{
public class GetAccountListRequestValidator : AbstractValidator<GetAccountListRequest>
{
public GetAccountListRequestValidator()
{
RuleFor(x => x.SearchText).NotNull()
.NotEmpty()
.MinimumLength(2)
.NotXssString();
RuleFor(x => x.PageSize).GreaterThan(0);
RuleFor(x => x.SortBy).NotXssString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;
using Hackney.Core.Validation;

namespace HousingSearchApi.V1.Boundary.Requests.Validation
{
public class GetAssetListRequestValidator : AbstractValidator<GetAssetListRequest>
{
public GetAssetListRequestValidator()
{
RuleFor(x => x.SearchText).NotNull()
.NotEmpty()
.MinimumLength(2)
.NotXssString();
RuleFor(x => x.PageSize).GreaterThan(0);
RuleFor(x => x.SortBy).NotXssString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentValidation;
using Hackney.Core.Validation;

namespace HousingSearchApi.V1.Boundary.Requests.Validation
{
public class GetTenureListRequestValidator : AbstractValidator<GetTenureListRequest>
{
public GetTenureListRequestValidator()
{
RuleFor(x => x.SearchText).NotNull()
.NotEmpty()
.MinimumLength(2)
.NotXssString();
RuleFor(x => x.PageSize).GreaterThan(0);
RuleFor(x => x.SortBy).NotXssString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public GetAssetListController(IGetAssetListUseCase getAssetListUseCase)
[ProducesResponseType(typeof(APIResponse<BadRequestException>), 400)]
[HttpGet, MapToApiVersion("1")]
[LogCall(LogLevel.Information)]
public async Task<IActionResult> GetAssetList([FromQuery] HousingSearchRequest request)
public async Task<IActionResult> GetAssetList([FromQuery] GetAssetListRequest request)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public GetTenureListController(IGetTenureListUseCase getTenureListUseCase)
[ProducesResponseType(typeof(APIResponse<BadRequestException>), 400)]
[HttpGet, MapToApiVersion("1")]
[LogCall(LogLevel.Information)]
public async Task<IActionResult> GetTenureList([FromQuery] HousingSearchRequest request)
public async Task<IActionResult> GetTenureList([FromQuery] GetTenureListRequest request)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion HousingSearchApi/V1/Gateways/GetAccountGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public GetAccountGateway(ISearchGateway searchGateway, ILogger<GetAccountGateway
}

[LogCall]
public async Task<GetAccountListResponse> Search(HousingSearchRequest parameters)
public async Task<GetAccountListResponse> Search(GetAccountListRequest parameters)
{
_logger.LogInformation("Housing search api for getting account list called.");
return await _searchGateway.GetListOfAccounts(parameters).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace HousingSearchApi.V1.Gateways.Interfaces
{
public interface IGetAccountGateway
{
Task<GetAccountListResponse> Search(HousingSearchRequest parameters);
Task<GetAccountListResponse> Search(GetAccountListRequest parameters);
}
}
8 changes: 4 additions & 4 deletions HousingSearchApi/V1/Gateways/Interfaces/ISearchGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace HousingSearchApi.V1.Gateways.Interfaces
{
public interface ISearchGateway
{
Task<GetPersonListResponse> GetListOfPersons(HousingSearchRequest query);
Task<GetTenureListResponse> GetListOfTenures(HousingSearchRequest query);
Task<GetAssetListResponse> GetListOfAssets(HousingSearchRequest query);
Task<GetAccountListResponse> GetListOfAccounts(HousingSearchRequest query);
Task<GetPersonListResponse> GetListOfPersons(GetPersonListRequest query);
Task<GetTenureListResponse> GetListOfTenures(GetTenureListRequest query);
Task<GetAssetListResponse> GetListOfAssets(GetAssetListRequest query);
Task<GetAccountListResponse> GetListOfAccounts(GetAccountListRequest query);
}
}
16 changes: 8 additions & 8 deletions HousingSearchApi/V1/Gateways/SearchGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public SearchGateway(IElasticSearchWrapper elasticSearchWrapper)
}

[LogCall]
public async Task<GetPersonListResponse> GetListOfPersons(HousingSearchRequest query)
public async Task<GetPersonListResponse> GetListOfPersons(GetPersonListRequest query)
{
var searchResponse = await _elasticSearchWrapper.Search<QueryablePerson>(query).ConfigureAwait(false);
var searchResponse = await _elasticSearchWrapper.Search<QueryablePerson, GetPersonListRequest>(query).ConfigureAwait(false);
var personListResponse = new GetPersonListResponse();

personListResponse.Persons.AddRange(searchResponse.Documents.Select(queryablePerson =>
Expand All @@ -37,9 +37,9 @@ public async Task<GetPersonListResponse> GetListOfPersons(HousingSearchRequest q
}

[LogCall]
public async Task<GetTenureListResponse> GetListOfTenures(HousingSearchRequest query)
public async Task<GetTenureListResponse> GetListOfTenures(GetTenureListRequest query)
{
var searchResponse = await _elasticSearchWrapper.Search<QueryableTenure>(query).ConfigureAwait(false);
var searchResponse = await _elasticSearchWrapper.Search<QueryableTenure, GetTenureListRequest>(query).ConfigureAwait(false);
var tenureListResponse = new GetTenureListResponse();

tenureListResponse.Tenures.AddRange(searchResponse.Documents.Select(queryableTenure =>
Expand All @@ -52,9 +52,9 @@ public async Task<GetTenureListResponse> GetListOfTenures(HousingSearchRequest q
}

[LogCall]
public async Task<GetAssetListResponse> GetListOfAssets(HousingSearchRequest query)
public async Task<GetAssetListResponse> GetListOfAssets(GetAssetListRequest query)
{
var searchResponse = await _elasticSearchWrapper.Search<QueryableAsset>(query).ConfigureAwait(false);
var searchResponse = await _elasticSearchWrapper.Search<QueryableAsset, GetAssetListRequest>(query).ConfigureAwait(false);
var assetListResponse = new GetAssetListResponse();

assetListResponse.Assets.AddRange(searchResponse.Documents.Select(queryableAsset =>
Expand All @@ -66,9 +66,9 @@ public async Task<GetAssetListResponse> GetListOfAssets(HousingSearchRequest que
return assetListResponse;
}

public async Task<GetAccountListResponse> GetListOfAccounts(HousingSearchRequest query)
public async Task<GetAccountListResponse> GetListOfAccounts(GetAccountListRequest query)
{
var searchResponse = await _elasticSearchWrapper.Search<QueryableAccount>(query).ConfigureAwait(false);
var searchResponse = await _elasticSearchWrapper.Search<QueryableAccount, GetAccountListRequest>(query).ConfigureAwait(false);
var accountListResponse = GetAccountListResponse.Create(searchResponse.Documents.Select(queryableAccount =>
queryableAccount.ToAccount())?.ToList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ElasticSearchWrapper(IElasticClient esClient, IQueryFactory queryFactory,
_indexSelector = indexSelector;
}

public async Task<ISearchResponse<T>> Search<T>(HousingSearchRequest request) where T : class
public async Task<ISearchResponse<T>> Search<T, TRequest>(TRequest request) where T : class where TRequest : class
{
try
{
Expand All @@ -40,12 +40,14 @@ public async Task<ISearchResponse<T>> Search<T>(HousingSearchRequest request) wh
if (request == null)
return new SearchResponse<T>();

var pageOffset = _pagingHelper.GetPageOffset(request.PageSize, request.Page);
HousingSearchRequest searchRequest = (HousingSearchRequest) (object) request;

var pageOffset = _pagingHelper.GetPageOffset(searchRequest.PageSize, searchRequest.Page);

var result = await _esClient.SearchAsync<T>(x => x.Index(_indexSelector.Create<T>())
.Query(q => BaseQuery<T>(request).Create(request, q))
.Sort(_iSortFactory.Create<T>(request).GetSortDescriptor)
.Size(request.PageSize)
.Query(q => BaseQuery<T>().Create(request, q))
.Sort(_iSortFactory.Create<T, TRequest>(request).GetSortDescriptor)
.Size(searchRequest.PageSize)
.Skip(pageOffset)
.TrackTotalHits()).ConfigureAwait(false);

Expand All @@ -60,9 +62,9 @@ public async Task<ISearchResponse<T>> Search<T>(HousingSearchRequest request) wh
}
}

private IQueryGenerator<T> BaseQuery<T>(HousingSearchRequest request) where T : class
private IQueryGenerator<T> BaseQuery<T>() where T : class
{
return _queryFactory.CreateQuery<T>(request);
return _queryFactory.CreateQuery<T>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static void ConfigureElasticSearch(this IServiceCollection services, ICon
var pool = new SingleNodeConnectionPool(new Uri(url));
var connectionSettings =
new ConnectionSettings(pool)
.PrettyJson().ThrowExceptions().DisableDirectStreaming();
.PrettyJson()
.ThrowExceptions()
.DisableDirectStreaming();
var esClient = new ElasticClient(connectionSettings);

services.TryAddSingleton<IElasticClient>(esClient);
Expand Down
Loading