This commit is contained in:
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
@@ -265,121 +264,121 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
#region WorkOrder Item
|
#region WorkOrder Item
|
||||||
//TODO: Plot exact routes needed here, not all are needed, particularly the collection ones
|
//TODO: Plot exact routes needed here, not all are needed, particularly the collection ones
|
||||||
//but maybe handy? Like do I need delete on entire woitems collection?
|
//but maybe handy? Like do I need delete on entire woitems collection?
|
||||||
//WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
|
//WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
|
||||||
//WorkOrder/{woid}/WorkOrderItems/{woitemid} <- CRUD single woitemid
|
//WorkOrder/{woid}/WorkOrderItems/{woitemid} <- CRUD single woitemid
|
||||||
|
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// Get full WorkOrder object
|
// /// Get full WorkOrder object
|
||||||
// /// </summary>
|
// /// </summary>
|
||||||
// /// <param name="id"></param>
|
// /// <param name="id"></param>
|
||||||
// /// <returns>A single WorkOrder</returns>
|
// /// <returns>A single WorkOrder</returns>
|
||||||
// [HttpGet("{id}")]
|
// [HttpGet("{id}")]
|
||||||
// public async Task<IActionResult> GetWorkOrder([FromRoute] long id)
|
// public async Task<IActionResult> GetWorkOrder([FromRoute] long id)
|
||||||
// {
|
// {
|
||||||
// if (!serverState.IsOpen)
|
// if (!serverState.IsOpen)
|
||||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
// //Instantiate the business object handler
|
// //Instantiate the business object handler
|
||||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
// WorkOrderBiz biz = WorkOrderBiz.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
|
// //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))
|
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
// 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(id);
|
||||||
// if (o == null)
|
// if (o == null)
|
||||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
// // NOTE: HERE would be the second check of biz rules before returning the object
|
// // NOTE: HERE would be the second check of biz rules before returning the object
|
||||||
// // in cases where there is also a business rule to affect retrieval on top of basic rights
|
// // in cases where there is also a business rule to affect retrieval on top of basic rights
|
||||||
|
|
||||||
// return Ok(ApiOkResponse.Response(o, !Authorized.HasModifyRole(HttpContext.Items, biz.BizType)));
|
// return Ok(ApiOkResponse.Response(o, !Authorized.HasModifyRole(HttpContext.Items, biz.BizType)));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //TODO: GET BY RELATIVE
|
// //TODO: GET BY RELATIVE
|
||||||
// //get by descendent type and id
|
// //get by descendent type and id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// Put (update) WorkOrder
|
// /// Put (update) WorkOrder
|
||||||
// /// </summary>
|
// /// </summary>
|
||||||
// /// <param name="id"></param>
|
// /// <param name="id"></param>
|
||||||
// /// <param name="inObj"></param>
|
// /// <param name="inObj"></param>
|
||||||
// /// <returns></returns>
|
// /// <returns></returns>
|
||||||
// [HttpPut("{id}")]
|
// [HttpPut("{id}")]
|
||||||
// public async Task<IActionResult> PutWorkOrder([FromRoute] long id, [FromBody] WorkOrder inObj)
|
// public async Task<IActionResult> PutWorkOrder([FromRoute] long id, [FromBody] WorkOrder inObj)
|
||||||
// {
|
// {
|
||||||
// if (!serverState.IsOpen)
|
// if (!serverState.IsOpen)
|
||||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
// if (!ModelState.IsValid)
|
// if (!ModelState.IsValid)
|
||||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
// //Instantiate the business object handler
|
// //Instantiate the business object handler
|
||||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
// var o = await biz.GetAsync(id, false);
|
// var o = await biz.GetAsync(id, false);
|
||||||
// if (o == null)
|
// if (o == null)
|
||||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
// if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
// try
|
// try
|
||||||
// {
|
// {
|
||||||
// if (!await biz.PutAsync(o, inObj))
|
// if (!await biz.PutAsync(o, inObj))
|
||||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
// }
|
// }
|
||||||
// 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
|
||||||
// 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>
|
// /// <summary>
|
||||||
// /// Post Workorder
|
// /// Post Workorder
|
||||||
// /// </summary>
|
// /// </summary>
|
||||||
// /// <param name="inObj"></param>
|
// /// <param name="inObj"></param>
|
||||||
// /// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
// /// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
// /// <returns></returns>
|
// /// <returns></returns>
|
||||||
// [HttpPost]
|
// [HttpPost]
|
||||||
// public async Task<IActionResult> PostWorkOrder([FromBody] WorkOrder inObj, ApiVersion apiVersion)
|
// public async Task<IActionResult> PostWorkOrder([FromBody] WorkOrder inObj, ApiVersion apiVersion)
|
||||||
// {
|
// {
|
||||||
// if (!serverState.IsOpen)
|
// if (!serverState.IsOpen)
|
||||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
// //Instantiate the business object handler
|
// //Instantiate the business object handler
|
||||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
// //If a user has change roles
|
// //If a user has change roles
|
||||||
// if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
||||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
// if (!ModelState.IsValid)
|
// if (!ModelState.IsValid)
|
||||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
// //Create and validate
|
// //Create and validate
|
||||||
// WorkOrder o = await biz.CreateAsync(inObj);
|
// WorkOrder o = await biz.CreateAsync(inObj);
|
||||||
// if (o == null)
|
// if (o == null)
|
||||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
// else
|
// else
|
||||||
// return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
// return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -412,14 +411,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
//stubbed out for now just to see routes
|
//stubbed out for now just to see routes
|
||||||
// if (!await biz.DeleteItemsAsync(o))
|
// if (!await biz.DeleteItemsAsync(o))
|
||||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete WorkOrderItems
|
/// Delete WorkOrderItems
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="workOrderId"></param>
|
/// <param name="workOrderId"></param>
|
||||||
@@ -439,17 +438,19 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
var o = await biz.GetAsync(workOrderId, false);
|
var o = await biz.GetAsync(workOrderId, false);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
//Make sure the item exists first before getting into it
|
||||||
|
if (!o.WorkorderItems.Exists(m => m.Id == workOrderItemId))
|
||||||
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//stubbed out for now just to see routes
|
||||||
//stubbed out for now just to see routes
|
|
||||||
// if (!await biz.DeleteItemsAsync(o))
|
// if (!await biz.DeleteItemsAsync(o))
|
||||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user