Generator Changes at 11/12/2025 11:18:31 PM +03:30
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
namespace CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
|
||||
public record SetPasswordForUserCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
//کلمه عبور فعلی
|
||||
public string? CurrentPassword { get; init; }
|
||||
//کلمه عبور
|
||||
public string NewPassword { get; init; }
|
||||
//تایید کلمه عبور
|
||||
public string ConfirmPassword { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
|
||||
public class SetPasswordForUserCommandHandler : IRequestHandler<SetPasswordForUserCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public SetPasswordForUserCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(SetPasswordForUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
//TODO: Implement your business logic
|
||||
return new Unit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
|
||||
public class SetPasswordForUserCommandValidator : AbstractValidator<SetPasswordForUserCommand>
|
||||
{
|
||||
public SetPasswordForUserCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.NewPassword)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.ConfirmPassword)
|
||||
.NotEmpty();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<SetPasswordForUserCommand>.CreateWithOptions((SetPasswordForUserCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.UserCQ.EventHandlers;
|
||||
|
||||
public class SetPasswordForUserEventHandler : INotificationHandler<SetPasswordForUserEvent>
|
||||
{
|
||||
private readonly ILogger<
|
||||
SetPasswordForUserEventHandler> _logger;
|
||||
|
||||
public SetPasswordForUserEventHandler(ILogger<SetPasswordForUserEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(SetPasswordForUserEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CMSMicroservice.Domain.Events;
|
||||
public class SetPasswordForUserEvent : BaseEvent
|
||||
{
|
||||
public SetPasswordForUserEvent(User item)
|
||||
{
|
||||
}
|
||||
public User Item { get; }
|
||||
}
|
||||
@@ -55,6 +55,12 @@ service UserContract
|
||||
|
||||
};
|
||||
};
|
||||
rpc SetPasswordForUser(SetPasswordForUserRequest) returns (google.protobuf.Empty){
|
||||
option (google.api.http) = {
|
||||
post: "/SetPasswordForUser"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
}
|
||||
message CreateNewUserRequest
|
||||
{
|
||||
@@ -174,3 +180,10 @@ message AdminGetJwtTokenResponse
|
||||
{
|
||||
string token = 1;
|
||||
}
|
||||
message SetPasswordForUserRequest
|
||||
{
|
||||
int64 user_id = 1;
|
||||
google.protobuf.StringValue current_password = 2;
|
||||
string new_password = 3;
|
||||
string confirm_password = 4;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using CMSMicroservice.Protobuf.Protos.User;
|
||||
namespace CMSMicroservice.Protobuf.Validator.User;
|
||||
|
||||
public class SetPasswordForUserRequestValidator : AbstractValidator<SetPasswordForUserRequest>
|
||||
{
|
||||
public SetPasswordForUserRequestValidator()
|
||||
{
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.NewPassword)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.ConfirmPassword)
|
||||
.NotEmpty();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<SetPasswordForUserRequest>.CreateWithOptions((SetPasswordForUserRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using CMSMicroservice.Application.UserCQ.Queries.GetUser;
|
||||
using CMSMicroservice.Application.UserCQ.Queries.GetAllUserByFilter;
|
||||
using CMSMicroservice.Application.UserCQ.Queries.GetJwtToken;
|
||||
using CMSMicroservice.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||
using CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
public class UserService : UserContract.UserContractBase
|
||||
{
|
||||
@@ -44,4 +45,8 @@ public class UserService : UserContract.UserContractBase
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<AdminGetJwtTokenRequest, AdminGetJwtTokenQuery, AdminGetJwtTokenResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> SetPasswordForUser(SetPasswordForUserRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<SetPasswordForUserRequest, SetPasswordForUserCommand>(request, context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user