56 lines
1.5 KiB
C#
56 lines
1.5 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,
|
|
CollectResults = req.CollectResults
|
|
};
|
|
|
|
await _spawnableService.CreateAsync(spawnable);
|
|
return Ok(spawnable);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize(Roles = "SUPER")]
|
|
public async Task<IActionResult> GetAll()
|
|
{
|
|
var all = await _spawnableService.GetAllAsync();
|
|
return Ok(all);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
[Authorize(Roles = "SUPER")]
|
|
public async Task<IActionResult> 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.");
|
|
}
|
|
}
|