-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathDetailsIndexerController.cs
More file actions
57 lines (51 loc) · 2.18 KB
/
DetailsIndexerController.cs
File metadata and controls
57 lines (51 loc) · 2.18 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
using Asp.Versioning;
using Examine;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Factories;
using Umbraco.Cms.Api.Management.ViewModels.Indexer;
namespace Umbraco.Cms.Api.Management.Controllers.Indexer;
[ApiVersion("1.0")]
public class DetailsIndexerController : IndexerControllerBase
{
private readonly IIndexPresentationFactory _indexPresentationFactory;
private readonly IExamineManager _examineManager;
public DetailsIndexerController(
IIndexPresentationFactory indexPresentationFactory,
IExamineManager examineManager)
{
_indexPresentationFactory = indexPresentationFactory;
_examineManager = examineManager;
}
/// <summary>
/// Check if the index has been rebuilt
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="indexName">The name of the index.</param>
/// <returns>The index details.</returns>
/// <remarks>
/// This is kind of rudimentary since there's no way we can know that the index has rebuilt, we
/// have a listener for the index op complete so we'll just check if that id is no longer there in the runtime cache
/// </remarks>
[HttpGet("{indexName}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(IndexResponseModel), StatusCodes.Status200OK)]
[EndpointSummary("Gets indexer details.")]
[EndpointDescription("Gets detailed information about the indexer identified by the provided name.")]
public async Task<ActionResult<IndexResponseModel?>> Details(CancellationToken cancellationToken, string indexName)
{
if (_examineManager.TryGetIndex(indexName, out IIndex? index))
{
return await _indexPresentationFactory.CreateAsync(index);
}
var invalidModelProblem = new ProblemDetails
{
Title = "Index Not Found",
Detail = $"No index found with name = {indexName}",
Status = StatusCodes.Status400BadRequest,
Type = "Error",
};
return NotFound(invalidModelProblem);
}
}