Skip to content

Commit

Permalink
feat: list file content base64 request (#33)
Browse files Browse the repository at this point in the history
* feat: list of fileContent in string base64 accepted

* refactor: impl using file new dir & update docs

* feat!: update Reference WCF to new update Gateway SOAP (file_rename)

* feat: added file rename

* refactor: add nullable location

* feat!: update to new WSDL Gateway-SOAP

* feat: file get added
  • Loading branch information
SantiagoGaonaC authored Oct 16, 2023
1 parent f755d51 commit 7b07e85
Show file tree
Hide file tree
Showing 12 changed files with 1,291 additions and 195 deletions.
2 changes: 1 addition & 1 deletion Controllers/Account/AccountPasswordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<IActionResult> Post([FromBody] reqAccPassword reqAccPassword)

return this.HandleResponseError<IResponse>(adapter);
}
return Ok(new { response.@return });
return Ok(new { response.@return.msg });
}
catch (Exception ex)
{
Expand Down
75 changes: 75 additions & 0 deletions Controllers/File/FileGetController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.AspNetCore.Mvc;
using proxy_net.Adapters;
using proxy_net.Handler;
using proxy_net.Models;
using proxy_net.Repositories.File;
using ServiceReference;

namespace proxy_net.Controllers.File
{
[ApiController]
[Route("file")]
public class FileGetControler : ControllerBase
{
private readonly ILogger<FileGetControler> _logger;
private readonly IFileRepository _fileRepository;

public FileGetControler(ILogger<FileGetControler> logger, IFileRepository fileRepository)
{
_logger = logger;
_fileRepository = fileRepository;
}

[HttpPost("get", Name = "File_Get")]
public async Task<IActionResult> Post([FromBody] reqFile request)
{
if (request == null || string.IsNullOrEmpty(request.token) || string.IsNullOrEmpty(request.fileUUID))
{
return BadRequest(new ResponseError
{
code = 400,
msg = "El cuerpo de la solicitud es nulo o incompleto",
error = true
});
}

var reqFile = new reqFile
{
fileUUID = request.fileUUID,
token = request.token
};

try
{
file_getResponse response = await _fileRepository.FileGetAsync(reqFile);
if (response?.@return == null)
{
return NotFound(new ResponseError
{
code = 404,
msg = "La respuesta del servicio SOAP es nula o inválida.",
error = true
});
}

if (response.@return.error)
{
var adapter = new ResponseAdapter(() => new ResponseError
{
code = response.@return.code,
msg = response.@return.msg,
error = response.@return.error
});

return this.HandleResponseError<IResponse>(adapter);
}
return Ok(new { response.@return.file, response.@return.msg });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error en la llamada SOAP.");
throw;
}
}
}
}
17 changes: 14 additions & 3 deletions Controllers/File/FileListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

namespace proxy_net.Controllers.File
{
public class FileListRequest
{
public string? Location { get; set; } = null;
public string Token { get; set; } = null!;
}

[ApiController]
[Route("file")]
public class FileListControler : ControllerBase
Expand All @@ -21,10 +27,9 @@ public FileListControler(ILogger<FileListControler> logger, IFileRepository file
}

[HttpPost("list", Name = "File_List")]
public async Task<IActionResult> Post([FromBody] reqFileList reqFileList)
public async Task<IActionResult> Post([FromBody] FileListRequest request)
{
if (reqFileList == null || string.IsNullOrEmpty(reqFileList.location)
|| string.IsNullOrEmpty(reqFileList.token))
if (request == null || string.IsNullOrEmpty(request.Token))
{
return BadRequest(new ResponseError
{
Expand All @@ -34,6 +39,12 @@ public async Task<IActionResult> Post([FromBody] reqFileList reqFileList)
});
}

var reqFileList = new reqFileList
{
location = request.Location,
token = request.Token
};

try
{
file_listResponse response = await _fileRepository.FileListAsync(reqFileList);
Expand Down
5 changes: 2 additions & 3 deletions Controllers/File/FileMoveController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public async Task<IActionResult> Pust([FromBody] reqFileMove reqFileMove)
{
if (reqFileMove == null || string.IsNullOrEmpty(reqFileMove.fileUUID)
|| string.IsNullOrEmpty(reqFileMove.token)
|| string.IsNullOrEmpty(reqFileMove.targetDirectoryUUID)
|| string.IsNullOrEmpty(reqFileMove.newName))
|| string.IsNullOrEmpty(reqFileMove.targetDirectoryUUID))
{
return BadRequest(new ResponseError
{
code = 400,
code = 400,
msg = "El cuerpo de la solicitud es nulo o incompleto",
error = true
});
Expand Down
21 changes: 18 additions & 3 deletions Controllers/File/FileNewDirectoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

namespace proxy_net.Controllers.File
{
public class ReqFileNewDir
{
public string DirectoryName { get; set; } = null!;
public string? Location { get; set; } = null;
public string? Token { get; set; } = null!;
}


[ApiController]
[Route("file")]
public class FileNewDirectoryController : ControllerBase
Expand All @@ -21,10 +29,9 @@ public FileNewDirectoryController(ILogger<FileNewDirectoryController> logger, IF
}

[HttpPost("new/directory", Name = "File_New_Directory")]
public async Task<IActionResult> Post([FromBody] reqFileNewDir reqFileNewDir)
public async Task<IActionResult> Post([FromBody] ReqFileNewDir request)
{
if (reqFileNewDir == null || string.IsNullOrEmpty(reqFileNewDir.directoryName) ||
string.IsNullOrEmpty(reqFileNewDir.location) || string.IsNullOrEmpty(reqFileNewDir.token))
if (request == null || string.IsNullOrEmpty(request.DirectoryName) || string.IsNullOrEmpty(request.Token))
{
return BadRequest(new ResponseError
{
Expand All @@ -34,6 +41,14 @@ public async Task<IActionResult> Post([FromBody] reqFileNewDir reqFileNewDir)
});
}

//Adapter
var reqFileNewDir = new reqFileNewDir
{
directoryName = request.DirectoryName,
location = request.Location,
token = request.Token
};

try
{
file_new_dirResponse response = await _fileRepository.FileNewDirAsync(reqFileNewDir);
Expand Down
71 changes: 71 additions & 0 deletions Controllers/File/FileRenameController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Mvc;
using proxy_net.Adapters;
using proxy_net.Handler;
using proxy_net.Models;
using proxy_net.Repositories.File;
using ServiceReference;

namespace proxy_net.Controllers.File
{
[ApiController]
[Route("file")]
public class FileRenameController : ControllerBase
{
private readonly ILogger<FileRenameController> _logger;
private readonly IFileRepository _fileRepository;

public FileRenameController(ILogger<FileRenameController> logger, IFileRepository fileRepository)
{
_logger = logger;
_fileRepository = fileRepository;
}

[HttpPost("rename", Name = "File_Rename")]
public async Task<IActionResult> Post([FromBody] reqFileRename reqFileRename)
{
if (reqFileRename == null || string.IsNullOrEmpty(reqFileRename.fileUUID)
|| string.IsNullOrEmpty(reqFileRename.newName)
|| string.IsNullOrEmpty(reqFileRename.token))
{
return BadRequest(new ResponseError
{
code = 400,
msg = "El cuerpo de la solicitud es nulo o incompleto",
error = true
});
}

try
{
file_renameResponse response = await _fileRepository.FileRenameAsync(reqFileRename);
if (response?.@return == null)
{
return NotFound(new ResponseError
{
code = 404,
msg = "La respuesta del servicio SOAP es nula o inválida.",
error = true
});
}

if (response.@return.error)
{
var adapter = new ResponseAdapter(() => new ResponseError
{
code = response.@return.code,
msg = response.@return.msg,
error = response.@return.error
});

return this.HandleResponseError<IResponse>(adapter);
}
return Ok(new { response.@return.msg });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error en la llamada SOAP.");
throw;
}
}
}
}
66 changes: 46 additions & 20 deletions Controllers/File/FileUploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

namespace proxy_net.Controllers.File
{
public class FileUploadRequest
{
public string FileName { get; set; } = null!;
public List<string> FileContent { get; set; } = null!;
public string? Location { get; set; } = null;
public string Token { get; set; } = null!;
}

[ApiController]
[Route("file")]
public class FileUploadController : ControllerBase
Expand All @@ -21,10 +29,12 @@ public FileUploadController(ILogger<FileUploadController> logger, IFileRepositor
}

[HttpPost("upload", Name = "File_Upload")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(file_uploadResponse))]
public async Task<IActionResult> Post([FromForm] string fileContentBase64, [FromForm] string fileName, [FromForm] string token)
public async Task<IActionResult> Post([FromBody] FileUploadRequest request)
{
if (string.IsNullOrEmpty(fileContentBase64) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(token))
if (string.IsNullOrEmpty(request.FileName) ||
string.IsNullOrEmpty(request.Token) ||
request.FileContent == null ||
!request.FileContent.Any())
{
return BadRequest(new ResponseError
{
Expand All @@ -34,15 +44,32 @@ public async Task<IActionResult> Post([FromForm] string fileContentBase64, [From
});
}

byte[] fileContent = Base64Converter.DecodeBase64(fileContentBase64);
List<byte> allFileContent = new List<byte>();

try
{
foreach (var contentBase64 in request.FileContent)
{
var fileContent = Convert.FromBase64String(contentBase64);
allFileContent.AddRange(fileContent);
}
}
catch (FormatException)
{
return BadRequest(new ResponseError
{
code = 400,
msg = "Invalid Base64 Format",
error = true
});
}

//DTO para el request (encapsular y transportar datos)
var reqFileUpload = new reqFileUpload
{
fileName = fileName,
fileContent = fileContent,
location = null,
token = token
fileName = request.FileName,
fileContent = allFileContent.ToArray(),
location = request.Location,
token = request.Token
};

try
Expand Down Expand Up @@ -71,20 +98,19 @@ public async Task<IActionResult> Post([FromForm] string fileContentBase64, [From
throw;
}
}
public class Base64Converter
}
public class Base64Converter
{
public static byte[] DecodeBase64(string base64)
{
public static byte[] DecodeBase64(string base64)
try
{
try
{
return Convert.FromBase64String(base64);
}
catch (FormatException ex)
{
throw new ArgumentException("Invalid Base64 format", ex);
}
return Convert.FromBase64String(base64);
}
catch (FormatException ex)
{
throw new ArgumentException("Invalid Base64 format", ex);
}
}
}

}
Loading

0 comments on commit 7b07e85

Please sign in to comment.