Updating character location based on occupied tile
This commit is contained in:
@@ -104,6 +104,31 @@ public class CharactersController : ControllerBase
|
||||
return Ok(locations);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/coord")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> UpdateCoord(string id, [FromBody] UpdateCharacterCoordRequest req)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
return Unauthorized();
|
||||
if (req.Coord is null)
|
||||
return BadRequest("Coord required");
|
||||
|
||||
var allowAnyOwner = User.IsInRole("SUPER");
|
||||
var character = await _characters.GetByIdAsync(id);
|
||||
if (character is null)
|
||||
return NotFound();
|
||||
if (!allowAnyOwner && character.OwnerUserId != userId)
|
||||
return Forbid();
|
||||
|
||||
character.Coord = req.Coord;
|
||||
var updated = await _characters.UpdateCoordAsync(id, req.Coord);
|
||||
if (!updated)
|
||||
return NotFound();
|
||||
|
||||
return Ok(character);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
|
||||
Reference in New Issue
Block a user