This commit is contained in:
2020-03-12 18:37:31 +00:00
parent 73662fab87
commit 2ac227875f
5 changed files with 215 additions and 175 deletions

View File

@@ -40,10 +40,6 @@ namespace AyaNova.Api.Controllers
serverState = apiServerState;
}
TODO: need a db schema table and objects to hold the picklist templates
//while they may have an ID to make them easier to work with, they are fetched and stored by the object type only (which is a type of id and unique so maybe it's still id
//but not an autonumber type id, have to check into that)
/// <summary>
@@ -70,7 +66,9 @@ TODO: need a db schema table and objects to hold the picklist templates
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var o = await biz.GetPickListAsync(ayaType, query);
var UserRoles = UserRolesFromContext.Roles(HttpContext.Items);
var o = await biz.GetPickListAsync(ayaType, query, UserRoles);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
@@ -84,14 +82,25 @@ TODO: need a db schema table and objects to hold the picklist templates
/// </summary>
/// <returns>List of strings</returns>
[HttpGet("TemplateList")]
public ActionResult GetTemplateList()
public async Task<IActionResult> GetTemplateList()
{
if (!serverState.IsOpen)
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
return Ok(ApiOkResponse.Response(PickListFactory.GetListOfAllPickListKeyNames(), true));
//Instantiate the business object handler
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
var o = await biz.GetListOfAllPickListKeyNames();
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(ApiOkResponse.Response(o, true));
}
@@ -100,7 +109,7 @@ TODO: need a db schema table and objects to hold the picklist templates
/// <summary>
/// POST (replace) Pick List template
/// </summary>
/// <param name="aytype"></param>
/// <param name="ayaType"></param>
/// <param name="template"></param>
/// <returns></returns>
[HttpPost("Template/{ayatype}")]
@@ -132,7 +141,7 @@ TODO: need a db schema table and objects to hold the picklist templates
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
}
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
return NoContent();
}
@@ -140,10 +149,10 @@ TODO: need a db schema table and objects to hold the picklist templates
/// Delete customized template
/// (revert to default)
/// </summary>
/// <param name="ayatype"></param>
/// <param name="ayaType"></param>
/// <returns>Ok</returns>
[HttpDelete("Template/{ayatype}")]
public async Task<IActionResult> DeletePickListTemplate([FromRoute] AyaType ayatype)
public async Task<IActionResult> DeletePickListTemplate([FromRoute] AyaType ayaType)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
@@ -154,11 +163,11 @@ TODO: need a db schema table and objects to hold the picklist templates
//Instantiate the business object handler
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!await biz.DeleteAsync(o))
if (!await biz.DeleteAsync(ayaType))
return BadRequest(new ApiErrorResponse(biz.Errors));
return NoContent();