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 Create([FromBody] CreateSpawnableRequest req) { var spawnable = new Spawnable { Name = req.Name.ToLower(), SpawnRate = req.SpawnRate, CollectAction = req.CollectAction, CollectResults = req.CollectResults }; await _spawnableService.CreateAsync(spawnable); return Ok(spawnable); } [HttpGet] [Authorize(Roles = "SUPER")] public async Task GetAll() { var all = await _spawnableService.GetAllAsync(); return Ok(all); } [HttpDelete("{id}")] [Authorize(Roles = "SUPER")] public async Task Delete(string id) { var spawnable = await _spawnableService.GetByIdAsync(id); if (spawnable == null) return NotFound("Spawnable not found."); await _spawnableService.DeleteAsync(id); return Ok($"Spawnable '{spawnable.Name}' deleted."); } }