Files
Umbraco-CMS/src/Umbraco.Cms.Api.Delivery/Controllers/ContentApiControllerBase.cs
Elitsa Marinovska 7ed59f05cb Delivery API: Not Found response when the start-item in "Start-Item" header is invalid (#14217)
* Update comment

* Implement ValidateStartItemAttribute

* Implement StartItemHeaderHasValue() on IRequestStartItemProvider

* Fix case-sensitivity problem on url segment

* Change StartItemHeaderHasValue() to RequestedStartItem()

* Fix variant start-item header bug

* Rearranging attributes

* Revert to not explicitly get the culture from IRequestCultureService

---------

Co-authored-by: kjac <kja@umbraco.dk>
2023-05-10 08:05:57 +02:00

48 lines
2.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Api.Delivery.Filters;
using Umbraco.Cms.Api.Delivery.Routing;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Services.OperationStatus;
namespace Umbraco.Cms.Api.Delivery.Controllers;
[VersionedDeliveryApiRoute("content")]
[ApiExplorerSettings(GroupName = "Content")]
[LocalizeFromAcceptLanguageHeader]
[ValidateStartItem]
public abstract class ContentApiControllerBase : DeliveryApiControllerBase
{
protected IApiPublishedContentCache ApiPublishedContentCache { get; }
protected IApiContentResponseBuilder ApiContentResponseBuilder { get; }
protected ContentApiControllerBase(IApiPublishedContentCache apiPublishedContentCache, IApiContentResponseBuilder apiContentResponseBuilder)
{
ApiPublishedContentCache = apiPublishedContentCache;
ApiContentResponseBuilder = apiContentResponseBuilder;
}
protected IActionResult ApiContentQueryOperationStatusResult(ApiContentQueryOperationStatus status) =>
status switch
{
ApiContentQueryOperationStatus.FilterOptionNotFound => BadRequest(new ProblemDetailsBuilder()
.WithTitle("Filter option not found")
.WithDetail("One of the attempted 'filter' options does not exist")
.Build()),
ApiContentQueryOperationStatus.IndexNotFound => BadRequest(new ProblemDetailsBuilder()
.WithTitle("Examine index not found")
.WithDetail($"No index found with name {Constants.UmbracoIndexes.DeliveryApiContentIndexName}")
.Build()),
ApiContentQueryOperationStatus.SelectorOptionNotFound => BadRequest(new ProblemDetailsBuilder()
.WithTitle("Selector option not found")
.WithDetail("The attempted 'fetch' option does not exist")
.Build()),
ApiContentQueryOperationStatus.SortOptionNotFound => BadRequest(new ProblemDetailsBuilder()
.WithTitle("Sort option not found")
.WithDetail("One of the attempted 'sort' options does not exist")
.Build()),
};
}