This commit is contained in:
72
server/AyaNova/Controllers/NameController.cs
Normal file
72
server/AyaNova/Controllers/NameController.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
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;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
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()));
|
||||||
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
||||||
|
{
|
||||||
|
ct.Database.OpenConnection();
|
||||||
|
return Ok(ApiOkResponse.Response(BizObjectNameFetcherDirect.Name(ayType, id, command)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//------------
|
||||||
|
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
}//eons
|
||||||
Reference in New Issue
Block a user