update
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.CreateNewProducts;
|
||||
public record CreateNewProductsCommand : IRequest<CreateNewProductsResponseDto>
|
||||
{
|
||||
public string Title { get; init; }
|
||||
public string Description { get; init; }
|
||||
public string ShortInfomation { get; init; }
|
||||
public string FullInformation { get; init; }
|
||||
public long Price { get; init; }
|
||||
public int Discount { get; init; }
|
||||
public int Rate { get; init; }
|
||||
public ImageFileModel ImageFile { get; init; }
|
||||
public ImageFileModel ThumbnailFile { get; init; }
|
||||
}
|
||||
|
||||
public class ImageFileModel
|
||||
{
|
||||
public byte[] File { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string Mime { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.CreateNewProducts;
|
||||
public class CreateNewProductsCommandHandler : IRequestHandler<CreateNewProductsCommand, CreateNewProductsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public CreateNewProductsCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CreateNewProductsResponseDto> Handle(CreateNewProductsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var createRequest = request.Adapt<CreateNewProductsRequest>();
|
||||
|
||||
if (request.ImageFile != null && request.ImageFile.File != null && request.ImageFile.File.Length > 0)
|
||||
{
|
||||
var fileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
|
||||
{
|
||||
Directory = "Images/Products",
|
||||
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))
|
||||
createRequest.ImagePath = fileInfo.File;
|
||||
}
|
||||
|
||||
if (request.ThumbnailFile != null && request.ThumbnailFile.File != null && request.ThumbnailFile.File.Length > 0)
|
||||
{
|
||||
var thumbInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
|
||||
{
|
||||
Directory = "Images/Products/Thumbnail",
|
||||
IsBase64 = false,
|
||||
MIME = request.ThumbnailFile.Mime,
|
||||
FileName = request.ThumbnailFile.FileName,
|
||||
File = ByteString.CopyFrom(request.ThumbnailFile.File)
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
if (thumbInfo != null && !string.IsNullOrWhiteSpace(thumbInfo.File))
|
||||
createRequest.ThumbnailPath = thumbInfo.File;
|
||||
}
|
||||
|
||||
var response = await _context.Products.CreateNewProductsAsync(createRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return response.Adapt<CreateNewProductsResponseDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.CreateNewProducts;
|
||||
public class CreateNewProductsResponseDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.DeleteProducts;
|
||||
public record DeleteProductsCommand : IRequest<Unit>
|
||||
{
|
||||
public long Id { get; init; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.DeleteProducts;
|
||||
public class DeleteProductsCommandHandler : IRequestHandler<DeleteProductsCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public DeleteProductsCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteProductsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.Products.DeleteProductsAsync(request.Adapt<DeleteProductsRequest>(), cancellationToken: cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.UpdateProducts;
|
||||
public record UpdateProductsCommand : IRequest<Unit>
|
||||
{
|
||||
public long Id { get; init; }
|
||||
public string Title { get; init; }
|
||||
public string Description { get; init; }
|
||||
public string ShortInfomation { get; init; }
|
||||
public string FullInformation { get; init; }
|
||||
public long Price { get; init; }
|
||||
public int Discount { get; init; }
|
||||
public int Rate { get; init; }
|
||||
public string ImagePath { get; init; }
|
||||
public string ThumbnailPath { get; init; }
|
||||
public ImageFileModel ImageFile { get; init; }
|
||||
public ImageFileModel ThumbnailFile { get; init; }
|
||||
}
|
||||
|
||||
public class ImageFileModel
|
||||
{
|
||||
public byte[] File { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string Mime { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Commands.UpdateProducts;
|
||||
public class UpdateProductsCommandHandler : IRequestHandler<UpdateProductsCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public UpdateProductsCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateProductsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var updateRequest = request.Adapt<UpdateProductsRequest>();
|
||||
|
||||
if (request.ImageFile != null && request.ImageFile.File != null && request.ImageFile.File.Length > 0)
|
||||
{
|
||||
var fileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
|
||||
{
|
||||
Directory = "Images/Products",
|
||||
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))
|
||||
updateRequest.ImagePath = fileInfo.File;
|
||||
}
|
||||
|
||||
if (request.ThumbnailFile != null && request.ThumbnailFile.File != null && request.ThumbnailFile.File.Length > 0)
|
||||
{
|
||||
var thumbInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
|
||||
{
|
||||
Directory = "Images/Products/Thumbnail",
|
||||
IsBase64 = false,
|
||||
MIME = request.ThumbnailFile.Mime,
|
||||
FileName = request.ThumbnailFile.FileName,
|
||||
File = ByteString.CopyFrom(request.ThumbnailFile.File)
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
if (thumbInfo != null && !string.IsNullOrWhiteSpace(thumbInfo.File))
|
||||
updateRequest.ThumbnailPath = thumbInfo.File;
|
||||
}
|
||||
|
||||
await _context.Products.UpdateProductsAsync(updateRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetAllProductsByFilter;
|
||||
public record GetAllProductsByFilterQuery : IRequest<GetAllProductsByFilterResponseDto>
|
||||
{
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
public string? SortBy { get; init; }
|
||||
public GetAllProductsByFilterFilter? Filter { get; init; }
|
||||
}
|
||||
|
||||
public class GetAllProductsByFilterFilter
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? ShortInfomation { get; set; }
|
||||
public string? FullInformation { get; set; }
|
||||
public long? Price { get; set; }
|
||||
public int? Discount { get; set; }
|
||||
public int? Rate { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetAllProductsByFilter;
|
||||
public class GetAllProductsByFilterQueryHandler : IRequestHandler<GetAllProductsByFilterQuery, GetAllProductsByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetAllProductsByFilterQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllProductsByFilterResponseDto> Handle(GetAllProductsByFilterQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.Products.GetAllProductsByFilterAsync(request.Adapt<GetAllProductsByFilterRequest>(), cancellationToken: cancellationToken);
|
||||
return response.Adapt<GetAllProductsByFilterResponseDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetAllProductsByFilter;
|
||||
public class GetAllProductsByFilterResponseDto
|
||||
{
|
||||
public MetaData MetaData { get; set; }
|
||||
public List<GetAllProductsByFilterResponseModel>? Models { get; set; }
|
||||
}
|
||||
|
||||
public class GetAllProductsByFilterResponseModel
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ShortInfomation { get; set; }
|
||||
public string FullInformation { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Discount { get; set; }
|
||||
public int Rate { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
public string ThumbnailPath { get; set; }
|
||||
public int SaleCount { get; set; }
|
||||
public int ViewCount { get; set; }
|
||||
public int RemainingCount { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProducts;
|
||||
public record GetProductsQuery : IRequest<GetProductsResponseDto>
|
||||
{
|
||||
public long Id { get; init; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProducts;
|
||||
public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProductsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetProductsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetProductsResponseDto> Handle(GetProductsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.Products.GetProductsAsync(request.Adapt<GetProductsRequest>(), cancellationToken: cancellationToken);
|
||||
return response.Adapt<GetProductsResponseDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProducts;
|
||||
public class GetProductsResponseDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ShortInfomation { get; set; }
|
||||
public string FullInformation { get; set; }
|
||||
public long Price { get; set; }
|
||||
public int Discount { get; set; }
|
||||
public int Rate { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
public string ThumbnailPath { get; set; }
|
||||
public int SaleCount { get; set; }
|
||||
public int ViewCount { get; set; }
|
||||
public int RemainingCount { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user