allowing territory to be abandoned, units to be dismissed, and buildings to be destroyed

This commit is contained in:
hz
2026-05-20 19:38:33 -05:00
parent 4a3d3af41c
commit f142440aca
7 changed files with 445 additions and 16 deletions
@@ -180,6 +180,52 @@ public class LocationsController : ControllerBase
: Ok(LocationResponse.FromLocation(location));
}
[Authorize(Roles = "USER,SUPER")]
[HttpPost("destroy-building")]
public async Task<ActionResult<LocationResponse>> DestroyBuilding([FromBody] TerritoryLocationRequest request)
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
try
{
var location = await _locations.DestroyBuildingAsync(username, request.Q, request.R);
return location is null
? BadRequest("Select controlled territory with a non-town-hall building.")
: Ok(LocationResponse.FromLocation(location));
}
catch (InvalidOperationException ex)
{
return BadRequest(ex.Message);
}
}
[Authorize(Roles = "USER,SUPER")]
[HttpPost("abandon")]
public async Task<ActionResult<LocationResponse>> Abandon([FromBody] TerritoryLocationRequest request)
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
try
{
var location = await _locations.AbandonAsync(username, request.Q, request.R);
return location is null
? BadRequest("Select controlled non-home territory to give up.")
: Ok(LocationResponse.FromLocation(location));
}
catch (InvalidOperationException ex)
{
return BadRequest(ex.Message);
}
}
[Authorize(Roles = "USER,SUPER")]
[HttpGet("home")]
public async Task<ActionResult<LocationResponse>> GetHome()
@@ -89,4 +89,34 @@ public class UnitsController : ControllerBase
return BadRequest(new { error = ex.Message });
}
}
[Authorize(Roles = "USER,SUPER")]
[HttpPost("dismiss")]
public async Task<ActionResult<DismissUnitSquadResponse>> Dismiss([FromBody] DismissUnitSquadRequest request)
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
try
{
var dismissedCount = await _units.DismissSquadAsync(username, request);
if (dismissedCount == 0)
{
return BadRequest(new { error = "No matching idle units are available to dismiss." });
}
return Ok(new DismissUnitSquadResponse
{
UnitType = request.UnitType,
DismissedCount = dismissedCount
});
}
catch (ArgumentException ex)
{
return BadRequest(new { error = ex.Message });
}
}
}