2026-07-24 17:35:34 -03:00
|
|
|
using Api.SeaHavenIndustries.Helper;
|
2026-04-20 13:25:56 -04:00
|
|
|
using Data.SeaHavenIndustries;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-07-24 17:35:34 -03:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
|
using SeaHaven.Services.Interfaces;
|
2026-04-20 13:25:56 -04:00
|
|
|
|
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[Route("api/uplifts")]
|
|
|
|
|
public class UpliftController : Controller
|
|
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
private readonly IUpliftService _upliftService;
|
|
|
|
|
private readonly ILogger<UpliftController> _logger;
|
2026-04-20 13:25:56 -04:00
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
public UpliftController(IUpliftService upliftService, ILogger<UpliftController> logger)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
_upliftService = upliftService;
|
|
|
|
|
_logger = logger;
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> List([FromQuery] string? status = "Pending", [FromQuery] int? tier = null, [FromQuery] int page = 1, [FromQuery] int pageSize = 25, CancellationToken cancellationToken = default)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _upliftService.ListAsync(User, status, tier, page, pageSize, cancellationToken);
|
|
|
|
|
return Ok(new DataResponse { Status = "Success", Data = result });
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("dispatch/{dispatchId:int}")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> ListForDispatch(int dispatchId, CancellationToken cancellationToken = default)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
var items = await _upliftService.ListForDispatchAsync(User, dispatchId, cancellationToken);
|
2026-04-20 13:25:56 -04:00
|
|
|
return Ok(new DataResponse { Status = "Success", Data = items });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id:int}/approve")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> Approve(int id, [FromBody] DecisionRequest? body, CancellationToken cancellationToken = default)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
try
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _upliftService.ApproveAsync(User, id, body?.Note, cancellationToken);
|
|
|
|
|
return Ok(new DataResponse { Status = "Success", Data = result });
|
|
|
|
|
}
|
|
|
|
|
catch (KeyNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
return NotFound(new Response { Status = "Error", Message = _logger.Sanitize(ex, "Uplift request not found") });
|
|
|
|
|
}
|
|
|
|
|
catch (UpliftForbiddenException ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(403, new Response { Status = "Error", Message = _logger.Sanitize(ex, "You are not authorized to perform this action on this uplift request") });
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new Response { Status = "Error", Message = _logger.Sanitize(ex, "This uplift request cannot be modified in its current state") });
|
|
|
|
|
}
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id:int}/deny")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> Deny(int id, [FromBody] DecisionRequest? body, CancellationToken cancellationToken = default)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
try
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _upliftService.DenyAsync(User, id, body?.Note, cancellationToken);
|
|
|
|
|
return Ok(new DataResponse { Status = "Success", Data = result });
|
|
|
|
|
}
|
|
|
|
|
catch (KeyNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
return NotFound(new Response { Status = "Error", Message = _logger.Sanitize(ex, "Uplift request not found") });
|
|
|
|
|
}
|
|
|
|
|
catch (UpliftForbiddenException ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(403, new Response { Status = "Error", Message = _logger.Sanitize(ex, "You are not authorized to perform this action on this uplift request") });
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new Response { Status = "Error", Message = _logger.Sanitize(ex, "This uplift request cannot be modified in its current state") });
|
|
|
|
|
}
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("can-approve")]
|
|
|
|
|
public IActionResult CanApprove([FromQuery] int tier)
|
|
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
return Ok(new DataResponse { Status = "Success", Data = new { canApprove = _upliftService.CanApprove(User, tier) } });
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DecisionRequest
|
|
|
|
|
{
|
|
|
|
|
public string? Note { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|