This commit is contained in:
2019-06-10 20:12:49 +00:00
parent 728b5abab6
commit 1e18f5a11d
4 changed files with 76 additions and 13 deletions

View File

@@ -16,6 +16,10 @@ REALLY MAKING MORE PROGRESS WHEN CLIENT DEV DRIVES BACKEND DEV, STICK TO THAT!!
DO CLIENT STUFF NOW COME BACK TO THIS STUFF LATER
###*** BEFORE NEXT UPDATE TO DEVOPS SERVER:::::::
TODO: Widget controller is doing a lot of database work in routes before calling biz, I'm concerned about separation of concerns here
- Controller shouldn't have to know about database or is this realistic with the design?
- Can I just move all DB related code out of widget or is this a nightmare at this point?
TODO: NEEDS A THINK, SOME CHANGES REQUIRE DB ERASURE BEFORE STARTUP
- Make it fucking easier to test deploy and erase db and fetch key and all that shit
- I would like to deploy, bring it up and then from a simple command from the api explorer trigger all the above

View File

@@ -327,7 +327,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
UserBiz biz = UserBiz.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 a user has change roles
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
{
return StatusCode(403, new ApiNotAuthorizedResponse());

View File

@@ -51,7 +51,7 @@ namespace AyaNova.Api.Controllers
/// Get full widget object
///
/// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
/// </summary>
/// <param name="id"></param>
/// <returns>A single widget</returns>
@@ -86,7 +86,7 @@ namespace AyaNova.Api.Controllers
/// Get filter and sort options
///
/// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
///
/// </summary>
/// <returns>Filter options</returns>
@@ -113,7 +113,7 @@ namespace AyaNova.Api.Controllers
/// Get paged list of widgets
///
/// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
/// </summary>
/// <returns>Paged collection of widgets with paging data</returns>
[HttpGet("ListWidgets", Name = nameof(ListWidgets))]//We MUST have a "Name" defined or we can't get the link for the pagination, non paged urls don't need a name
@@ -167,7 +167,6 @@ namespace AyaNova.Api.Controllers
///
/// Required roles:
/// BizAdminFull, InventoryFull
/// TechFull (owned only)
///
/// </summary>
/// <param name="id"></param>
@@ -214,7 +213,7 @@ namespace AyaNova.Api.Controllers
///
/// Required roles:
/// BizAdminFull, InventoryFull
/// TechFull (owned only)
///
/// </summary>
/// <param name="id"></param>
/// <param name="concurrencyToken"></param>
@@ -262,7 +261,7 @@ namespace AyaNova.Api.Controllers
/// Post widget
///
/// Required roles:
/// BizAdminFull, InventoryFull, TechFull
/// BizAdminFull, InventoryFull
/// </summary>
/// <param name="inObj"></param>
/// <returns></returns>
@@ -275,7 +274,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
WidgetBiz biz = WidgetBiz.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 a user has change roles
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
@@ -291,6 +290,43 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Duplicate widget
///
/// Required roles:
/// BizAdminFull, InventoryFull
/// </summary>
/// <param name="id">Create a duplicate of this item id</param>
/// <returns></returns>
[HttpPost("duplicate/{id}")]
public async Task<IActionResult> DuplicateWidget([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//Instantiate the business object handler
WidgetBiz biz = WidgetBiz.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));
var oSrc = await biz.GetNoLogAsync(id);
if (oSrc == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Create and validate
Widget o = await biz.DuplicateAsync(oSrc);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
}
/// <summary>
@@ -298,7 +334,7 @@ namespace AyaNova.Api.Controllers
///
/// Required roles:
/// BizAdminFull, InventoryFull
/// TechFull (owned only)
///
///
/// </summary>
/// <param name="id"></param>

View File

@@ -85,7 +85,7 @@ namespace AyaNova.Biz
{
//do stuff with widget
Widget outObj = inObj;
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
@@ -113,7 +113,7 @@ namespace AyaNova.Biz
{
//do stuff with widget
Widget outObj = inObj;
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
@@ -131,6 +131,29 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE
//
internal async Task<Widget> DuplicateAsync(Widget dbObj)
{
Widget outObj = new Widget();
CopyObject.Copy(dbObj, outObj);
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
await ct.Widget.AddAsync(outObj);
await ct.SaveChangesAsync();
//Handle child and associated items:
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
SearchIndex(outObj, true);
TagUtil.ProcessUpdateTagsInRepository(ct, outObj.Tags, null);
return outObj;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE
@@ -139,7 +162,7 @@ namespace AyaNova.Biz
//put
internal bool Put(Widget dbObj, Widget inObj)
{
//make a snapshot of the original for validation but update the original to preserve workflow
Widget SnapshotOfOriginalDBObj = new Widget();
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
@@ -351,7 +374,7 @@ namespace AyaNova.Biz
// // }
// }
//Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");