Files
gameauthapi/Controllers/SpawnableController.cs
T
2025-06-08 21:24:06 -05:00

43 lines
1.1 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 SpawnableController : ControllerBase
{
private readonly SpawnableService _spawnableService;
public SpawnableController(SpawnableService spawnableService)
{
_spawnableService = spawnableService;
}
[HttpPost]
[Authorize(Roles = "SUPER")]
public async Task<IActionResult> Create([FromBody] CreateSpawnableRequest req)
{
var spawnable = new Spawnable
{
Name = req.Name.ToLower(),
SpawnRate = req.SpawnRate,
CollectAction = req.CollectAction
};
await _spawnableService.CreateAsync(spawnable);
return Ok(spawnable);
}
[HttpGet]
[Authorize(Roles = "SUPER")]
public async Task<IActionResult> GetAll()
{
var all = await _spawnableService.GetAllAsync();
return Ok(all);
}
}