Generator Changes at 11/12/2025 1:32:03 AM +03:30

This commit is contained in:
masoodafar-web
2025-11-12 02:24:02 +03:30
parent 826ae4589f
commit b27c765731
290 changed files with 30811 additions and 21316 deletions

View File

@@ -0,0 +1,9 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.CreateNewUserWallet;
public record CreateNewUserWalletCommand : IRequest<CreateNewUserWalletResponseDto>
{
//شناسه کاربر
public long UserId { get; init; }
//موجودی
public long Balance { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletCQ.Commands.CreateNewUserWallet;
public class CreateNewUserWalletCommandHandler : IRequestHandler<CreateNewUserWalletCommand, CreateNewUserWalletResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserWalletCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserWalletResponseDto> Handle(CreateNewUserWalletCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserWallet>();
await _context.UserWallets.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserWalletEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserWalletResponseDto>();
}
}

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.CreateNewUserWallet;
public class CreateNewUserWalletCommandValidator : AbstractValidator<CreateNewUserWalletCommand>
{
public CreateNewUserWalletCommandValidator()
{
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.Balance)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserWalletCommand>.CreateWithOptions((CreateNewUserWalletCommand)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 CMSMicroservice.Application.UserWalletCQ.Commands.CreateNewUserWallet;
public class CreateNewUserWalletResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
public record DeleteUserWalletCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
public class DeleteUserWalletCommandHandler : IRequestHandler<DeleteUserWalletCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteUserWalletCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteUserWalletCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserWallets
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWallet), request.Id);
entity.IsDeleted = true;
_context.UserWallets.Update(entity);
entity.AddDomainEvent(new DeleteUserWalletEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.DeleteUserWallet;
public class DeleteUserWalletCommandValidator : AbstractValidator<DeleteUserWalletCommand>
{
public DeleteUserWalletCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteUserWalletCommand>.CreateWithOptions((DeleteUserWalletCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
public record UpdateUserWalletCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه کاربر
public long UserId { get; init; }
//موجودی
public long Balance { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
public class UpdateUserWalletCommandHandler : IRequestHandler<UpdateUserWalletCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateUserWalletCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateUserWalletCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserWallets
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWallet), request.Id);
request.Adapt(entity);
_context.UserWallets.Update(entity);
entity.AddDomainEvent(new UpdateUserWalletEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.UserWalletCQ.Commands.UpdateUserWallet;
public class UpdateUserWalletCommandValidator : AbstractValidator<UpdateUserWalletCommand>
{
public UpdateUserWalletCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.Balance)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserWalletCommand>.CreateWithOptions((UpdateUserWalletCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.UserWalletCQ.EventHandlers;
public class CreateNewUserWalletEventHandler : INotificationHandler<CreateNewUserWalletEvent>
{
private readonly ILogger<
CreateNewUserWalletEventHandler> _logger;
public CreateNewUserWalletEventHandler(ILogger<CreateNewUserWalletEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewUserWalletEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.UserWalletCQ.EventHandlers;
public class DeleteUserWalletEventHandler : INotificationHandler<DeleteUserWalletEvent>
{
private readonly ILogger<
DeleteUserWalletEventHandler> _logger;
public DeleteUserWalletEventHandler(ILogger<DeleteUserWalletEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteUserWalletEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.UserWalletCQ.EventHandlers;
public class UpdateUserWalletEventHandler : INotificationHandler<UpdateUserWalletEvent>
{
private readonly ILogger<
UpdateUserWalletEventHandler> _logger;
public UpdateUserWalletEventHandler(ILogger<UpdateUserWalletEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateUserWalletEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
public record GetAllUserWalletByFilterQuery : IRequest<GetAllUserWalletByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllUserWalletByFilterFilter? Filter { get; init; }
}public class GetAllUserWalletByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه کاربر
public long? UserId { get; set; }
//موجودی
public long? Balance { get; set; }
}

View File

@@ -0,0 +1,32 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
public class GetAllUserWalletByFilterQueryHandler : IRequestHandler<GetAllUserWalletByFilterQuery, GetAllUserWalletByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllUserWalletByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllUserWalletByFilterResponseDto> Handle(GetAllUserWalletByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.UserWallets
.ApplyOrder(sortBy: request.SortBy)
.AsNoTracking()
.AsQueryable();
if (request.Filter is not null)
{
query = query
.Where(x => request.Filter.Id == null || x.Id == request.Filter.Id)
.Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId)
.Where(x => request.Filter.Balance == null || x.Balance == request.Filter.Balance)
;
}
return new GetAllUserWalletByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllUserWalletByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
public class GetAllUserWalletByFilterQueryValidator : AbstractValidator<GetAllUserWalletByFilterQuery>
{
public GetAllUserWalletByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllUserWalletByFilterQuery>.CreateWithOptions((GetAllUserWalletByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
public class GetAllUserWalletByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllUserWalletByFilterResponseModel>? Models { get; set; }
}public class GetAllUserWalletByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه کاربر
public long UserId { get; set; }
//موجودی
public long Balance { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public record GetUserWalletQuery : IRequest<GetUserWalletResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public class GetUserWalletQueryHandler : IRequestHandler<GetUserWalletQuery, GetUserWalletResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserWalletQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserWalletResponseDto> Handle(GetUserWalletQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserWallets
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetUserWalletResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserWallet), request.Id);
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public class GetUserWalletQueryValidator : AbstractValidator<GetUserWalletQuery>
{
public GetUserWalletQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetUserWalletQuery>.CreateWithOptions((GetUserWalletQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public class GetUserWalletResponseDto
{
//شناسه
public long Id { get; set; }
//شناسه کاربر
public long UserId { get; set; }
//موجودی
public long Balance { get; set; }
}