Tracking character movement
This commit is contained in:
@@ -11,10 +11,12 @@ namespace LocationsApi.Controllers;
|
||||
public class LocationsController : ControllerBase
|
||||
{
|
||||
private readonly LocationStore _locations;
|
||||
private readonly IConfiguration _cfg;
|
||||
|
||||
public LocationsController(LocationStore locations)
|
||||
public LocationsController(LocationStore locations, IConfiguration cfg)
|
||||
{
|
||||
_locations = locations;
|
||||
_cfg = cfg;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -31,6 +33,7 @@ public class LocationsController : ControllerBase
|
||||
{
|
||||
Name = req.Name.Trim(),
|
||||
Coord = req.Coord,
|
||||
CharacterIds = new List<string>(),
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
@@ -85,4 +88,28 @@ public class LocationsController : ControllerBase
|
||||
|
||||
return Ok("Updated");
|
||||
}
|
||||
|
||||
[HttpPost("presence")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> UpdatePresence([FromBody] UpdateLocationPresenceRequest req)
|
||||
{
|
||||
var internalKey = _cfg["Internal:Key"];
|
||||
if (!string.IsNullOrWhiteSpace(internalKey))
|
||||
{
|
||||
if (!Request.Headers.TryGetValue("X-Internal-Key", out var provided) || provided != internalKey)
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.CharacterId))
|
||||
return BadRequest("CharacterId required");
|
||||
|
||||
if (req.Coord is null)
|
||||
return BadRequest("Coord required");
|
||||
|
||||
var updated = await _locations.UpdatePresenceAsync(req.CharacterId.Trim(), req.Coord);
|
||||
if (!updated)
|
||||
return NotFound("Location not found");
|
||||
|
||||
return Ok("Updated");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user