This commit is contained in:
2020-05-16 15:32:53 +00:00
parent 36cc5fd825
commit 6f0182042e
3 changed files with 31 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using Newtonsoft.Json.Linq;
namespace AyaNova.Api.Controllers
@@ -88,7 +90,30 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
if (!Authorized.HasModifyRole(HttpContext.Items, ayaType))
return StatusCode(403, new ApiNotAuthorizedResponse());
return Ok(ApiOkResponse.Response(await TagUtil.BulkAdd(ayaType, tag, idList, ct), true));
if (idList.Count == 0)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "List of ids"));
tag = TagUtil.NormalizeTag(tag);
if (string.IsNullOrWhiteSpace(tag))
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag"));
var JobName = $"BulkAdd tag {tag} to {ayaType} ({idList.Count} specified)";
JObject o = JObject.FromObject(new
{
ayaType = ayaType,
idList = idList,
op = "bulk-add",
tag = tag
});
OpsJob j = new OpsJob();
j.Name = $"BulkTag";
j.JobType = JobType.BulkTag;
j.Exclusive = false;
j.JobInfo = o.ToString();
// await JobsBiz.AddJobAsync(j, ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, ayaType, AyaEvent.Created, JobName), ct);
return Accepted(new { JobId = j.GId });
}
/// <summary>

View File

@@ -3,7 +3,7 @@ namespace AyaNova.Biz
/// <summary>
/// All AyaNova Job types, used by OpsJob and biz objects for long running applications
/// All AyaNova Job types, used by OpsJob and biz objects for long running processes
/// </summary>
public enum JobType : int
{
@@ -11,7 +11,7 @@ namespace AyaNova.Biz
TestWidgetJob = 1,//test job for unit testing
CoreJobSweeper = 2,
SeedTestData = 4,
BulkTag = 5
}

View File

@@ -212,11 +212,13 @@ namespace AyaNova.Biz
/////////////////////////////////
//BULK OPS
//BULK OPS JOBS
//
public static async Task<long> BulkAdd(AyaType ayaType, string tag, List<long> idList, AyContext ct)
{
//SUBMIT AS JOB
//todo iterate the object in question, open and update and save each one through it's biz object interface so rules etc are all maintained
//not sure if should update locked or read only objects, probably not I guess as it should only do whatever was done in interface
await Task.CompletedTask;