refactor: rename UserWalletChangeLog→UserWalletHistory, add History interceptor & migration
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m11s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m11s
- Rename UserWalletChangeLog to UserWalletHistory across 54+ files (entities, configs, DTOs, commands, queries, protos, services) - Rename 34 files and 11 directories accordingly - Rename proto file userwalletchangelog.proto → userwallethistory.proto - Add IHasHistory<T> generic interface for history auto-tracking - Implement IHasHistory<PackageHistory> on Package entity - Add HistoryTrackingSaveChangesInterceptor (reflection-based, auto-fills Old* values from OriginalValues) - Wire interceptor in DI and ApplicationDbContext - Add EF migration Q27_HistoryTables_And_RenameWalletHistory: * RenameTable UserWalletChangeLogs → UserWalletHistories (preserves data) * Rename PK, FK constraints and indexes via sp_rename * CreateTable ClubMembershipCycleHistories + PackageHistories
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.CreateNewUserWalletHistory;
|
||||
public record CreateNewUserWalletHistoryCommand : IRequest<CreateNewUserWalletHistoryResponseDto>
|
||||
{
|
||||
//شناسه کیف پول
|
||||
public long WalletId { get; init; }
|
||||
//موجودی
|
||||
public long CurrentBalance { get; init; }
|
||||
//تغییر موجودی
|
||||
public long ChangeValue { get; init; }
|
||||
//موجودی جاری شبکه
|
||||
public long CurrentNetworkBalance { get; init; }
|
||||
//تغییر موجودی شبکه
|
||||
public long ChangeNerworkValue { get; init; }
|
||||
//افزایشی؟
|
||||
public bool IsIncrease { get; init; }
|
||||
//شناسه ارجاع
|
||||
public long? RefrenceId { get; init; }
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.CreateNewUserWalletHistory;
|
||||
public class CreateNewUserWalletHistoryCommandHandler : IRequestHandler<CreateNewUserWalletHistoryCommand, CreateNewUserWalletHistoryResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateNewUserWalletHistoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CreateNewUserWalletHistoryResponseDto> Handle(CreateNewUserWalletHistoryCommand request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = request.Adapt<UserWalletHistory>();
|
||||
await _context.UserWalletHistories.AddAsync(entity, cancellationToken);
|
||||
entity.AddDomainEvent(new CreateNewUserWalletHistoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return entity.Adapt<CreateNewUserWalletHistoryResponseDto>();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.CreateNewUserWalletHistory;
|
||||
public class CreateNewUserWalletHistoryCommandValidator : AbstractValidator<CreateNewUserWalletHistoryCommand>
|
||||
{
|
||||
public CreateNewUserWalletHistoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.WalletId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.CurrentBalance)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ChangeValue)
|
||||
.NotNull();
|
||||
RuleFor(model => model.CurrentNetworkBalance)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ChangeNerworkValue)
|
||||
.NotNull();
|
||||
RuleFor(model => model.IsIncrease)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateNewUserWalletHistoryCommand>.CreateWithOptions((CreateNewUserWalletHistoryCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.CreateNewUserWalletHistory;
|
||||
public class CreateNewUserWalletHistoryResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.DeleteUserWalletHistory;
|
||||
public record DeleteUserWalletHistoryCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.DeleteUserWalletHistory;
|
||||
public class DeleteUserWalletHistoryCommandHandler : IRequestHandler<DeleteUserWalletHistoryCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public DeleteUserWalletHistoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteUserWalletHistoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserWalletHistories
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWalletHistory), request.Id);
|
||||
entity.IsDeleted = true;
|
||||
_context.UserWalletHistories.Update(entity);
|
||||
entity.AddDomainEvent(new DeleteUserWalletHistoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.DeleteUserWalletHistory;
|
||||
public class DeleteUserWalletHistoryCommandValidator : AbstractValidator<DeleteUserWalletHistoryCommand>
|
||||
{
|
||||
public DeleteUserWalletHistoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<DeleteUserWalletHistoryCommand>.CreateWithOptions((DeleteUserWalletHistoryCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.UpdateUserWalletHistory;
|
||||
public record UpdateUserWalletHistoryCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//شناسه کیف پول
|
||||
public long WalletId { get; init; }
|
||||
//موجودی
|
||||
public long CurrentBalance { get; init; }
|
||||
//تغییر موجودی
|
||||
public long ChangeValue { get; init; }
|
||||
//موجودی جاری شبکه
|
||||
public long CurrentNetworkBalance { get; init; }
|
||||
//تغییر موجودی شبکه
|
||||
public long ChangeNerworkValue { get; init; }
|
||||
//افزایشی؟
|
||||
public bool IsIncrease { get; init; }
|
||||
//شناسه ارجاع
|
||||
public long? RefrenceId { get; init; }
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.UpdateUserWalletHistory;
|
||||
public class UpdateUserWalletHistoryCommandHandler : IRequestHandler<UpdateUserWalletHistoryCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public UpdateUserWalletHistoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateUserWalletHistoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserWalletHistories
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWalletHistory), request.Id);
|
||||
request.Adapt(entity);
|
||||
_context.UserWalletHistories.Update(entity);
|
||||
entity.AddDomainEvent(new UpdateUserWalletHistoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
namespace CMSMicroservice.Application.UserWalletHistoryCQ.Commands.UpdateUserWalletHistory;
|
||||
public class UpdateUserWalletHistoryCommandValidator : AbstractValidator<UpdateUserWalletHistoryCommand>
|
||||
{
|
||||
public UpdateUserWalletHistoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.WalletId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.CurrentBalance)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ChangeValue)
|
||||
.NotNull();
|
||||
RuleFor(model => model.CurrentNetworkBalance)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ChangeNerworkValue)
|
||||
.NotNull();
|
||||
RuleFor(model => model.IsIncrease)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateUserWalletHistoryCommand>.CreateWithOptions((UpdateUserWalletHistoryCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user