Adding
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog;
|
||||
using LCU.Api.Internal.FTP.Extensions;
|
||||
using LCU.Api.Internal.FTP.Helpers;
|
||||
using LCU.Api.Internal.FTP.Services;
|
||||
using LCU.Api.Internal.FTPLib.Models;
|
||||
using LCU.Api.Internal.FTP.Services.FtpOpertionServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
namespace LCU.Api.Internal.FTP.Controllers;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class SftpController : ControllerBase
|
||||
{
|
||||
private readonly IQueueFtpService _queueFtpService;
|
||||
private readonly IWinScpListDirectoryService _winScpSftpListDirectoryService;
|
||||
|
||||
public SftpController(IQueueFtpService queueFtpService,
|
||||
IWinScpListDirectoryService winScpSftpListDirectoryService)
|
||||
{
|
||||
_queueFtpService = queueFtpService;
|
||||
_winScpSftpListDirectoryService = winScpSftpListDirectoryService;
|
||||
}
|
||||
|
||||
[Obsolete("01/04/2022 - Please use QueueSftpUploadRequest Endpoint for Sftp Request and SshFtpController QueueSshFtpRequest Endpoint")]
|
||||
[HttpPost]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult Post([FromBody] SftpRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
if (!WinScpSessionOptionValidators.IsValidSessionOptions(request))
|
||||
{
|
||||
Log.Error("Sftp request can not be created into a valid session options.");
|
||||
return BadRequest("Sftp request can not be created into a valid session options.");
|
||||
}
|
||||
|
||||
|
||||
_queueFtpService.QueueSftp(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("01/04/2022 - Please use QueueSftpUploadRequest Endpoint")]
|
||||
[HttpPost("QueueSftpDynamicFileRequest")]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult QueueSftpDynamicFileRequest([FromBody] SftpDynamicFileRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
if (!WinScpSessionOptionValidators.IsValidSessionOptions(request))
|
||||
{
|
||||
return BadRequest("Sftp request can not be created into a valid session options.");
|
||||
}
|
||||
|
||||
_queueFtpService.QueueSftpDynamicFileRequest(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueSftpUploadRequest")]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult QueueSftpUploadRequest([FromBody] SftpUploadFileRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
_queueFtpService.QueueSftpUploadRequest(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("QueueSftpDownloadRequest")]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult QueueSftpDownloadRequest([FromBody] SftpDownloadFileRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
_queueFtpService.QueueSftpDownloadRequest(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("ListFilesInDirectory")]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult ListFilesInDirectory([FromQuery] ListDirectoryRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
var result = _winScpSftpListDirectoryService.GetListOfFilesInDirectory(request);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Serilog;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LCU.Api.Internal.FTP.Extensions;
|
||||
using LCU.Api.Internal.FTP.Services;
|
||||
using LCU.Api.Internal.FTPLib.Models;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
namespace LCU.Api.Internal.FTP.Controllers;
|
||||
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class SshFtpController : ControllerBase
|
||||
{
|
||||
private readonly IQueueSshFtpService _queueSshFtpService;
|
||||
|
||||
public SshFtpController(IQueueSshFtpService queueSshFtpService)
|
||||
{
|
||||
_queueSshFtpService = queueSshFtpService;
|
||||
}
|
||||
|
||||
[HttpPost("QueueSshFtpRequest")]
|
||||
[ProducesResponseType(201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult QueueSshFtpRequest([FromBody] SshFtpRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
_queueSshFtpService.QueueSshFtpRequest(request);
|
||||
return Ok();
|
||||
}
|
||||
catch (ServiceException)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Unexpected Exception");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using LCU.Api.Internal.FTP.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.Api.Internal.FTP.Controllers;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class StatusController : ControllerBase
|
||||
{
|
||||
private readonly IEnvironmentView _environmentView;
|
||||
|
||||
public StatusController(IEnvironmentView environmentView)
|
||||
{
|
||||
_environmentView = environmentView;
|
||||
}
|
||||
|
||||
[HttpGet()]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(500)]
|
||||
public IActionResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(_environmentView);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Failure to return status");
|
||||
return StatusCode((int)System.Net.HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user