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

Added filters to the use-case request. #47

Merged
merged 3 commits into from
Sep 13, 2024
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 @@ -59,7 +59,7 @@ public CognitiveSearchServiceAdapter(
/// Prescribes the context of the search including the keyword and collection target.
/// </param>
/// <returns>
/// A configured <<see cref="SearchResults"/> object hydrated from the results of the azure search.
/// A configured <see cref="SearchResults"/> object hydrated from the results of the azure search.
/// </returns>
/// <exception cref="ApplicationException">
/// An application exception is thrown if we either have no options configured, which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <summary>
/// Prescribes the context of the search including
/// the keyword, search fields, and facets to use.
/// </summary>
public sealed class SearchServiceAdapterRequest
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase;

/// <summary>
/// Encapsulates a single filter to be applied to the search request
/// </summary>
public class FilterRequest
{
/// <summary>
/// The name of the filter field
/// </summary>
public string FilterName { get; }

/// <summary>
/// The readonly list of values of the filter to be included in the filter expression
/// </summary>
public IList<object> FilterValues => _filterValues.AsReadOnly();

private IList<object> _filterValues;

/// <summary>
/// Constructor that initialises the <see cref="FilterName"/> and the <see cref="FilterValues"/>
/// </summary>
/// <param name="filterName"></param>
/// <param name="filterValues"></param>
public FilterRequest(string filterName, IList<object> filterValues)
{
FilterName = filterName;
_filterValues = filterValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
public sealed class SearchByKeywordRequest
{
/// <summary>
/// The following arguments are passed via the constructor and used to create
/// The following search keyword argument is passed via the constructor and used to create
/// an immutable <see cref="SearchByKeywordRequest" /> instance which encapsulates
/// the parameters required to formulate a valid search request.
/// the search keyword required to formulate a valid (baseline) search request.
/// </summary>
/// <param name="searchKeyword">
/// The string keyword used to search the collection specified.
Expand All @@ -21,8 +21,29 @@ public SearchByKeywordRequest(string searchKeyword)
SearchKeyword = searchKeyword;
}

/// <summary>
/// The following search keyword and filter arguments are passed via the constructor and used to create
/// an immutable <see cref="SearchByKeywordRequest" /> instance which encapsulates the parameters required
/// to formulate a valid search request which are refined using the provisioned filters.
/// </summary>
/// <param name="searchKeyword">
/// The string keyword used to search the collection specified.
/// </param>
/// <param name="filterRequests">
/// The <see cref="FilterRequest"/> used to refine the search criteria.
/// </param>
public SearchByKeywordRequest(string searchKeyword, IList<FilterRequest> filterRequests) : this(searchKeyword)
{
FilterRequests = filterRequests;
}

/// <summary>
/// The string keyword used to search the collection specified.
/// </summary>
public string SearchKeyword { get; }

/// <summary>
/// The filter (key/values) used to refine the search criteria.
/// </summary>
public IList<FilterRequest>? FilterRequests { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase;
using FluentAssertions;
using Xunit;

namespace Dfe.Data.SearchPrototype.Tests.SearchForEstablishments.ByKeyword;

public class SearchByKeywordRequestTests
{
[Fact]
public void Constructor_WithFilterParam_PopulatesFilterRequests()
{
// arrange
var filterList = new List<FilterRequest>()
{
new FilterRequest("EducationPhase", new List<object>() {"Primary", "Secondary"}),
new FilterRequest("MaybeATypeCode", new List<object>() {1,2})
};

// act
var request = new SearchByKeywordRequest("searchKeyword", filterList);

// assert
request.FilterRequests.Should().NotBeNull();
foreach (var item in filterList)
{
var matchingRequest = request.FilterRequests!.First(x => x.FilterName == item.FilterName);
matchingRequest.FilterValues.Should().BeEquivalentTo(item.FilterValues);
}
}

[Fact]
public void Constructor_WithNoFilterParam_HasFilterRequestsNull()
{
// act
var request = new SearchByKeywordRequest("searchKeyword");

// assert
request.FilterRequests.Should().BeNull();
}
}