2026-04-20 13:25:56 -04:00
|
|
|
using Data.SeaHavenIndustries;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-05-06 10:49:33 -05:00
|
|
|
using SeaHaven.Services.Interfaces;
|
2026-04-20 13:25:56 -04:00
|
|
|
|
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[Route("api/dispatches")]
|
|
|
|
|
public class DispatchController : Controller
|
|
|
|
|
{
|
2026-05-06 10:49:33 -05:00
|
|
|
private readonly IDispatchService _dispatchService;
|
2026-04-20 13:25:56 -04:00
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
public DispatchController(IDispatchService dispatchService)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-05-06 10:49:33 -05:00
|
|
|
_dispatchService = dispatchService;
|
2026-04-20 13:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> List(
|
|
|
|
|
[FromQuery] string? search = null,
|
|
|
|
|
[FromQuery] string? status = null,
|
|
|
|
|
[FromQuery] int? vendorId = null,
|
|
|
|
|
[FromQuery] DateTime? dateFrom = null,
|
|
|
|
|
[FromQuery] DateTime? dateTo = null,
|
|
|
|
|
[FromQuery] string? sortBy = "dispatchedAt",
|
|
|
|
|
[FromQuery] string? sortDir = "desc",
|
|
|
|
|
[FromQuery] int page = 1,
|
2026-07-24 17:35:34 -03:00
|
|
|
[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 _dispatchService.GetDispatchListAsync(
|
|
|
|
|
search, status, vendorId, dateFrom, dateTo, sortBy, sortDir, page, pageSize, cancellationToken);
|
2026-04-20 13:25:56 -04:00
|
|
|
|
|
|
|
|
return Ok(new DataResponse
|
|
|
|
|
{
|
|
|
|
|
Status = "Success",
|
2026-07-24 17:35:34 -03:00
|
|
|
Data = new { total = result.Total, page = result.Page, pageSize = result.PageSize, items = result.Items }
|
2026-04-20 13:25:56 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id:int}")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
|
2026-04-20 13:25:56 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
var dispatch = await _dispatchService.GetDispatchDetailAsync(id, cancellationToken);
|
2026-04-20 13:25:56 -04:00
|
|
|
if (dispatch == null) return NotFound(new Response { Status = "Error", Message = "Dispatch not found" });
|
|
|
|
|
|
|
|
|
|
return Ok(new DataResponse
|
|
|
|
|
{
|
|
|
|
|
Status = "Success",
|
2026-07-24 17:35:34 -03:00
|
|
|
Data = dispatch
|
2026-04-20 13:25:56 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|