This commit is contained in:
@@ -47,10 +47,10 @@ namespace AyaNova.Api.Controllers
|
||||
/// Export to file
|
||||
/// </summary>
|
||||
/// <param name="format">Valid values are: "csv","json"</param>
|
||||
/// <param name="dataListSelection"></param>
|
||||
/// <param name="selectedRequest"></param>
|
||||
/// <returns>downloadable export file name</returns>
|
||||
[HttpPost("render/{format}")]
|
||||
public async Task<IActionResult> RenderExport([FromRoute] string format, [FromBody] DataListSelectedProcessingOptions dataListSelection)
|
||||
public async Task<IActionResult> RenderExport([FromRoute] string format, [FromBody] DataListSelectedRequest selectedRequest)
|
||||
{
|
||||
|
||||
if (!serverState.IsOpen)
|
||||
@@ -58,10 +58,10 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
if (dataListSelection.IsEmpty)
|
||||
if (selectedRequest.IsEmpty)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "DataListSelection is required"));
|
||||
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, dataListSelection.ObjectType))
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, selectedRequest.ObjectType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (string.IsNullOrWhiteSpace(format))
|
||||
@@ -70,17 +70,17 @@ namespace AyaNova.Api.Controllers
|
||||
if (format != "csv" && format != "json")
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "format not valid, must be 'csv' or 'json'"));
|
||||
|
||||
await dataListSelection.RehydrateIdList(ct, UserRolesFromContext.Roles(HttpContext.Items), log, UserIdFromContext.Id(HttpContext.Items));
|
||||
if (dataListSelection.SelectedRowIds.Length == 0)
|
||||
await selectedRequest.RehydrateIdList(ct, UserRolesFromContext.Roles(HttpContext.Items), log, UserIdFromContext.Id(HttpContext.Items));
|
||||
if (selectedRequest.SelectedRowIds.Length == 0)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "List of ids"));
|
||||
|
||||
|
||||
log.LogDebug($"Instantiating biz object handler for {dataListSelection.ObjectType}");
|
||||
var biz = BizObjectFactory.GetBizObject(dataListSelection.ObjectType, ct);
|
||||
log.LogDebug($"Fetching data for {dataListSelection.SelectedRowIds.Length} {dataListSelection.ObjectType} items");
|
||||
log.LogDebug($"Instantiating biz object handler for {selectedRequest.ObjectType}");
|
||||
var biz = BizObjectFactory.GetBizObject(selectedRequest.ObjectType, ct);
|
||||
log.LogDebug($"Fetching data for {selectedRequest.SelectedRowIds.Length} {selectedRequest.ObjectType} items");
|
||||
// var TheData = await ((IExportAbleObject)biz).GetJSONExportData(dataListSelection.SelectedRowIds);
|
||||
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{dataListSelection.ObjectType.ToString().ToLowerInvariant()}-{format}-{FileUtil.GetSafeDateFileName()}");
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{selectedRequest.ObjectType.ToString().ToLowerInvariant()}-{format}-{FileUtil.GetSafeDateFileName()}");
|
||||
|
||||
// string outputRandomFileNameNoExtension = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "");
|
||||
string outputSourceFileName = baseFileName + "." + format;
|
||||
@@ -93,7 +93,7 @@ namespace AyaNova.Api.Controllers
|
||||
case "csv":
|
||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest.SelectedRowIds);
|
||||
w.Write(ToDynamicList(dat));
|
||||
}
|
||||
break;
|
||||
@@ -101,7 +101,7 @@ namespace AyaNova.Api.Controllers
|
||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest.SelectedRowIds);
|
||||
dat.WriteTo(writer);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user