Adding endpoint to only get locations visible to character
This commit is contained in:
@@ -19,10 +19,10 @@ public class CharactersController : ControllerBase
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Create([FromBody] CreateCharacterRequest req)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(req.Name))
|
||||
return BadRequest("Name required");
|
||||
public async Task<IActionResult> Create([FromBody] CreateCharacterRequest req)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(req.Name))
|
||||
return BadRequest("Name required");
|
||||
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
@@ -33,6 +33,7 @@ public class CharactersController : ControllerBase
|
||||
OwnerUserId = userId,
|
||||
Name = req.Name.Trim(),
|
||||
Coord = new Coord { X = 0, Y = 0 },
|
||||
VisionRadius = 3,
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
@@ -42,19 +43,36 @@ public class CharactersController : ControllerBase
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> ListMine()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
return Unauthorized();
|
||||
public async Task<IActionResult> ListMine()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
return Unauthorized();
|
||||
|
||||
var characters = await _characters.GetForOwnerAsync(userId);
|
||||
return Ok(characters);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
var characters = await _characters.GetForOwnerAsync(userId);
|
||||
return Ok(characters);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/visible-locations")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> VisibleLocations(string id)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
return Unauthorized();
|
||||
|
||||
var allowAnyOwner = User.IsInRole("SUPER");
|
||||
var character = await _characters.GetForOwnerByIdAsync(id, userId, allowAnyOwner);
|
||||
if (character is null)
|
||||
return NotFound();
|
||||
|
||||
var locations = await _characters.GetVisibleLocationsAsync(character);
|
||||
return Ok(locations);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
|
||||
Reference in New Issue
Block a user