-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathAllIndexerController.cs
More file actions
58 lines (50 loc) · 1.88 KB
/
AllIndexerController.cs
File metadata and controls
58 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Asp.Versioning;
using Examine;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Factories;
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
using Umbraco.Cms.Api.Management.ViewModels.Indexer;
using Umbraco.Extensions;
namespace Umbraco.Cms.Api.Management.Controllers.Indexer;
[ApiVersion("1.0")]
public class AllIndexerController : IndexerControllerBase
{
private readonly IExamineManager _examineManager;
private readonly IIndexPresentationFactory _indexPresentationFactory;
public AllIndexerController(
IExamineManager examineManager,
IIndexPresentationFactory indexPresentationFactory)
{
_examineManager = examineManager;
_indexPresentationFactory = indexPresentationFactory;
}
/// <summary>
/// Get the details for indexers
/// </summary>
/// <returns></returns>
[HttpGet]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<IndexResponseModel>), StatusCodes.Status200OK)]
[EndpointSummary("Gets a collection of indexers.")]
[EndpointDescription("Gets a collection of configured search indexers in the Umbraco installation.")]
public async Task<PagedViewModel<IndexResponseModel>> All(
CancellationToken cancellationToken,
int skip = 0,
int take = 100)
{
var indexes = new List<IndexResponseModel>();
foreach (IIndex index in _examineManager.Indexes)
{
indexes.Add(await _indexPresentationFactory.CreateAsync(index));
}
indexes.Sort((a, b) =>
string.Compare(a.Name.TrimEnd("Indexer"), b.Name.TrimEnd("Indexer"), StringComparison.Ordinal));
var viewModel = new PagedViewModel<IndexResponseModel>
{
Items = indexes.Skip(skip).Take(take),
Total = indexes.Count,
};
return viewModel;
}
}