Updating peasants

This commit is contained in:
hz
2026-05-20 04:09:32 -05:00
parent 864835a8f9
commit 194dae43da
13 changed files with 557 additions and 62 deletions
@@ -148,6 +148,38 @@ public class LocationsController : ControllerBase
}
}
[Authorize(Roles = "USER,SUPER")]
[HttpPost("assign-worker")]
public async Task<ActionResult<LocationResponse>> AssignWorker([FromBody] AssignWorkerRequest request)
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
var location = await _locations.AssignWorkerAsync(username, request);
return location is null
? BadRequest("Select an idle Peasant and a controlled completed building without a worker.")
: Ok(LocationResponse.FromLocation(location));
}
[Authorize(Roles = "USER,SUPER")]
[HttpPost("deassign-worker")]
public async Task<ActionResult<LocationResponse>> DeassignWorker([FromBody] DeassignWorkerRequest request)
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
var location = await _locations.DeassignWorkerAsync(username, request);
return location is null
? BadRequest("Select a controlled building with an assigned worker.")
: Ok(LocationResponse.FromLocation(location));
}
[Authorize(Roles = "USER,SUPER")]
[HttpGet("home")]
public async Task<ActionResult<LocationResponse>> GetHome()