2026-09-18 12:40:33 -03:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SeaHaven.Services.Exceptions;
|
|
|
|
|
using SeaHaven.Services.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/notifications")]
|
|
|
|
|
public class NotificationsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly INotificationFeedService _feedService;
|
2026-09-25 11:16:21 -03:00
|
|
|
private readonly ISlaBreachAcknowledgementService _slaAcknowledgement;
|
2026-09-18 12:40:33 -03:00
|
|
|
|
2026-09-25 11:16:21 -03:00
|
|
|
public NotificationsController(
|
|
|
|
|
INotificationFeedService feedService,
|
|
|
|
|
ISlaBreachAcknowledgementService slaAcknowledgement)
|
2026-09-18 12:40:33 -03:00
|
|
|
{
|
|
|
|
|
_feedService = feedService;
|
2026-09-25 11:16:21 -03:00
|
|
|
_slaAcknowledgement = slaAcknowledgement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Acknowledges the missed response deadline of one work order in the caller's Notification Center.
|
|
|
|
|
/// 204 when recorded or already recorded; 404 when the caller's feed does not cover the work order;
|
|
|
|
|
/// 409 when its deadline has not been missed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("sla/{workOrderId:int}/acknowledge")]
|
|
|
|
|
public async Task<IActionResult> AcknowledgeSlaBreach(int workOrderId, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var outcome = await _slaAcknowledgement.AcknowledgeAsync(User, workOrderId, cancellationToken);
|
|
|
|
|
return outcome switch
|
|
|
|
|
{
|
|
|
|
|
SlaBreachAcknowledgementOutcome.NotFound => NotFound(new
|
|
|
|
|
{
|
|
|
|
|
code = "NotFound",
|
|
|
|
|
message = "Work order not found."
|
|
|
|
|
}),
|
|
|
|
|
SlaBreachAcknowledgementOutcome.NotBreached => Conflict(new
|
|
|
|
|
{
|
|
|
|
|
code = "NotBreached",
|
|
|
|
|
message = "This work order has not missed its response deadline."
|
|
|
|
|
}),
|
|
|
|
|
_ => NoContent()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
catch (WorkOrderBoardValidationException ex) when (ex.Code == "Forbidden")
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status403Forbidden, new
|
|
|
|
|
{
|
|
|
|
|
code = ex.Code,
|
|
|
|
|
message = ex.Message
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-09-18 12:40:33 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> GetFeed(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(await _feedService.GetFeedAsync(User, cancellationToken));
|
|
|
|
|
}
|
|
|
|
|
catch (WorkOrderBoardValidationException ex) when (ex.Code == "Forbidden")
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status403Forbidden, new
|
|
|
|
|
{
|
|
|
|
|
code = ex.Code,
|
|
|
|
|
message = ex.Message
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|