This commit is contained in:
2020-10-23 18:59:51 +00:00
parent 4bfa45f92c
commit 5f440184ce
9 changed files with 46 additions and 24 deletions

View File

@@ -79,38 +79,45 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Bulk add tags to list of object id's specified
/// </summary>
/// <param name="ayaType"></param>
/// </summary>
/// <param name="tag"></param>
/// <param name="idList"></param>
/// <param name="dataListSelection"></param>
/// <returns>Job Id</returns>
[HttpPost("bulk-add/{ayaType}/{tag}")]
public async Task<IActionResult> BulkAdd([FromRoute] AyaType ayaType, [FromRoute] string tag, [FromBody] List<long> idList)
[HttpPost("bulk-add/{tag}")]
public async Task<IActionResult> BulkAdd([FromRoute] string tag, [FromBody] DataListSelection dataListSelection)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (!ayaType.HasAttribute(typeof(CoreBizObjectAttribute)))
if (dataListSelection.IsEmpty)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "DataListSelection is required"));
if (!dataListSelection.ObjectType.HasAttribute(typeof(CoreBizObjectAttribute)))
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Not a taggable object type"));
if (!Authorized.HasModifyRole(HttpContext.Items, ayaType))
if (!Authorized.HasModifyRole(HttpContext.Items, dataListSelection.ObjectType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (idList.Count == 0)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "List of ids are required"));
tag = TagBiz.NormalizeTag(tag);
if (string.IsNullOrWhiteSpace(tag))
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "tag required"));
await dataListSelection.RehydrateIdList(ct, UserRolesFromContext.Roles(HttpContext.Items), log);
if (dataListSelection.SelectedRowIds.Length == 0)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "List of ids"));
var JobName = $"Bulk operation: Add tag \"{tag}\" on {ayaType} ({idList.Count} specified)";
var JobName = $"Bulk operation: Add tag \"{tag}\" on {dataListSelection.ObjectType} ({dataListSelection.SelectedRowIds.LongLength} specified)";
JObject o = JObject.FromObject(new
{
idList = idList,
idList = dataListSelection.SelectedRowIds,
tag = tag
});
OpsJob j = new OpsJob();
j.Name = JobName;
j.ObjectType = ayaType;
j.ObjectType = dataListSelection.ObjectType;
j.JobType = JobType.BulkCoreBizObjectOperation;
j.SubType = JobSubType.TagAdd;
j.Exclusive = false;