Добавил загрузку документов
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 19s
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 19s
This commit is contained in:
parent
abc6239174
commit
75ef2f218a
29
PaydayBackend/Controllers/UserController.cs
Normal file
29
PaydayBackend/Controllers/UserController.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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
|
||||
|
46
PaydayBackend/Services/IUserService.cs
Normal file
46
PaydayBackend/Services/IUserService.cs
Normal 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";
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user