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

View File

@@ -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; }
}

View File

@@ -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>();
}
}

View File

@@ -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);
};
}

View File

@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
public class CreateNewPackageResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.PackageCQ.Commands.DeletePackage;
public record DeletePackageCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -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;
}
}

View File

@@ -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);
};
}

View File

@@ -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; }
}

View File

@@ -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;
}
}

View File

@@ -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);
};
}