-
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
18 changed files
with
349 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Logitar.Cms.Contracts.Contents; | ||
|
||
public enum ContentSort | ||
{ | ||
UniqueName, | ||
UpdatedOn | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/Logitar.Cms.Contracts/Contents/ContentSortOption.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.Contents; | ||
|
||
public record ContentSortOption : SortOption | ||
{ | ||
public new ContentSort Field | ||
{ | ||
get => Enum.Parse<ContentSort>(base.Field); | ||
set => base.Field = value.ToString(); | ||
} | ||
|
||
public ContentSortOption() : this(ContentSort.UpdatedOn, isDescending: true) | ||
{ | ||
} | ||
|
||
public ContentSortOption(ContentSort field, bool isDescending = false) : base(field.ToString(), isDescending) | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/Logitar.Cms.Contracts/Contents/SearchContentsPayload.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 @@ | ||
using Logitar.Cms.Contracts.Search; | ||
|
||
namespace Logitar.Cms.Contracts.Contents; | ||
|
||
public record SearchContentsPayload : SearchPayload | ||
{ | ||
public Guid? ContentTypeId { get; set; } | ||
public Guid? LanguageId { get; set; } | ||
|
||
public new List<ContentSortOption>? 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
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
7 changes: 7 additions & 0 deletions
7
backend/src/Logitar.Cms.Core/Contents/Queries/SearchContentsQuery.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.Cms.Contracts.Contents; | ||
using Logitar.Cms.Contracts.Search; | ||
using MediatR; | ||
|
||
namespace Logitar.Cms.Core.Contents.Queries; | ||
|
||
public record SearchContentsQuery(SearchContentsPayload Payload) : IRequest<SearchResults<ContentLocale>>; |
20 changes: 20 additions & 0 deletions
20
backend/src/Logitar.Cms.Core/Contents/Queries/SearchContentsQueryHandler.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.Contents; | ||
using Logitar.Cms.Contracts.Search; | ||
using MediatR; | ||
|
||
namespace Logitar.Cms.Core.Contents.Queries; | ||
|
||
internal class SearchContentsQueryHandler : IRequestHandler<SearchContentsQuery, SearchResults<ContentLocale>> | ||
{ | ||
private readonly IContentQuerier _contentQuerier; | ||
|
||
public SearchContentsQueryHandler(IContentQuerier fieldTypeQuerier) | ||
{ | ||
_contentQuerier = fieldTypeQuerier; | ||
} | ||
|
||
public async Task<SearchResults<ContentLocale>> Handle(SearchContentsQuery query, CancellationToken cancellationToken) | ||
{ | ||
return await _contentQuerier.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
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
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
41 changes: 41 additions & 0 deletions
41
backend/src/Logitar.Cms.Web/Models/Contents/SearchContentsParameters.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,41 @@ | ||
using Logitar.Cms.Contracts.Contents; | ||
using Logitar.Cms.Contracts.Search; | ||
using Logitar.Cms.Web.Models.Search; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Logitar.Cms.Web.Models.Contents; | ||
|
||
public record SearchContentsParameters : SearchParameters | ||
{ | ||
[FromQuery(Name = "type")] | ||
public Guid? ContentTypeId { get; set; } | ||
|
||
[FromQuery(Name = "language")] | ||
public Guid? LanguageId { get; set; } | ||
|
||
public SearchContentsPayload ToPayload() | ||
{ | ||
SearchContentsPayload payload = new() | ||
{ | ||
ContentTypeId = ContentTypeId, | ||
LanguageId = LanguageId | ||
}; | ||
|
||
FillPayload(payload); | ||
|
||
var sortOptions = ((SearchPayload)payload).Sort; | ||
if (sortOptions != null) | ||
{ | ||
payload.Sort = new List<ContentSortOption>(capacity: sortOptions.Count); | ||
foreach (var sort in sortOptions) | ||
{ | ||
if (Enum.TryParse(sort.Field, out ContentSort field)) | ||
{ | ||
payload.Sort.Add(new ContentSortOption(field, sort.IsDescending)); | ||
} | ||
} | ||
} | ||
|
||
return payload; | ||
} | ||
} |
Oops, something went wrong.