-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
* Add endpoint for retrieveing the configured default language * Update OpenApi.json
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Check failure on line 13 in src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs GitHub Actions / CodeQL-Build
Check failure on line 13 in src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs GitHub Actions / CodeQL-Build
Check failure on line 13 in src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs Azure Pipelines / Umbraco CMS 9+ (Build Build Umbraco CMS)src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs#L13
Check failure on line 13 in src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs Azure Pipelines / Umbraco CMS 9+src/Umbraco.Cms.Api.Management/Controllers/Language/Item/DefaultLanguageEntityController.cs#L13
|
||
{ | ||
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."))); | ||
} | ||
} |