This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
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
21 changed files
with
354 additions
and
4 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
backend/src/Logitar.Master.Application/Projects/Queries/SearchProjectsQuery.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,7 @@ | ||
using Logitar.Master.Contracts.Projects; | ||
using Logitar.Master.Contracts.Search; | ||
using MediatR; | ||
|
||
namespace Logitar.Master.Application.Projects.Queries; | ||
|
||
public record SearchProjectsQuery(SearchProjectsPayload Payload) : IRequest<SearchResults<Project>>; |
20 changes: 20 additions & 0 deletions
20
backend/src/Logitar.Master.Application/Projects/Queries/SearchProjectsQueryHandler.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.Master.Contracts.Projects; | ||
using Logitar.Master.Contracts.Search; | ||
using MediatR; | ||
|
||
namespace Logitar.Master.Application.Projects.Queries; | ||
|
||
internal class SearchProjectsQueryHandler : IRequestHandler<SearchProjectsQuery, SearchResults<Project>> | ||
{ | ||
private readonly IProjectQuerier _projectQuerier; | ||
|
||
public SearchProjectsQueryHandler(IProjectQuerier projectQuerier) | ||
{ | ||
_projectQuerier = projectQuerier; | ||
} | ||
|
||
public async Task<SearchResults<Project>> Handle(SearchProjectsQuery query, CancellationToken cancellationToken) | ||
{ | ||
return await _projectQuerier.SearchAsync(query.Payload, cancellationToken); | ||
} | ||
} |
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 @@ | ||
namespace Logitar.Master.Contracts.Projects; | ||
|
||
public enum ProjectSort | ||
{ | ||
DisplayName, | ||
UniqueKey, | ||
UpdatedOn | ||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/Logitar.Master.Contracts/Projects/ProjectSortOption.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,19 @@ | ||
using Logitar.Master.Contracts.Search; | ||
|
||
namespace Logitar.Master.Contracts.Projects; | ||
|
||
public record ProjectSortOption : SortOption | ||
{ | ||
public new ProjectSort Field | ||
{ | ||
get => Enum.Parse<ProjectSort>(base.Field); | ||
set => base.Field = value.ToString(); | ||
} | ||
public ProjectSortOption() : this(ProjectSort.UpdatedOn, isDescending: true) | ||
{ | ||
} | ||
|
||
public ProjectSortOption(ProjectSort field, bool isDescending = false) : base(field.ToString(), isDescending) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/Logitar.Master.Contracts/Projects/SearchProjectsPayload.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.Master.Contracts.Search; | ||
|
||
namespace Logitar.Master.Contracts.Projects; | ||
|
||
public record SearchProjectsPayload : SearchPayload | ||
{ | ||
public new List<ProjectSortOption>? Sort { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/Logitar.Master.Contracts/Search/SearchOperator.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,7 @@ | ||
namespace Logitar.Master.Contracts.Search; | ||
|
||
public enum SearchOperator | ||
{ | ||
And = 0, | ||
Or = 1 | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/Logitar.Master.Contracts/Search/SearchPayload.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,12 @@ | ||
namespace Logitar.Master.Contracts.Search; | ||
|
||
public record SearchPayload | ||
{ | ||
public List<Guid>? Ids { get; set; } | ||
public TextSearch? Search { get; set; } | ||
|
||
public List<SortOption>? Sort { get; set; } | ||
|
||
public int? Skip { get; set; } | ||
public int? Limit { get; set; } | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/Logitar.Master.Contracts/Search/SearchResults.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,28 @@ | ||
namespace Logitar.Master.Contracts.Search; | ||
|
||
public record SearchResults<T> | ||
{ | ||
public List<T> Items { get; set; } | ||
public long Total { get; set; } | ||
|
||
public SearchResults() | ||
{ | ||
Items = []; | ||
} | ||
|
||
public SearchResults(IEnumerable<T> items) : this() | ||
{ | ||
Items.AddRange(items); | ||
} | ||
|
||
public SearchResults(long total) : this() | ||
{ | ||
Total = total; | ||
} | ||
|
||
public SearchResults(IEnumerable<T> items, long total) : this() | ||
{ | ||
Items.AddRange(items); | ||
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.Master.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.Master.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,18 @@ | ||
namespace Logitar.Master.Contracts.Search; | ||
|
||
public record TextSearch | ||
{ | ||
public List<SearchTerm> Terms { get; set; } | ||
public SearchOperator Operator { get; set; } | ||
|
||
public TextSearch() | ||
{ | ||
Terms = []; | ||
} | ||
|
||
public TextSearch(IEnumerable<SearchTerm> terms, SearchOperator @operator = SearchOperator.And) : this() | ||
{ | ||
Terms.AddRange(terms); | ||
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
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using Logitar.Data; | ||
using Logitar.Master.Contracts.Search; | ||
|
||
namespace Logitar.Master.EntityFrameworkCore; | ||
|
||
public interface ISqlHelper | ||
{ | ||
void ApplyTextSearch(IQueryBuilder query, TextSearch? search, params ColumnId[] columns); | ||
IQueryBuilder QueryFrom(TableId table); | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
backend/src/Logitar.Master.EntityFrameworkCore/QueryingExtensions.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
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
45 changes: 45 additions & 0 deletions
45
backend/src/Logitar.Master.EntityFrameworkCore/SqlHelper.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,45 @@ | ||
using Logitar.Data; | ||
using Logitar.Master.Contracts.Search; | ||
|
||
namespace Logitar.Master.EntityFrameworkCore; | ||
|
||
public abstract class SqlHelper : ISqlHelper | ||
{ | ||
public virtual void ApplyTextSearch(IQueryBuilder query, TextSearch? search, params ColumnId[] columns) | ||
{ | ||
if (search != null && search.Terms.Count > 0 && columns.Length > 0) | ||
{ | ||
List<Condition> conditions = new(capacity: search.Terms.Count); | ||
HashSet<string> patterns = new(capacity: search.Terms.Count); | ||
foreach (SearchTerm term in search.Terms) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(term.Value)) | ||
{ | ||
string pattern = term.Value.Trim(); | ||
if (patterns.Add(pattern)) | ||
{ | ||
conditions.Add(columns.Length == 1 | ||
? new OperatorCondition(columns[0], CreateOperator(pattern)) | ||
: new OrCondition(columns.Select(column => new OperatorCondition(column, CreateOperator(pattern))).ToArray())); | ||
} | ||
} | ||
} | ||
|
||
if (conditions.Count > 0) | ||
{ | ||
switch (search.Operator) | ||
{ | ||
case SearchOperator.And: | ||
query.WhereAnd([.. conditions]); | ||
break; | ||
case SearchOperator.Or: | ||
query.WhereOr([.. conditions]); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
public virtual ConditionalOperator CreateOperator(string pattern) => Operators.IsLike(pattern); | ||
|
||
public abstract IQueryBuilder QueryFrom(TableId table); | ||
} |
Oops, something went wrong.