68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.Logging;
|
|
using AyaNova.Models;
|
|
using AyaNova.Api.ControllerHelpers;
|
|
using AyaNova.Biz;
|
|
|
|
namespace AyaNova.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[ApiVersion("8.0")]
|
|
[Route("api/v{version:apiVersion}/name")]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
public class NameController : ControllerBase
|
|
{
|
|
private readonly AyContext ct;
|
|
private readonly ILogger<NameController> log;
|
|
private readonly ApiServerState serverState;
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
/// <param name="dbcontext"></param>
|
|
/// <param name="logger"></param>
|
|
/// <param name="apiServerState"></param>
|
|
public NameController(AyContext dbcontext, ILogger<NameController> logger, ApiServerState apiServerState)
|
|
{
|
|
ct = dbcontext;
|
|
log = logger;
|
|
serverState = apiServerState;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Get Name of business object
|
|
/// not all business objects have names some may return '-' or simply the type name
|
|
/// if that is the case
|
|
/// </summary>
|
|
/// <param name="ayType">AyaType</param>
|
|
/// <param name="id">Non zero id, if zero returns type name</param>
|
|
/// <returns>Name</returns>
|
|
[HttpGet("{ayType}/{id}")]
|
|
public ActionResult GetName([FromRoute] AyaType ayType, [FromRoute] long id)
|
|
{
|
|
if (!serverState.IsOpen)
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
if (!Authorized.HasSelectRole(HttpContext.Items, ayType))
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(new ApiErrorResponse(ModelState));
|
|
if (id == 0)
|
|
return Ok(ApiOkResponse.Response(ayType.ToString()));
|
|
|
|
return Ok(ApiOkResponse.Response(BizObjectNameFetcherDirect.Name(ayType, id, ct)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------
|
|
|
|
|
|
}//eoc
|
|
}//eons |