Добавил загрузку документов
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 19s

This commit is contained in:
Sergey Karmanov 2023-07-30 11:14:15 +03:00
parent abc6239174
commit 75ef2f218a
Signed by: serega404
GPG Key ID: B6AD49C8C835460C
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using PaydayBackend.Services;
namespace PaydayBackend.Controllers;
[Route("v1/user")]
[ApiController]
public class UserController : ControllerBase
{
private readonly IUserService _userService;
public UserController(IUserService userService)
{
_userService = userService;
}
/// <summary>
/// Загрузить документы
/// </summary>
[HttpPost("banks")]
public async Task<ActionResult> AddBank(long userId, IFormFile file)
{
string result = await _userService.UploadDocs(userId, file);
if (result == "ОК")
return Ok(result);
return BadRequest(result);
}
}

View File

@ -8,4 +8,6 @@ public class Bank
public long Id { get; set; }
public string Name { get; set; }
public string ImageUrl { get; set; }
public string CallbackUrl { get; set; }
public string SecretKey { get; set; }
}

View File

@ -42,6 +42,7 @@ builder.Services.AddHealthChecks()
// Services
builder.Services.AddSingleton<IStorageService, StorageService>();
builder.Services.AddScoped<IAdminService, AdminService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IPublicService, PublicService>();
// Minio

View File

@ -0,0 +1,46 @@
using PaydayBackend.Utils;
namespace PaydayBackend.Services;
public interface IUserService
{
public Task<string> UploadDocs(long userId, IFormFile file);
}
public class UserService : IUserService
{
private readonly DatabaseContext _databaseContext;
private readonly IStorageService _storageService;
public UserService(DatabaseContext databaseContext, IStorageService storageService)
{
_databaseContext = databaseContext;
_storageService = storageService;
}
public async Task<string> UploadDocs(long userId, IFormFile file)
{
string sizeValidator = FileHelper.ValidateMaxFileSize(file, 5, new []{".png"});
if (sizeValidator != "OK")
return sizeValidator;
var fileStream = new MemoryStream();
await file.CopyToAsync(fileStream);
fileStream.Position = 0;
string imageValidator = await FileHelper.ValidateImage(fileStream, null, 200, 200);
if (imageValidator != "OK")
return imageValidator;
await FileHelper.CropImage(fileStream);
var filename = "Doc" + userId + ".png";
if (await _storageService.UploadFile(fileStream, "personal", filename))
{
// Send Request to bank
return "ОК";
}
return "Image not uploaded";
}
}