Backoffice Api: Server Controller (#12932)
* Add initial implementation using 1 controller pr. action
* Add OpenApiTag attribute
Otherwise the endpoints won't be grouped correctly
* Use correct response type
* Move ApiVersion to endpoint controllers
* Add ServerController suffix to endpoint controllers
(cherry picked from commit 9cf7e965a9)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NSwag.Annotations;
|
||||
using Umbraco.New.Cms.Web.Common.Routing;
|
||||
|
||||
namespace Umbraco.Cms.ManagementApi.Controllers.Server;
|
||||
|
||||
[ApiController]
|
||||
[BackOfficeRoute("api/v{version:apiVersion}/server")]
|
||||
[OpenApiTag("Server")]
|
||||
public abstract class ServerControllerBase : Controller
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.ManagementApi.ViewModels.Server;
|
||||
|
||||
namespace Umbraco.Cms.ManagementApi.Controllers.Server;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
public class StatusServerController : ServerControllerBase
|
||||
{
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
|
||||
public StatusServerController(IRuntimeState runtimeState) => _runtimeState = runtimeState;
|
||||
|
||||
[HttpGet("status")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ServerStatusViewModel), StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<ServerStatusViewModel>> Get() =>
|
||||
new ServerStatusViewModel { ServerStatus = _runtimeState.Level };
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.ManagementApi.ViewModels.Server;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.ManagementApi.Controllers.Server;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
public class VersionServerController : ServerControllerBase
|
||||
{
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
|
||||
public VersionServerController(IUmbracoVersion umbracoVersion) => _umbracoVersion = umbracoVersion;
|
||||
|
||||
[HttpGet("version")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(VersionViewModel), StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<VersionViewModel>> Get() =>
|
||||
new VersionViewModel { Version = _umbracoVersion.SemanticVersion.ToSemanticStringWithoutBuild() };
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Umbraco.Cms.Core;
|
||||
|
||||
namespace Umbraco.Cms.ManagementApi.ViewModels.Server;
|
||||
|
||||
public class ServerStatusViewModel
|
||||
{
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public RuntimeLevel ServerStatus { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.ManagementApi.ViewModels.Server;
|
||||
|
||||
public class VersionViewModel
|
||||
{
|
||||
public string Version { get; set; } = null!;
|
||||
}
|
||||
Reference in New Issue
Block a user