74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using Fengling.RiskControl.Domain.Aggregates.RiskAlerts;
|
|
using Fengling.RiskControl.Domain.Events;
|
|
using Fengling.RiskControl.Domain.Repositories;
|
|
using MediatR;
|
|
|
|
namespace Fengling.RiskControl.Application.Services;
|
|
|
|
public class RiskAlertService : IRiskAlertService
|
|
{
|
|
private readonly IRiskAlertRepository _alertRepository;
|
|
private readonly IMediator _mediator;
|
|
|
|
public RiskAlertService(IRiskAlertRepository alertRepository, IMediator mediator)
|
|
{
|
|
_alertRepository = alertRepository;
|
|
_mediator = mediator;
|
|
}
|
|
|
|
public async Task<RiskAlert> CreateAlertAsync(long memberId, string alertType, string description,
|
|
RiskAlertPriority priority = RiskAlertPriority.Medium)
|
|
{
|
|
var alert = RiskAlert.Create(memberId, alertType, description, priority);
|
|
await _alertRepository.AddAsync(alert);
|
|
|
|
return alert;
|
|
}
|
|
|
|
public async Task<RiskAlert> ResolveAlertAsync(long alertId, string notes)
|
|
{
|
|
var alert = await _alertRepository.GetByIdAsync(alertId);
|
|
if (alert == null)
|
|
throw new KeyNotFoundException($"Alert not found: {alertId}");
|
|
|
|
alert.Resolve(notes);
|
|
await _alertRepository.UpdateAsync(alert);
|
|
|
|
return alert;
|
|
}
|
|
|
|
public async Task<RiskAlert> DismissAlertAsync(long alertId, string notes)
|
|
{
|
|
var alert = await _alertRepository.GetByIdAsync(alertId);
|
|
if (alert == null)
|
|
throw new KeyNotFoundException($"Alert not found: {alertId}");
|
|
|
|
alert.Dismiss(notes);
|
|
await _alertRepository.UpdateAsync(alert);
|
|
|
|
return alert;
|
|
}
|
|
|
|
public async Task<RiskAlert> EscalateAlertAsync(long alertId)
|
|
{
|
|
var alert = await _alertRepository.GetByIdAsync(alertId);
|
|
if (alert == null)
|
|
throw new KeyNotFoundException($"Alert not found: {alertId}");
|
|
|
|
alert.Escalate();
|
|
await _alertRepository.UpdateAsync(alert);
|
|
|
|
return alert;
|
|
}
|
|
|
|
public Task<IEnumerable<RiskAlert>> GetMemberAlertsAsync(long memberId)
|
|
{
|
|
return _alertRepository.GetByMemberIdAsync(memberId);
|
|
}
|
|
|
|
public Task<IEnumerable<RiskAlert>> GetPendingAlertsAsync()
|
|
{
|
|
return _alertRepository.GetPendingAlertsAsync();
|
|
}
|
|
}
|