This commit is contained in:
@@ -11,14 +11,12 @@ using Microsoft.Extensions.Logging;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
|
using AyaNova.DataList;
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[ApiVersion("8.0")]
|
[ApiVersion("8.0")]
|
||||||
[Route("api/v{version:apiVersion}/[controller]")]
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
@@ -49,12 +47,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// Get full DataListTemplate object
|
/// Get full DataListTemplate object
|
||||||
///
|
///
|
||||||
/// Required roles:
|
/// Required roles:
|
||||||
/// Any (for public filter), owned only for private filter
|
/// Any
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="DataListKey"></param>
|
||||||
/// <returns>A single DataListTemplate</returns>
|
/// <returns>A single DataListTemplate</returns>
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{DataListKey}")]
|
||||||
public async Task<IActionResult> GetDataListTemplate([FromRoute] long id)
|
public async Task<IActionResult> GetDataListTemplate([FromRoute] string DataListKey)
|
||||||
{
|
{
|
||||||
if (serverState.IsClosed)
|
if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
@@ -68,7 +66,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
var o = await biz.GetAsync(id);
|
var o = await biz.GetAsync(DataListKey);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
@@ -76,29 +74,21 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get DataListTemplate pick list
|
/// List of all DataList keys available
|
||||||
///
|
///
|
||||||
/// Required roles: Any
|
/// Required roles: Any
|
||||||
///
|
/// </summary>
|
||||||
/// </summary>
|
/// <returns>List of strings</returns>
|
||||||
/// <returns>List of public or owned data filters for listKey provided</returns>
|
[HttpGet("ListKeys")]
|
||||||
[HttpGet("PickList", Name = nameof(DataListTemplatePickList))]
|
public ActionResult GetDataListKeys()
|
||||||
public async Task<IActionResult> DataListTemplatePickList([FromQuery] string ListKey)
|
|
||||||
{
|
{
|
||||||
if (serverState.IsClosed)
|
if (!serverState.IsOpen)
|
||||||
|
{
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
|
}
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
return Ok(ApiOkResponse.Response(DataListFactory.GetListOfAllDataListKeyNames(), true));
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
|
||||||
|
|
||||||
//Instantiate the business object handler
|
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
|
||||||
|
|
||||||
var l = await biz.GetPickListAsync(ListKey);
|
|
||||||
return Ok(ApiOkResponse.Response(l, true));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,14 +96,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// Put (update) DataListTemplate
|
/// Put (update) DataListTemplate
|
||||||
///
|
///
|
||||||
/// Required roles:
|
/// Required roles:
|
||||||
/// Any (public filter) or owned only (private filter)
|
/// BizAdminFull
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="DataListKey"></param>
|
||||||
/// <param name="inObj"></param>
|
/// <param name="inObj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{DataListKey}")]
|
||||||
public async Task<IActionResult> PutDataListTemplate([FromRoute] long id, [FromBody] DataListTemplate inObj)
|
public async Task<IActionResult> PutDataListTemplate([FromRoute] string DataListKey, [FromBody] DataListTemplate inObj)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
@@ -124,7 +114,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetNoLogAsync(id);
|
var o = await biz.GetNoLogAsync(DataListKey);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
@@ -138,62 +128,28 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if (!await biz.ExistsAsync(id))
|
// if (!await biz.ExistsAsync(id))
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
else
|
// else
|
||||||
|
//these always exist so can only be concurrency conflict
|
||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||||
}
|
}
|
||||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Post DataListTemplate
|
|
||||||
///
|
|
||||||
/// Required roles:
|
|
||||||
/// BizAdminFull, InventoryFull, TechFull
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="inObj"></param>
|
|
||||||
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost]
|
|
||||||
public async Task<IActionResult> PostDataListTemplate([FromBody] DataListTemplate inObj, ApiVersion apiVersion)
|
|
||||||
{
|
|
||||||
if (!serverState.IsOpen)
|
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
|
||||||
|
|
||||||
//Instantiate the business object handler
|
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
|
||||||
|
|
||||||
//If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner
|
|
||||||
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
|
||||||
|
|
||||||
//Create and validate
|
|
||||||
DataListTemplate o = await biz.CreateAsync(inObj);
|
|
||||||
if (o == null)
|
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
|
||||||
else
|
|
||||||
return CreatedAtAction(nameof(DataListTemplateController.GetDataListTemplate), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete DataListTemplate
|
/// Delete DataListTemplate
|
||||||
///
|
/// (Reset DataListTemplate to default)
|
||||||
/// Required roles:
|
/// Required roles:
|
||||||
/// Any if public otherwise creator only
|
/// BizAdminFull
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="DataListKey"></param>
|
||||||
/// <returns>Ok</returns>
|
/// <returns>Ok</returns>
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{DataListKey}")]
|
||||||
public async Task<IActionResult> DeleteDataListTemplate([FromRoute] long id)
|
public async Task<IActionResult> DeleteDataListTemplate([FromRoute] string DataListKey)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
@@ -204,7 +160,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetNoLogAsync(id);
|
var o = await biz.GetNoLogAsync(DataListKey);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user