Add endpoint for retrieveing the configured default language (#16086)
* Add endpoint for retrieveing the configured default language * Update OpenApi.json
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Language.Item;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.Language.Item;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
public class DefaultLanguageEntityController : LanguageEntityControllerBase
|
||||
{
|
||||
private readonly ILanguageService _languageService;
|
||||
private readonly IUmbracoMapper _mapper;
|
||||
|
||||
public DefaultLanguageEntityController(ILanguageService languageService, IUmbracoMapper mapper)
|
||||
{
|
||||
_languageService = languageService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("default")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(LanguageItemResponseModel), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> Default(CancellationToken cancellationToken)
|
||||
{
|
||||
ILanguage? language = await _languageService.GetDefaultLanguageAsync();
|
||||
return language is not null
|
||||
? Ok(_mapper.Map<ILanguage, LanguageItemResponseModel>(language))
|
||||
: OperationStatusResult(
|
||||
LanguageOperationStatus.NotFound,
|
||||
problemDetailsBuilder => NotFound(problemDetailsBuilder.WithTitle("The default language could not be found.")));
|
||||
}
|
||||
}
|
||||
@@ -11419,6 +11419,41 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/umbraco/management/api/v1/item/language/default": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Language"
|
||||
],
|
||||
"operationId": "GetItemLanguageDefault",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/LanguageItemResponseModel"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "The resource is protected and requires an authentication token"
|
||||
},
|
||||
"403": {
|
||||
"description": "The authenticated user do not have access to this resource"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"Backoffice User": [ ]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/umbraco/management/api/v1/language": {
|
||||
"get": {
|
||||
"tags": [
|
||||
|
||||
@@ -14,6 +14,14 @@ public interface ILanguageService
|
||||
/// </returns>
|
||||
Task<ILanguage?> GetAsync(string isoCode);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="ILanguage" />
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <see cref="ILanguage" />
|
||||
/// </returns>
|
||||
Task<ILanguage?> GetDefaultLanguageAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default language ISO code.
|
||||
/// </summary>
|
||||
|
||||
@@ -42,6 +42,15 @@ internal sealed class LanguageService : RepositoryService, ILanguageService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ILanguage?> GetDefaultLanguageAsync()
|
||||
{
|
||||
using (ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
return await Task.FromResult(_languageRepository.GetByIsoCode(_languageRepository.GetDefaultIsoCode()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetDefaultIsoCodeAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user