feat: add FileUploadDto and image file handling to CreateManualPayment command and protobuf definitions
Build and Deploy / build (push) Successful in 2m23s
Build and Deploy / build (push) Successful in 2m23s
This commit is contained in:
+12
@@ -8,6 +8,18 @@ public class CreateManualPaymentCommand : IRequest<CreateManualPaymentResponseDt
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string? ReferenceNumber { get; set; }
|
||||
public string? ImagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Image file data for FMS upload
|
||||
/// </summary>
|
||||
public FileUploadDto? ImageFile { get; set; }
|
||||
}
|
||||
|
||||
public class FileUploadDto
|
||||
{
|
||||
public byte[] File { get; set; } = Array.Empty<byte>();
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Mime { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CreateManualPaymentResponseDto
|
||||
|
||||
+20
-1
@@ -1,4 +1,5 @@
|
||||
using CMSMicroservice.Protobuf.Protos.ManualPayment;
|
||||
using Google.Protobuf;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BackOffice.BFF.Application.ManualPaymentCQ.Commands.CreateManualPayment;
|
||||
@@ -37,7 +38,25 @@ public class CreateManualPaymentCommandHandler : IRequestHandler<CreateManualPay
|
||||
grpcRequest.ReferenceNumber = request.ReferenceNumber;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.ImagePath))
|
||||
// Upload image to FMS if provided
|
||||
if (request.ImageFile != null && request.ImageFile.File != null && request.ImageFile.File.Length > 0)
|
||||
{
|
||||
var fileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
|
||||
{
|
||||
Directory = "Images/ManualPayments",
|
||||
IsBase64 = false,
|
||||
MIME = request.ImageFile.Mime,
|
||||
FileName = request.ImageFile.FileName,
|
||||
File = ByteString.CopyFrom(request.ImageFile.File)
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
if (fileInfo != null && !string.IsNullOrWhiteSpace(fileInfo.File))
|
||||
{
|
||||
grpcRequest.ImagePath = fileInfo.File;
|
||||
_logger.LogInformation("Image uploaded to FMS: {ImagePath}", fileInfo.File);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(request.ImagePath))
|
||||
{
|
||||
grpcRequest.ImagePath = request.ImagePath;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,26 @@
|
||||
using BackOffice.BFF.Application.ManualPaymentCQ.Commands.CreateManualPayment;
|
||||
using BackOffice.BFF.ManualPayment.Protobuf;
|
||||
|
||||
namespace BackOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class ManualPaymentProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
// GetManualPaymentsResponseDto -> GetManualPaymentsResponse
|
||||
// config.NewConfig<GetManualPaymentsResponseDto, GetManualPaymentsResponse>()
|
||||
// .MapWith(src => new GetManualPaymentsResponse
|
||||
// {
|
||||
// MetaData = new MetaData
|
||||
// {
|
||||
// CurrentPage = src.MetaData.PageNumber,
|
||||
// PageSize = src.MetaData.PageSize,
|
||||
// TotalCount = src.MetaData.TotalCount,
|
||||
// TotalPage = (int)Math.Ceiling((double)src.MetaData.TotalCount / src.MetaData.PageSize)
|
||||
// },
|
||||
// Models = { (src.Models ?? Enumerable.Empty<ManualPaymentModel>())
|
||||
// .Select(m => new ManualPaymentProtoModel
|
||||
// {
|
||||
// Id = m.Id,
|
||||
// UserId = m.UserId,
|
||||
// UserFullName = m.UserFullName ?? string.Empty,
|
||||
// UserMobile = m.UserMobile ?? string.Empty,
|
||||
// Amount = m.Amount,
|
||||
// Type = m.Type,
|
||||
// TypeDisplay = m.TypeDisplay ?? string.Empty,
|
||||
// Description = m.Description ?? string.Empty,
|
||||
// ReferenceNumber = m.ReferenceNumber ?? string.Empty,
|
||||
// Status = m.Status,
|
||||
// StatusDisplay = m.StatusDisplay ?? string.Empty,
|
||||
// RequestedBy = m.RequestedBy,
|
||||
// RequestedByName = m.RequestedByName ?? string.Empty,
|
||||
// ApprovedBy = m.ApprovedBy ?? 0,
|
||||
// ApprovedByName = m.ApprovedByName ?? string.Empty,
|
||||
// ApprovedAt = m.ApprovedAt.HasValue
|
||||
// ? Timestamp.FromDateTime(DateTime.SpecifyKind(m.ApprovedAt.Value, DateTimeKind.Utc))
|
||||
// : null,
|
||||
// RejectionReason = m.RejectionReason ?? string.Empty,
|
||||
// TransactionId = m.TransactionId ?? 0,
|
||||
// Created = Timestamp.FromDateTime(DateTime.SpecifyKind(m.Created, DateTimeKind.Utc))
|
||||
// }) }
|
||||
// });
|
||||
// FileUploadModel -> FileUploadDto
|
||||
config.NewConfig<FileUploadModel, FileUploadDto>()
|
||||
.Map(dest => dest.File, src => src.File.ToByteArray())
|
||||
.Map(dest => dest.FileName, src => src.FileName)
|
||||
.Map(dest => dest.Mime, src => src.Mime);
|
||||
|
||||
// CreateManualPaymentResponseDto -> CreateManualPaymentResponse
|
||||
// config.NewConfig<CreateManualPaymentResponseDto, CreateManualPaymentResponse>()
|
||||
// .MapWith(src => new CreateManualPaymentResponse
|
||||
// {
|
||||
// Id = src.Id,
|
||||
// TransactionId = src.TransactionId
|
||||
// });
|
||||
// CreateManualPaymentRequest -> CreateManualPaymentCommand
|
||||
config.NewConfig<CreateManualPaymentRequest, CreateManualPaymentCommand>()
|
||||
.Map(dest => dest.UserId, src => src.UserId)
|
||||
.Map(dest => dest.Amount, src => src.Amount)
|
||||
.Map(dest => dest.Type, src => (int)src.Type)
|
||||
.Map(dest => dest.Description, src => src.Description)
|
||||
.Map(dest => dest.ReferenceNumber, src => src.ReferenceNumber)
|
||||
.Map(dest => dest.ImagePath, src => src.ImagePath)
|
||||
.Map(dest => dest.ImageFile, src => src.ImageFile);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.0.6</Version>
|
||||
<Version>0.0.11</Version>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
|
||||
@@ -66,6 +66,14 @@ message CreateManualPaymentRequest
|
||||
string description = 4;
|
||||
google.protobuf.StringValue reference_number = 5;
|
||||
google.protobuf.StringValue image_path = 6;
|
||||
FileUploadModel image_file = 7;
|
||||
}
|
||||
|
||||
message FileUploadModel
|
||||
{
|
||||
bytes file = 1;
|
||||
string file_name = 2;
|
||||
string mime = 3;
|
||||
}
|
||||
|
||||
message CreateManualPaymentResponse
|
||||
|
||||
Reference in New Issue
Block a user