This commit is contained in:
@@ -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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using AyaNova.Util;
|
|||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user