adding resources
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user