50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using FastEndpoints;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Fengling.RiskControl.Application.Services;
|
|
using Fengling.RiskControl.Application.Commands;
|
|
|
|
namespace Fengling.RiskControl.Web.Endpoints;
|
|
|
|
public class EvaluateRiskEndpoint : Endpoint<EvaluateRiskRequest, RiskEvaluationResult>
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public EvaluateRiskEndpoint(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Post("/api/v1/risk/evaluate");
|
|
Summary(s => {
|
|
s.Summary = "风险评估";
|
|
s.Description = "对会员进行实时风险评估";
|
|
});
|
|
}
|
|
|
|
public override async Task HandleAsync(EvaluateRiskRequest req, CancellationToken ct)
|
|
{
|
|
var result = await _mediator.Send(new EvaluateRiskCommand
|
|
{
|
|
MemberId = req.MemberId,
|
|
EntityType = req.EntityType,
|
|
EntityId = req.EntityId,
|
|
ActionType = req.ActionType,
|
|
Context = req.Context ?? new()
|
|
}, ct);
|
|
|
|
Response = result;
|
|
}
|
|
}
|
|
|
|
public class EvaluateRiskRequest
|
|
{
|
|
public long MemberId { get; set; }
|
|
public string EntityType { get; set; } = string.Empty;
|
|
public string EntityId { get; set; } = string.Empty;
|
|
public string ActionType { get; set; } = string.Empty;
|
|
public Dictionary<string, object>? Context { get; set; }
|
|
}
|