From 96f47de2e5a1e35fed9f55c5db9570ddd37b833b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 23 Jun 2022 20:35:37 +0000 Subject: [PATCH] --- .../Controllers/IntegrationController.cs | 39 +++++++++++++++++++ server/AyaNova/biz/IntegrationBiz.cs | 26 +++++++++++++ 2 files changed, 65 insertions(+) diff --git a/server/AyaNova/Controllers/IntegrationController.cs b/server/AyaNova/Controllers/IntegrationController.cs index 5178dbb9..6d2e441e 100644 --- a/server/AyaNova/Controllers/IntegrationController.cs +++ b/server/AyaNova/Controllers/IntegrationController.cs @@ -197,6 +197,45 @@ namespace AyaNova.Api.Controllers } + /// + /// Create Integration log entry + /// + /// id=Integration internal Id (not IntegrationAppId value), name = status text to log + /// From route path + /// NoContent if ok otherwise BadRequest and an error object + [HttpPost("log")] + public async Task PostIntegrationLog([FromBody] NameIdItem logItem, ApiVersion apiVersion) + { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + IntegrationBiz biz = IntegrationBiz.GetBiz(ct, HttpContext); + if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + bool bResult = await biz.LogAsync(logItem); + if (bResult == false) + return BadRequest(new ApiErrorResponse(biz.Errors)); + else + return NoContent(); + } + + /// + /// Get Integration log for id of integration specified + /// + /// All log entries available for integration id + [HttpGet("log/{id}")] + public async Task GetAllLogs([FromRoute] long id) + { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + IntegrationBiz biz = IntegrationBiz.GetBiz(ct, HttpContext); + if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + return Ok(ApiOkResponse.Response(await biz.GetLogAsync(id))); + } diff --git a/server/AyaNova/biz/IntegrationBiz.cs b/server/AyaNova/biz/IntegrationBiz.cs index 91107f24..a8aef7c1 100644 --- a/server/AyaNova/biz/IntegrationBiz.cs +++ b/server/AyaNova/biz/IntegrationBiz.cs @@ -5,6 +5,7 @@ using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Models; using System.Linq; +using System.Collections.Generic; namespace AyaNova.Biz { @@ -168,7 +169,32 @@ namespace AyaNova.Biz } + ///////////////////////////////////////////////////////////////////////////////// + //LOG to integration log + // + internal async Task LogAsync(NameIdItem logItem) + { + if (string.IsNullOrWhiteSpace(logItem.Name)) + { + AddError(ApiErrorCode.NOT_FOUND, "name", "The log text message (name) is empty, nothing to log"); + return false; + } + if (!await ExistsAsync(logItem.Id)) + { + AddError(ApiErrorCode.NOT_FOUND, "id", "The integration id specified was not found, remember this is the internal id (integer), not the application specific id (Guid)"); + return false; + } + await ct.IntegrationLog.AddAsync(new IntegrationLog { IntegrationId = logItem.Id, StatusText = logItem.Name }); + await ct.SaveChangesAsync(); + return true; + } + + //GET LOG + internal async Task> GetLogAsync(long id) + { + return await ct.IntegrationLog.AsNoTracking().Where(z=>z.IntegrationId==id).OrderByDescending(z=>z.Created).ToListAsync(); + } ////////////////////////////////////////////////////////////////////////////////////////////////