Files
gameauthapi/Controllers/ItemController.cs
T
2025-05-08 09:29:20 -05:00

40 lines
1.0 KiB
C#

using System.Threading.Tasks;
using GameAuthApi.Models;
using GameAuthApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace GameAuthApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ItemController : ControllerBase
{
private readonly ItemService _itemService;
private readonly LocationService _locationService;
public ItemController(ItemService itemService, LocationService locationService)
{
_itemService = itemService;
_locationService = locationService;
}
[HttpPost]
[Authorize(Roles = "SUPER")]
public async Task<IActionResult> Create([FromBody] CreateItemRequest req)
{
var location = await _locationService.GetByIdAsync(req.LocationId);
if (location == null)
return BadRequest("Invalid location ID.");
var item = new Item
{
Name = req.Name,
LocationId = req.LocationId
};
await _itemService.CreateAsync(item);
return Ok(item);
}
}