Spaces:
Paused
Paused
File size: 1,255 Bytes
70556b7 cee3b55 70556b7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | using Application.Abstractions.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace RobDeliveryAPI.Controllers
{
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class MapController : ControllerBase
{
private readonly IMapService _mapService;
public MapController(IMapService mapService)
{
_mapService = mapService;
}
/// <summary>
/// Get all map data (robots and nodes positions)
/// </summary>
[HttpGet("data")]
public async Task<IActionResult> GetMapData()
{
try
{
int? userId = null;
var userIdClaim = User.FindFirst("Id")?.Value;
if (userIdClaim != null && int.TryParse(userIdClaim, out int parsedId))
{
userId = parsedId;
}
var mapData = await _mapService.GetMapDataAsync(userId);
return Ok(mapData);
}
catch (Exception ex)
{
return StatusCode(500, new { error = "An error occurred while retrieving map data", details = ex.Message });
}
}
}
}
|