103 lines
2.8 KiB
C#
103 lines
2.8 KiB
C#
using FastEndpoints;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Fengling.RiskControl.Domain.Aggregates.RiskAlerts;
|
|
|
|
namespace Fengling.RiskControl.Web.Endpoints;
|
|
|
|
public class GetPendingAlertsEndpoint : Endpoint<EmptyRequest, IEnumerable<RiskAlertResponse>>
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public GetPendingAlertsEndpoint(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Get("/api/v1/risk/alerts/pending");
|
|
Roles("Admin");
|
|
}
|
|
|
|
public override async Task HandleAsync(EmptyRequest req, CancellationToken ct)
|
|
{
|
|
var alerts = await _mediator.Send(new GetPendingAlertsQuery(), ct);
|
|
Response = alerts.Select(a => new RiskAlertResponse
|
|
{
|
|
Id = a.Id,
|
|
MemberId = a.MemberId,
|
|
AlertType = a.AlertType,
|
|
Description = a.Description,
|
|
Priority = a.Priority.ToString(),
|
|
Status = a.Status.ToString(),
|
|
CreatedAt = a.CreatedAt
|
|
});
|
|
}
|
|
}
|
|
|
|
public class GetPendingAlertsQuery : IRequest<IEnumerable<RiskAlert>>
|
|
{
|
|
}
|
|
|
|
public record RiskAlertResponse
|
|
{
|
|
public long Id { get; init; }
|
|
public long MemberId { get; init; }
|
|
public string AlertType { get; init; } = string.Empty;
|
|
public string Description { get; init; } = string.Empty;
|
|
public string Priority { get; init; } = string.Empty;
|
|
public string Status { get; init; } = string.Empty;
|
|
public DateTime CreatedAt { get; init; }
|
|
}
|
|
|
|
public class ResolveAlertEndpoint : Endpoint<ResolveAlertRequest, RiskAlertResponse>
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public ResolveAlertEndpoint(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Post("/api/v1/risk/alerts/{AlertId}/resolve");
|
|
Roles("Admin");
|
|
}
|
|
|
|
public override async Task HandleAsync(ResolveAlertRequest req, CancellationToken ct)
|
|
{
|
|
var alert = await _mediator.Send(new ResolveAlertCommand
|
|
{
|
|
AlertId = req.AlertId,
|
|
Notes = req.Notes
|
|
}, ct);
|
|
|
|
Response = new RiskAlertResponse
|
|
{
|
|
Id = alert.Id,
|
|
MemberId = alert.MemberId,
|
|
AlertType = alert.AlertType,
|
|
Description = alert.Description,
|
|
Priority = alert.Priority.ToString(),
|
|
Status = alert.Status.ToString(),
|
|
CreatedAt = alert.CreatedAt
|
|
};
|
|
}
|
|
}
|
|
|
|
public class ResolveAlertRequest
|
|
{
|
|
[Microsoft.AspNetCore.Mvc.FromRoute]
|
|
public long AlertId { get; set; }
|
|
[Microsoft.AspNetCore.Mvc.FromBody]
|
|
public string Notes { get; set; } = string.Empty;
|
|
}
|
|
|
|
public record ResolveAlertCommand : IRequest<RiskAlert>
|
|
{
|
|
public long AlertId { get; init; }
|
|
public string Notes { get; init; } = string.Empty;
|
|
}
|