-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
backend/src/Logitar.Cms.Contracts/Languages/LanguageSort.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Logitar.Cms.Contracts.Languages; | ||
|
||
public enum LanguageSort | ||
{ | ||
Code, | ||
CreatedOn, | ||
DisplayName, | ||
EnglishName, | ||
NativeName, | ||
UpdatedOn | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/Logitar.Cms.Contracts/Languages/LanguageSortOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Logitar.Cms.Contracts.Search; | ||
|
||
namespace Logitar.Cms.Contracts.Languages; | ||
|
||
public record LanguageSortOption : SortOption | ||
{ | ||
public new LanguageSort Field | ||
{ | ||
get => Enum.Parse<LanguageSort>(base.Field); | ||
set => base.Field = value.ToString(); | ||
} | ||
|
||
public LanguageSortOption() : this(LanguageSort.DisplayName) | ||
{ | ||
} | ||
|
||
public LanguageSortOption(LanguageSort field, bool isDescending = false) : base(field.ToString(), isDescending) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/Logitar.Cms.Contracts/Languages/SearchLanguagesPayload.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Logitar.Cms.Contracts.Search; | ||
|
||
namespace Logitar.Cms.Contracts.Languages; | ||
|
||
public record SearchLanguagesPayload : SearchPayload | ||
{ | ||
public new List<LanguageSortOption> Sort { get; set; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public enum SearchOperator | ||
{ | ||
And = 0, | ||
Or = 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public record SearchPayload | ||
{ | ||
public List<Guid> Ids { get; set; } = []; | ||
public TextSearch Search { get; set; } = new(); | ||
|
||
public List<SortOption> Sort { get; set; } = []; | ||
|
||
public int Skip { get; set; } | ||
public int Limit { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public record SearchResults<T> | ||
{ | ||
public List<T> Items { get; set; } | ||
public long Total { get; set; } | ||
|
||
public SearchResults() : this([]) | ||
{ | ||
} | ||
|
||
public SearchResults(IEnumerable<T> items) : this(items, items.LongCount()) | ||
{ | ||
} | ||
|
||
public SearchResults(long total) : this([], total) | ||
{ | ||
} | ||
|
||
public SearchResults(IEnumerable<T> items, long total) | ||
{ | ||
Items = items.ToList(); | ||
Total = total; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public record SearchTerm | ||
{ | ||
public string Value { get; set; } | ||
|
||
public SearchTerm() : this(string.Empty) | ||
{ | ||
} | ||
|
||
public SearchTerm(string value) | ||
{ | ||
Value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public record SortOption | ||
{ | ||
public string Field { get; set; } | ||
public bool IsDescending { get; set; } | ||
|
||
public SortOption() : this(string.Empty) | ||
{ | ||
} | ||
|
||
public SortOption(string field, bool isDescending = false) | ||
{ | ||
Field = field; | ||
IsDescending = isDescending; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Logitar.Cms.Contracts.Search; | ||
|
||
public record TextSearch | ||
{ | ||
public List<SearchTerm> Terms { get; set; } | ||
public SearchOperator Operator { get; set; } | ||
|
||
public TextSearch() : this([]) | ||
{ | ||
} | ||
|
||
public TextSearch(IEnumerable<SearchTerm> terms, SearchOperator @operator = SearchOperator.And) | ||
{ | ||
Terms = terms.ToList(); | ||
Operator = @operator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/src/Logitar.Cms.Core/Languages/Queries/SearchLanguagesQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Logitar.Cms.Contracts.Languages; | ||
using Logitar.Cms.Contracts.Search; | ||
using MediatR; | ||
|
||
namespace Logitar.Cms.Core.Languages.Queries; | ||
|
||
public record SearchLanguagesQuery(SearchLanguagesPayload Payload) : IRequest<SearchResults<LanguageModel>>; | ||
|
||
internal class SearchLanguagesQueryHandler : IRequestHandler<SearchLanguagesQuery, SearchResults<LanguageModel>> | ||
{ | ||
private readonly ILanguageQuerier _languageQuerier; | ||
|
||
public SearchLanguagesQueryHandler(ILanguageQuerier languageQuerier) | ||
{ | ||
_languageQuerier = languageQuerier; | ||
} | ||
|
||
public async Task<SearchResults<LanguageModel>> Handle(SearchLanguagesQuery query, CancellationToken cancellationToken) | ||
{ | ||
return await _languageQuerier.SearchAsync(query.Payload, cancellationToken); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...nd/tests/Logitar.Cms.Core.UnitTests/Languages/Queries/SearchLanguagesQueryHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Logitar.Cms.Contracts.Languages; | ||
using Logitar.Cms.Contracts.Search; | ||
using Moq; | ||
|
||
namespace Logitar.Cms.Core.Languages.Queries; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class SearchLanguagesQueryHandlerTests | ||
{ | ||
private readonly CancellationToken _cancellationToken = default; | ||
|
||
private readonly Mock<ILanguageQuerier> _languageQuerier = new(); | ||
|
||
private readonly SearchLanguagesQueryHandler _handler; | ||
|
||
public SearchLanguagesQueryHandlerTests() | ||
{ | ||
_handler = new(_languageQuerier.Object); | ||
} | ||
|
||
[Fact(DisplayName = "It should return the correct search results.")] | ||
public async Task It_should_return_the_correct_search_results() | ||
{ | ||
SearchLanguagesPayload payload = new(); | ||
|
||
SearchResults<LanguageModel> results = new(); | ||
_languageQuerier.Setup(x => x.SearchAsync(payload, _cancellationToken)).ReturnsAsync(results); | ||
|
||
SearchLanguagesQuery query = new(payload); | ||
|
||
SearchResults<LanguageModel> searchResults = await _handler.Handle(query, _cancellationToken); | ||
Assert.Same(results, searchResults); | ||
} | ||
} |