This commit is contained in:
@@ -11,14 +11,12 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.DataList;
|
||||
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
@@ -49,12 +47,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// Get full DataListTemplate object
|
||||
///
|
||||
/// Required roles:
|
||||
/// Any (for public filter), owned only for private filter
|
||||
/// Any
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="DataListKey"></param>
|
||||
/// <returns>A single DataListTemplate</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetDataListTemplate([FromRoute] long id)
|
||||
[HttpGet("{DataListKey}")]
|
||||
public async Task<IActionResult> GetDataListTemplate([FromRoute] string DataListKey)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
@@ -68,7 +66,7 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var o = await biz.GetAsync(id);
|
||||
var o = await biz.GetAsync(DataListKey);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
@@ -76,29 +74,21 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get DataListTemplate pick list
|
||||
/// List of all DataList keys available
|
||||
///
|
||||
/// Required roles: Any
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>List of public or owned data filters for listKey provided</returns>
|
||||
[HttpGet("PickList", Name = nameof(DataListTemplatePickList))]
|
||||
public async Task<IActionResult> DataListTemplatePickList([FromQuery] string ListKey)
|
||||
/// </summary>
|
||||
/// <returns>List of strings</returns>
|
||||
[HttpGet("ListKeys")]
|
||||
public ActionResult GetDataListKeys()
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
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));
|
||||
|
||||
return Ok(ApiOkResponse.Response(DataListFactory.GetListOfAllDataListKeyNames(), true));
|
||||
}
|
||||
|
||||
|
||||
@@ -106,14 +96,14 @@ namespace AyaNova.Api.Controllers
|
||||
/// Put (update) DataListTemplate
|
||||
///
|
||||
/// Required roles:
|
||||
/// Any (public filter) or owned only (private filter)
|
||||
/// BizAdminFull
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="DataListKey"></param>
|
||||
/// <param name="inObj"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutDataListTemplate([FromRoute] long id, [FromBody] DataListTemplate inObj)
|
||||
[HttpPut("{DataListKey}")]
|
||||
public async Task<IActionResult> PutDataListTemplate([FromRoute] string DataListKey, [FromBody] DataListTemplate inObj)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
@@ -124,7 +114,7 @@ namespace AyaNova.Api.Controllers
|
||||
//Instantiate the business object handler
|
||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.GetNoLogAsync(id);
|
||||
var o = await biz.GetNoLogAsync(DataListKey);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
@@ -138,62 +128,28 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await biz.ExistsAsync(id))
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
else
|
||||
// if (!await biz.ExistsAsync(id))
|
||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
// else
|
||||
//these always exist so can only be concurrency conflict
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
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>
|
||||
/// Delete DataListTemplate
|
||||
///
|
||||
/// (Reset DataListTemplate to default)
|
||||
/// Required roles:
|
||||
/// Any if public otherwise creator only
|
||||
/// BizAdminFull
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="DataListKey"></param>
|
||||
/// <returns>Ok</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteDataListTemplate([FromRoute] long id)
|
||||
[HttpDelete("{DataListKey}")]
|
||||
public async Task<IActionResult> DeleteDataListTemplate([FromRoute] string DataListKey)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
@@ -204,7 +160,7 @@ namespace AyaNova.Api.Controllers
|
||||
//Instantiate the business object handler
|
||||
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.GetNoLogAsync(id);
|
||||
var o = await biz.GetNoLogAsync(DataListKey);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user