Updating
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Api.Internal.FileOperations.Services.ExcelServices;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.ExcelModels.Requests;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.ExcelModels.Responses;
|
||||
using LCU.Api.Internal.FileOperations.Extensions;
|
||||
namespace LCU.Api.Internal.FileOperations.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ExcelController : ControllerBase
|
||||
{
|
||||
private readonly IExcelService _excelService;
|
||||
|
||||
public ExcelController(IExcelService excelService)
|
||||
{
|
||||
_excelService = excelService;
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// This endpoint is a direct file operations call to extract excel workbook data. The ExcelDataRequest contains
|
||||
/// the file content in a base64 encoded string for an excel sheet and it will extract all data into a json object.
|
||||
/// The request also has optional SheetRequests in which a SheetName and specific Rows and Columns can be selected.
|
||||
///
|
||||
/// Notes:
|
||||
/// - FileContent is required.
|
||||
/// - SheetRequests are optional.
|
||||
/// - If SheetRequests are added the SheetName is required.
|
||||
/// - The SheetRequest's Rows and Columns are optional.
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <returns>ExcelDataResponse</returns>
|
||||
[HttpPost("ExtractExcelWorkBookData")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(typeof(ExcelDataResponse), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult ExtractExcelWorkBookData([FromBody] ExcelDataRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
var requestResponse = _excelService.ExtractExcelWorkBookData(request);
|
||||
return Ok(requestResponse);
|
||||
}
|
||||
catch (ServiceException exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user