diff --git a/devdocs/todo.txt b/devdocs/todo.txt
index 406b2128..2860a8fa 100644
--- a/devdocs/todo.txt
+++ b/devdocs/todo.txt
@@ -15,6 +15,9 @@ todo: check attachment NOTES property is actually supported
todo: search tables in schema, I think there is a missing index here, need to look at the search query section again as it was changed several times from the original schema creation
+todo: all api route URI's sb lower case with dashes if necessary (use plural noun scheme)
+ https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design#organize-the-api-around-resources
+
todo: Routes should check rights *BEFORE* they fetch the object, not after, all routes affected
i.e. delete route instantiates biz object, then it fetchs object from db *then* it checks if they have rights to delete (generically, not specific to that object)
This is out of order as it triggers a db call even if they have no rights to do it
diff --git a/server/AyaNova/Controllers/WorkOrderController.cs b/server/AyaNova/Controllers/WorkOrderController.cs
index ac3496d6..a20f720f 100644
--- a/server/AyaNova/Controllers/WorkOrderController.cs
+++ b/server/AyaNova/Controllers/WorkOrderController.cs
@@ -1,3 +1,4 @@
+using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -15,7 +16,7 @@ namespace AyaNova.Api.Controllers
[ApiController]
[ApiVersion("8.0")]
- [Route("api/v{version:apiVersion}/[controller]")]
+ [Route("api/v{version:apiVersion}/workorders")]
[Produces("application/json")]
[Authorize]
public class WorkOrderController : ControllerBase
@@ -122,7 +123,7 @@ namespace AyaNova.Api.Controllers
///
- /// Post Workorder
+ /// Create Workorder
///
///
/// Automatically filled from route path, no need to specify in body
@@ -153,37 +154,6 @@ namespace AyaNova.Api.Controllers
}
- // ///
- // /// Post WorkOrder
- // ///
- // ///
- // ///
- // /// force a workorder number, leave null to autogenerate the next one in sequence (mostly used for import)
- // /// Automatically filled from route path, no need to specify in body
- // /// A created workorder ready to fill out
- // [HttpPost("Create")]
- // public async Task PostWorkOrder([FromQuery] long? workorderTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
- // {
- // if (!serverState.IsOpen)
- // return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
-
- // //Instantiate the business object handler
- // WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
-
- // //If a user has change roles
- // if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
- // return StatusCode(403, new ApiNotAuthorizedResponse());
-
- // if (!ModelState.IsValid)
- // return BadRequest(new ApiErrorResponse(ModelState));
-
- // //Create and validate
- // WorkOrder o = await biz.CreateAsync(workorderTemplateId,customerId, serial);
- // if (o == null)
- // return BadRequest(new ApiErrorResponse(biz.Errors));
- // else
- // return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
- // }
//TODO: CreateFromTemplate(templateid)
//TODO: Createfromquote(quoteid)
@@ -267,6 +237,16 @@ namespace AyaNova.Api.Controllers
//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/{woitemid} <- CRUD single woitemid
+//https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design#define-operations-in-terms-of-http-methods
+/*
+Resource POST GET PUT DELETE
+/customers Create a new customer Retrieve all customers Bulk update of customers Remove all customers
+/customers/1 Error Retrieve the details for customer 1 Update the details of customer 1 if it exists Remove customer 1
+/customers/1/orders Create a new order for customer 1 Retrieve all orders for customer 1 Bulk update of orders for customer 1 Remove all orders for customer 1
+*/
+
+//So Post into a collection means create one item in that collection, never a whole collection being created at once
+//GET PUT and DELETE on a collecdtion always mean the entire collection, POST is the outlier here
// ///
@@ -383,52 +363,21 @@ namespace AyaNova.Api.Controllers
+ //TODO: I can see adding or updating a collection of workorderitems but not deleting an entire collection
+
///
- /// Delete WorkOrderItems
- ///
- ///
- /// Ok
- [HttpDelete("{WorkOrderId}/WorkorderItems/")]
- public async Task DeleteWorkOrderItems([FromRoute] long workOrderId)
- {
- ////WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
- ///WorkOrder/{WorkOrderId}/WorkorderItems
- if (!serverState.IsOpen)
- return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
-
- if (!ModelState.IsValid)
- return BadRequest(new ApiErrorResponse(ModelState));
-
- //Instantiate the business object handler
- WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
-
- var o = await biz.GetAsync(workOrderId, false);
- if (o == null)
- return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
-
- if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
- return StatusCode(403, new ApiNotAuthorizedResponse());
-
- //stubbed out for now just to see routes
- // if (!await biz.DeleteItemsAsync(o))
- // return BadRequest(new ApiErrorResponse(biz.Errors));
-
- return NoContent();
- }
-
- ///
- /// Delete WorkOrderItems
+ /// Delete WorkOrderItem
///
///
///
- /// Ok
- [HttpDelete("{WorkOrderId}/WorkorderItems/{WorkOrderItemId}")]
+ /// Ok-no content
+ [HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}")]
public async Task DeleteWorkOrderItem([FromRoute] long workOrderId, [FromRoute] long workOrderItemId)
{
- ////WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
- ///WorkOrder/{WorkOrderId}/WorkorderItems
+ //WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
+ //WorkOrder/{WorkOrderId}/WorkorderItems
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -464,11 +413,94 @@ namespace AyaNova.Api.Controllers
#region WorkOrderItemLabor
+
+ ///
+ /// Delete WorkOrderItemLabor
+ ///
+ ///
+ ///
+ ///
+ /// Ok-no content
+ [HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}/labors/{WorkOrderItemLaborId}")]
+ public async Task DeleteWorkOrderItemLabor([FromRoute] long workOrderId, [FromRoute] long workOrderItemId, [FromRoute] long workOrderItemLaborId)
+ {
+ if (!serverState.IsOpen)
+ return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
+
+ if (!ModelState.IsValid)
+ return BadRequest(new ApiErrorResponse(ModelState));
+
+ //Instantiate the business object handler
+ WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
+
+ if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
+ return StatusCode(403, new ApiNotAuthorizedResponse());
+
+ var o = await biz.GetAsync(workOrderId, false);
+ if (o == null)
+ return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
+
+ //Get WorkorderItem
+ var woitem = o.WorkorderItems.FirstOrDefault(m => m.Id == workOrderItemId);
+ if (woitem == null)
+ return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
+
+ //Get WorkOrderItemLabor
+ var woitemlabor = woitem.WorkorderItemLabors.FirstOrDefault(m => m.Id == workOrderItemLaborId);
+ if (woitem == null)
+ return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
+
+
+
+
+ //stubbed out for now just to see routes
+ // if (!await biz.DeleteWorkOrderItemLaborAsync(woitemlabor))//may need more info, not sure
+ // return BadRequest(new ApiErrorResponse(biz.Errors));
+
+ return NoContent();
+ }
#endregion WorkOrderItemLabor
#region WorkOrderItemPart
+ ///
+ /// Delete WorkOrderItemPart
+ ///
+ ///
+ ///
+ ///
+ /// Ok-no content
+ [HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}/parts/{WorkOrderItemPartId}")]
+ public async Task DeleteWorkOrderItemPart([FromRoute] long workOrderId, [FromRoute] long workOrderItemId, [FromRoute] long workOrderItemPartId)
+ {
+ if (!serverState.IsOpen)
+ return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
+
+ if (!ModelState.IsValid)
+ return BadRequest(new ApiErrorResponse(ModelState));
+
+ //Instantiate the business object handler
+ WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
+
+ if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
+ return StatusCode(403, new ApiNotAuthorizedResponse());
+
+ var o = await biz.GetAsync(workOrderId, false);
+ if (o == null)
+ 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
+ // if (!await biz.DeleteItemsAsync(o))
+ // return BadRequest(new ApiErrorResponse(biz.Errors));
+
+ return NoContent();
+ }
#endregion WorkOrderItemPart
//------------