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