36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Fengling.RiskControl.Application.Services;
|
|
using MediatR;
|
|
|
|
namespace Fengling.RiskControl.Application.Commands;
|
|
|
|
public record EvaluateRiskCommand : IRequest<RiskEvaluationResult>
|
|
{
|
|
public long MemberId { get; init; }
|
|
public string EntityType { get; init; } = string.Empty;
|
|
public string EntityId { get; init; } = string.Empty;
|
|
public string ActionType { get; init; } = string.Empty;
|
|
public Dictionary<string, object> Context { get; init; } = new();
|
|
}
|
|
|
|
public class EvaluateRiskCommandHandler : IRequestHandler<EvaluateRiskCommand, RiskEvaluationResult>
|
|
{
|
|
private readonly IRiskEvaluationService _riskService;
|
|
|
|
public EvaluateRiskCommandHandler(IRiskEvaluationService riskService)
|
|
{
|
|
_riskService = riskService;
|
|
}
|
|
|
|
public async Task<RiskEvaluationResult> Handle(EvaluateRiskCommand request, CancellationToken cancellationToken)
|
|
{
|
|
return await _riskService.EvaluateRiskAsync(new RiskEvaluationRequest
|
|
{
|
|
MemberId = request.MemberId,
|
|
EntityType = request.EntityType,
|
|
EntityId = request.EntityId,
|
|
ActionType = request.ActionType,
|
|
Context = request.Context
|
|
});
|
|
}
|
|
}
|