This commit is contained in:
116
server/AyaNova/Controllers/PickListController.cs
Normal file
116
server/AyaNova/Controllers/PickListController.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
//using AyaNova.PickList;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class PickListController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<PickListController> log;
|
||||
private readonly ApiServerState serverState;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="dbcontext"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="apiServerState"></param>
|
||||
public PickListController(AyContext dbcontext, ILogger<PickListController> logger, ApiServerState apiServerState)
|
||||
{
|
||||
ct = dbcontext;
|
||||
log = logger;
|
||||
serverState = apiServerState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get picklist
|
||||
/// </summary>
|
||||
/// <param name="ayaType">The AyaType object type to select from</param>
|
||||
/// <param name="query">The query to filter the returned list by</param>
|
||||
/// <returns>Filtered list (maximum 25 items are returned for any query)</returns>
|
||||
[HttpGet("List")]
|
||||
public async Task<IActionResult> GetList([FromQuery]AyaType ayaType, [FromQuery]string query)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// //NOTE: This is the first check and often the only check but in some cases with some objects this will also need to check biz object rules
|
||||
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var o = await biz.GetPickListAsync(ayaType,query);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
|
||||
return Ok(ApiOkResponse.Response(o, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// List of all PickList templates
|
||||
/// </summary>
|
||||
/// <returns>List of strings</returns>
|
||||
[HttpGet("TemplateList")]
|
||||
public ActionResult GetTemplateList()
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
return Ok(ApiOkResponse.Response(PickListFactory.GetListOfAllPickListKeyNames(), true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// List of all fields for data list key specified
|
||||
/// </summary>
|
||||
/// <returns>List of PickListFieldDefinition</returns>
|
||||
[HttpGet("ListFields")]
|
||||
public ActionResult GetPickListFields([FromQuery] string PickListKey)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
var PickList = PickListFactory.GetAyaPickList(PickListKey);
|
||||
//was the name not found as a list?
|
||||
if (PickList == null)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "PickListKey", $"PickList \"{PickListKey}\" specified does not exist"));
|
||||
}
|
||||
|
||||
return Ok(ApiOkResponse.Response(PickList.FieldDefinitions, true));
|
||||
}
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
Reference in New Issue
Block a user