First Commit
This commit is contained in:
117
Apis/ADS.Apis.Gps/Controllers/Sicrep/SicrepAuthController.cs
Normal file
117
Apis/ADS.Apis.Gps/Controllers/Sicrep/SicrepAuthController.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ADS.Apis.Gps.Application.Contracts.Auth;
|
||||
using ADS.Apis.Gps.Application.Dtos.Auth;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ADS.Apis.Gps.Controllers.Sicrep;
|
||||
|
||||
[ApiController]
|
||||
[Route("gps/sicrep/auth")]
|
||||
public sealed class SicrepAuthController : ControllerBase
|
||||
{
|
||||
private readonly ISicrepAuthService _service;
|
||||
|
||||
public SicrepAuthController(ISicrepAuthService service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpPost("token")]
|
||||
public async Task<ActionResult<SicrepAuthResponse>> CreateToken(
|
||||
[FromBody] SicrepAuthRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var ip = GetClientIp(HttpContext);
|
||||
var mac = HttpContext.Request.Headers["X-Device-Mac"].ToString(); // si tu app lo manda
|
||||
var grupoEmpresa = HttpContext.Request.Headers["X-GrupoEmpresa"].ToString();
|
||||
var response = await _service.CreateTokenAsync(request,ip,mac,grupoEmpresa, ct);
|
||||
return Ok(response);
|
||||
}
|
||||
static string? GetClientIp(HttpContext http)
|
||||
{
|
||||
// 1) Si hay proxy, X-Forwarded-For trae una lista: "client, proxy1, proxy2"
|
||||
if (http.Request.Headers.TryGetValue("X-Forwarded-For", out var xff))
|
||||
{
|
||||
var first = xff.ToString().Split(',')[0].Trim();
|
||||
if (!string.IsNullOrWhiteSpace(first)) return first;
|
||||
}
|
||||
|
||||
// 2) fallback
|
||||
return http.Connection.RemoteIpAddress?.ToString();
|
||||
}
|
||||
// // ========= UNITS =========
|
||||
|
||||
// [HttpGet("units")]
|
||||
// [ProducesResponseType(typeof(PagedResponse<UnitListItem>), StatusCodes.Status200OK)]
|
||||
// public Task<PagedResponse<UnitListItem>> GetUnits(
|
||||
// [FromQuery] string? search,
|
||||
// [FromQuery] int page = 1,
|
||||
// [FromQuery] int pageSize = 50,
|
||||
// CancellationToken ct = default)
|
||||
// => _svc.GetUnitsAsync(search, page, pageSize, ct);
|
||||
|
||||
// [HttpGet("units/{unitId:int}")]
|
||||
// [ProducesResponseType(typeof(UnitDetail), StatusCodes.Status200OK)]
|
||||
// [ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
// public async Task<ActionResult<UnitDetail>> GetUnit([FromRoute] int unitId, CancellationToken ct = default)
|
||||
// {
|
||||
// var dto = await _svc.GetUnitAsync(unitId, ct);
|
||||
// return dto is null ? NotFound() : Ok(dto);
|
||||
// }
|
||||
|
||||
// [HttpGet("units/{unitId:int}/location")]
|
||||
// [ProducesResponseType(typeof(UnitLocation), StatusCodes.Status200OK)]
|
||||
// [ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
// public async Task<ActionResult<UnitLocation>> GetLastLocation([FromRoute] int unitId, CancellationToken ct = default)
|
||||
// {
|
||||
// var dto = await _svc.GetLastLocationAsync(unitId, ct);
|
||||
// return dto is null ? NotFound() : Ok(dto);
|
||||
// }
|
||||
|
||||
// [HttpGet("units/{unitId:int}/positions")]
|
||||
// [ProducesResponseType(typeof(PositionsResponse), StatusCodes.Status200OK)]
|
||||
// public Task<PositionsResponse> GetPositions(
|
||||
// [FromRoute] int unitId,
|
||||
// [FromQuery] DateTime from,
|
||||
// [FromQuery] DateTime to,
|
||||
// [FromQuery] int limit = 5000,
|
||||
// CancellationToken ct = default)
|
||||
// => _svc.GetPositionsAsync(unitId, from, to, limit, ct);
|
||||
|
||||
// [HttpGet("units/{unitId:int}/events")]
|
||||
// [ProducesResponseType(typeof(EventsResponse), StatusCodes.Status200OK)]
|
||||
// public Task<EventsResponse> GetEvents(
|
||||
// [FromRoute] int unitId,
|
||||
// [FromQuery] DateTime from,
|
||||
// [FromQuery] DateTime to,
|
||||
// CancellationToken ct = default)
|
||||
// => _svc.GetEventsAsync(unitId, from, to, ct);
|
||||
|
||||
// [HttpGet("units/{unitId:int}/status")]
|
||||
// [ProducesResponseType(typeof(UnitStatus), StatusCodes.Status200OK)]
|
||||
// [ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
// public async Task<ActionResult<UnitStatus>> GetStatus([FromRoute] int unitId, CancellationToken ct = default)
|
||||
// {
|
||||
// var dto = await _svc.GetStatusAsync(unitId, ct);
|
||||
// return dto is null ? NotFound() : Ok(dto);
|
||||
// }
|
||||
|
||||
// [HttpPost("units/{unitId:int}/status")]
|
||||
// [ProducesResponseType(typeof(UnitStatus), StatusCodes.Status200OK)]
|
||||
// public Task<UnitStatus> SetStatus(
|
||||
// [FromRoute] int unitId,
|
||||
// [FromBody] UnitStatusRequest body,
|
||||
// CancellationToken ct = default)
|
||||
// => _svc.SetStatusAsync(unitId, body, ct);
|
||||
|
||||
// [HttpGet("units/{unitId:int}/health")]
|
||||
// [ProducesResponseType(typeof(UnitHealth), StatusCodes.Status200OK)]
|
||||
// [ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
// public async Task<ActionResult<UnitHealth>> GetHealth([FromRoute] int unitId, CancellationToken ct = default)
|
||||
// {
|
||||
// var dto = await _svc.GetHealthAsync(unitId, ct);
|
||||
// return dto is null ? NotFound() : Ok(dto);
|
||||
// }
|
||||
}
|
||||
57
Apis/ADS.Apis.Gps/Controllers/UnitsController.cs
Normal file
57
Apis/ADS.Apis.Gps/Controllers/UnitsController.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using ADS.Apis.Gps.Application.Units;
|
||||
using ADS.Helpers.Middleware.InternalUser;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ADS.Apis.Gps.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("units")]
|
||||
public sealed class UnitsController : ControllerBase
|
||||
{
|
||||
private readonly IUnitLocationQueryService _unitLocationQueryService;
|
||||
private readonly IInternalUserContextAccessor _internalUserContextAccessor;
|
||||
|
||||
public UnitsController(
|
||||
IUnitLocationQueryService unitLocationQueryService,
|
||||
IInternalUserContextAccessor internalUserContextAccessor)
|
||||
{
|
||||
_unitLocationQueryService = unitLocationQueryService;
|
||||
_internalUserContextAccessor = internalUserContextAccessor;
|
||||
}
|
||||
|
||||
[HttpGet("location/{noEconomico}")]
|
||||
public async Task<IActionResult> GetLastLocationByNoEconomico(
|
||||
[FromRoute] string noEconomico,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var cveUsuario = _internalUserContextAccessor.Current?.CveUser;
|
||||
|
||||
if (cveUsuario is null || cveUsuario <= 0)
|
||||
return Unauthorized("No se encontró el usuario interno.");
|
||||
|
||||
var result = await _unitLocationQueryService
|
||||
.GetLastLocationByNoEconomicoAsync(cveUsuario.Value, noEconomico, ct);
|
||||
|
||||
if (result is null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("client/{cveCliente}")]
|
||||
public async Task<IActionResult> GetLocationsByClient(
|
||||
[FromRoute] int cveCliente,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var cveUsuario = _internalUserContextAccessor.Current?.CveUser;
|
||||
|
||||
if (cveUsuario is null || cveUsuario <= 0)
|
||||
return Unauthorized("No se encontró el usuario interno.");
|
||||
|
||||
var result = await _unitLocationQueryService
|
||||
.GetLocationsByClientAsync(cveUsuario.Value, cveCliente, ct);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user