Files
territory-autobattler/microservices/LocationsApi/Controllers/ResourcesController.cs
T
2026-05-18 15:05:55 -05:00

34 lines
886 B
C#

using LocationsApi.Models;
using LocationsApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace LocationsApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ResourcesController : ControllerBase
{
private readonly ResourceService _resources;
public ResourcesController(ResourceService resources)
{
_resources = resources;
}
[Authorize(Roles = "USER,SUPER")]
[HttpGet("me")]
public async Task<ActionResult<PlayerResourcesResponse>> GetMine()
{
var username = User.FindFirstValue(ClaimTypes.Name);
if (string.IsNullOrWhiteSpace(username))
{
return Unauthorized();
}
var resources = await _resources.GetAsync(username);
return Ok(PlayerResourcesResponse.FromResources(resources));
}
}