60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.Api.Internal.FileOperations.Extensions;
|
|
using LCU.Api.Internal.FileOperations.Services.FileActionServices;
|
|
using LCU.Library.Internal.ApiResponse.Models;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using LCU.Library.Internal.FileOperationsModels.Models;
|
|
using LCU.Library.Internal.FileOperationsModels.Models.Requests;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Serilog;
|
|
|
|
namespace LCU.Api.Internal.FileOperations.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class DirectFileInformationController : ControllerBase
|
|
{
|
|
private readonly IFileSizeService _fileSizeService;
|
|
|
|
public DirectFileInformationController(IFileSizeService fileSizeService)
|
|
{
|
|
_fileSizeService = fileSizeService;
|
|
}
|
|
|
|
[HttpPost("GetFileSize")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(typeof(List<string>), 400)]
|
|
[ProducesResponseType(500)]
|
|
public IActionResult GetFileSize([FromBody] FileSizeRequest request)
|
|
{
|
|
try
|
|
{
|
|
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState.GetErrorMessages());
|
|
}
|
|
|
|
var validateResponse = _fileSizeService.PreQueueValidation(request);
|
|
if (!validateResponse.IsSuccessful)
|
|
{
|
|
return BadRequest($"Request is invalid. Response: {string.Join("\n ", validateResponse.MessageStack.ToArray())}");
|
|
}
|
|
|
|
var response = _fileSizeService.GetFileSize(request);
|
|
return Ok(response);
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
} |