This commit is contained in:
King
2025-09-28 15:24:13 +03:30
parent 514b3a5975
commit 4241523443
222 changed files with 8139 additions and 0 deletions
@@ -0,0 +1,21 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
public record CreateNewPackageCommand : IRequest<CreateNewPackageResponseDto>
{
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//فایل تصویر
public BoostCardFileModel ImageFile { get; init; }
//قیمت
public long Price { get; init; }
}public class BoostCardFileModel
{
//فایل
public byte[] File { get; set; }
//نام
public string FileName { get; set; }
//نوع فایل
public string Mime { get; set; }
}
@@ -0,0 +1,37 @@
using BackOffice.BFF.Application.UserCQ.Commands.CreateNewUser;
using CMSMicroservice.Protobuf.Protos.Package;
using Google.Protobuf;
namespace BackOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
public class CreateNewPackageCommandHandler : IRequestHandler<CreateNewPackageCommand, CreateNewPackageResponseDto>
{
private readonly IApplicationContractContext _context;
public CreateNewPackageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<CreateNewPackageResponseDto> Handle(CreateNewPackageCommand request, CancellationToken cancellationToken)
{
var createNewPackageRequest = request.Adapt<CreateNewPackageRequest>();
if (request.ImageFile != null && request.ImageFile.File != null && request.ImageFile.File.Length > 0)
{
var createNewFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/Package",
IsBase64 = false,
MIME = request.ImageFile.Mime,
FileName = request.ImageFile.FileName,
File = ByteString.CopyFrom(request.ImageFile.File)
}, cancellationToken: cancellationToken);
if (createNewFileInfo != null && !string.IsNullOrWhiteSpace(createNewFileInfo.File))
createNewPackageRequest.ImagePath = createNewFileInfo.File;
}
var response = await _context.Packages.CreateNewPackageAsync(createNewPackageRequest, cancellationToken: cancellationToken);
return response.Adapt<CreateNewPackageResponseDto>();
}
}
@@ -0,0 +1,22 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
public class CreateNewPackageCommandValidator : AbstractValidator<CreateNewPackageCommand>
{
public CreateNewPackageCommandValidator()
{
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.ImageFile)
.NotNull();
RuleFor(model => model.Price)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewPackageCommand>.CreateWithOptions((CreateNewPackageCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
public class CreateNewPackageResponseDto
{
//شناسه
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.DeletePackage;
public record DeletePackageCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,19 @@
using CMSMicroservice.Protobuf.Protos.Package;
namespace BackOffice.BFF.Application.PackageCQ.Commands.DeletePackage;
public class DeletePackageCommandHandler : IRequestHandler<DeletePackageCommand, Unit>
{
private readonly IApplicationContractContext _context;
public DeletePackageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeletePackageCommand request, CancellationToken cancellationToken)
{
await _context.Packages.DeletePackageAsync(request.Adapt<DeletePackageRequest>(), cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.DeletePackage;
public class DeletePackageCommandValidator : AbstractValidator<DeletePackageCommand>
{
public DeletePackageCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeletePackageCommand>.CreateWithOptions((DeletePackageCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,25 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.UpdatePackage;
public record UpdatePackageCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//آدرس تصویر
public string? ImagePath { get; init; }
//قیمت
public long Price { get; init; }
//فایل تصویر
public BoostCardFileModel? ImageFile { get; init; }
}public class BoostCardFileModel
{
//فایل
public byte[] File { get; set; }
//نام
public string FileName { get; set; }
//نوع فایل
public string Mime { get; set; }
}
@@ -0,0 +1,35 @@
using CMSMicroservice.Protobuf.Protos.Package;
using Google.Protobuf;
namespace BackOffice.BFF.Application.PackageCQ.Commands.UpdatePackage;
public class UpdatePackageCommandHandler : IRequestHandler<UpdatePackageCommand, Unit>
{
private readonly IApplicationContractContext _context;
public UpdatePackageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdatePackageCommand request, CancellationToken cancellationToken)
{
var updatePackageRequest = request.Adapt<UpdatePackageRequest>();
if (request.ImageFile != null && request.ImageFile.File != null && request.ImageFile.File.Length > 0)
{
var createNewFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/Package",
IsBase64 = false,
MIME = request.ImageFile.Mime,
FileName = request.ImageFile.FileName,
File = ByteString.CopyFrom(request.ImageFile.File)
}, cancellationToken: cancellationToken);
if (createNewFileInfo != null && !string.IsNullOrWhiteSpace(createNewFileInfo.File))
updatePackageRequest.ImagePath = createNewFileInfo.File;
}
await _context.Packages.UpdatePackageAsync(updatePackageRequest, cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,22 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.UpdatePackage;
public class UpdatePackageCommandValidator : AbstractValidator<UpdatePackageCommand>
{
public UpdatePackageCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.Price)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdatePackageCommand>.CreateWithOptions((UpdatePackageCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,23 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetAllPackageByFilter;
public record GetAllPackageByFilterQuery : IRequest<GetAllPackageByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllPackageByFilterFilter? Filter { get; init; }
}public class GetAllPackageByFilterFilter
{
//شناسه
public long? Id { get; set; }
//عنوان
public string? Title { get; set; }
//توضیحات
public string? Description { get; set; }
//آدرس تصویر
public string? ImagePath { get; set; }
//قیمت
public long? Price { get; set; }
}
@@ -0,0 +1,21 @@
using BackOffice.BFF.Application.UserCQ.Queries.GetAllUserByFilter;
using CMSMicroservice.Protobuf.Protos.Package;
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetAllPackageByFilter;
public class GetAllPackageByFilterQueryHandler : IRequestHandler<GetAllPackageByFilterQuery, GetAllPackageByFilterResponseDto>
{
private readonly IApplicationContractContext _context;
public GetAllPackageByFilterQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetAllPackageByFilterResponseDto> Handle(GetAllPackageByFilterQuery request, CancellationToken cancellationToken)
{
var response = await _context.Packages.GetAllPackageByFilterAsync(request.Adapt<GetAllPackageByFilterRequest>(), cancellationToken: cancellationToken);
return response.Adapt<GetAllPackageByFilterResponseDto>();
}
}
@@ -0,0 +1,14 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetAllPackageByFilter;
public class GetAllPackageByFilterQueryValidator : AbstractValidator<GetAllPackageByFilterQuery>
{
public GetAllPackageByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllPackageByFilterQuery>.CreateWithOptions((GetAllPackageByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,21 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetAllPackageByFilter;
public class GetAllPackageByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllPackageByFilterResponseModel>? Models { get; set; }
}public class GetAllPackageByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//آدرس تصویر
public string ImagePath { get; set; }
//قیمت
public long Price { get; set; }
}
@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetPackage;
public record GetPackageQuery : IRequest<GetPackageResponseDto>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,20 @@
using BackOffice.BFF.Application.UserCQ.Queries.GetUser;
using CMSMicroservice.Protobuf.Protos.Package;
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetPackage;
public class GetPackageQueryHandler : IRequestHandler<GetPackageQuery, GetPackageResponseDto>
{
private readonly IApplicationContractContext _context;
public GetPackageQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetPackageResponseDto> Handle(GetPackageQuery request, CancellationToken cancellationToken)
{
var response = await _context.Packages.GetPackageAsync(request.Adapt<GetPackageRequest>(), cancellationToken: cancellationToken);
return response.Adapt<GetPackageResponseDto>();
}
}
@@ -0,0 +1,16 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetPackage;
public class GetPackageQueryValidator : AbstractValidator<GetPackageQuery>
{
public GetPackageQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetPackageQuery>.CreateWithOptions((GetPackageQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,15 @@
namespace BackOffice.BFF.Application.PackageCQ.Queries.GetPackage;
public class GetPackageResponseDto
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//آدرس تصویر
public string ImagePath { get; set; }
//قیمت
public long Price { get; set; }
}