This commit is contained in:
2022-06-23 20:35:37 +00:00
parent eee19ffc61
commit 96f47de2e5
2 changed files with 65 additions and 0 deletions

View File

@@ -197,6 +197,45 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Create Integration log entry
/// </summary>
/// <param name="logItem">id=Integration internal Id (not IntegrationAppId value), name = status text to log</param>
/// <param name="apiVersion">From route path</param>
/// <returns>NoContent if ok otherwise BadRequest and an error object</returns>
[HttpPost("log")]
public async Task<IActionResult> 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();
}
/// <summary>
/// Get Integration log for id of integration specified
/// </summary>
/// <returns>All log entries available for integration id</returns>
[HttpGet("log/{id}")]
public async Task<IActionResult> 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)));
}

View File

@@ -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<bool> 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<List<IntegrationLog>> GetLogAsync(long id)
{
return await ct.IntegrationLog.AsNoTracking().Where(z=>z.IntegrationId==id).OrderByDescending(z=>z.Created).ToListAsync();
}
////////////////////////////////////////////////////////////////////////////////////////////////