Updating peasants
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user