From 6a2b5bdea2aeb1ce924227ac593233840530218e Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 22 Jan 2020 15:20:03 +0000 Subject: [PATCH] --- .../Controllers/DataListTemplateController.cs | 104 +++++------------- 1 file changed, 30 insertions(+), 74 deletions(-) diff --git a/server/AyaNova/Controllers/DataListTemplateController.cs b/server/AyaNova/Controllers/DataListTemplateController.cs index 21c796df..6e988ce7 100644 --- a/server/AyaNova/Controllers/DataListTemplateController.cs +++ b/server/AyaNova/Controllers/DataListTemplateController.cs @@ -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 { - /// - /// - /// [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 /// - /// + /// /// A single DataListTemplate - [HttpGet("{id}")] - public async Task GetDataListTemplate([FromRoute] long id) + [HttpGet("{DataListKey}")] + public async Task 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 } - /// - /// Get DataListTemplate pick list + /// List of all DataList keys available /// /// Required roles: Any - /// - /// - /// List of public or owned data filters for listKey provided - [HttpGet("PickList", Name = nameof(DataListTemplatePickList))] - public async Task DataListTemplatePickList([FromQuery] string ListKey) + /// + /// List of strings + [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 /// /// - /// + /// /// /// - [HttpPut("{id}")] - public async Task PutDataListTemplate([FromRoute] long id, [FromBody] DataListTemplate inObj) + [HttpPut("{DataListKey}")] + public async Task 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)); } - /// - /// Post DataListTemplate - /// - /// Required roles: - /// BizAdminFull, InventoryFull, TechFull - /// - /// - /// Automatically filled from route path, no need to specify in body - /// - [HttpPost] - public async Task 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)); - - } - - /// /// Delete DataListTemplate - /// + /// (Reset DataListTemplate to default) /// Required roles: - /// Any if public otherwise creator only + /// BizAdminFull /// /// - /// + /// /// Ok - [HttpDelete("{id}")] - public async Task DeleteDataListTemplate([FromRoute] long id) + [HttpDelete("{DataListKey}")] + public async Task 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));