diff --git a/Controllers/AdminController.cs b/Controllers/AdminController.cs new file mode 100644 index 0000000..d936c48 --- /dev/null +++ b/Controllers/AdminController.cs @@ -0,0 +1,27 @@ +using GameAuthApi.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace GameAuthApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class AdminController : ControllerBase +{ + private readonly AdminService _adminService; + + public AdminController(AdminService adminService) + { + _adminService = adminService; + } + + [HttpGet("status")] + [Authorize(Roles = "SUPER")] + public async Task GetStatus() + { + var status = await _adminService.GetStatusAsync(); + return Ok(status); + } +} + diff --git a/GameAuthApi.Tests/AdminControllerTests.cs b/GameAuthApi.Tests/AdminControllerTests.cs new file mode 100644 index 0000000..9e3926b --- /dev/null +++ b/GameAuthApi.Tests/AdminControllerTests.cs @@ -0,0 +1,23 @@ +using GameAuthApi.Controllers; +using GameAuthApi.Services; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; + +public class AdminControllerTests +{ + [Fact] + public async Task GetStatus_ReturnsOk() + { + var expected = new Dictionary { { "status", "ok" } }; + var mockService = new Mock(); + mockService.Setup(s => s.GetStatusAsync()).ReturnsAsync(expected); + var controller = new AdminController(mockService.Object); + + var result = await controller.GetStatus(); + + var ok = Assert.IsType(result); + Assert.Equal(expected, ok.Value); + } +} + diff --git a/Program.cs b/Program.cs index 6edfeca..79d12b9 100644 --- a/Program.cs +++ b/Program.cs @@ -54,6 +54,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); var jwtKey = builder.Configuration["Jwt:Key"]; var keyBytes = Encoding.UTF8.GetBytes(jwtKey); @@ -108,4 +109,4 @@ app.UseAuthorization(); app.MapControllers(); -app.Run(); \ No newline at end of file +app.Run(); diff --git a/README.md b/README.md index d5ddf24..d66cae9 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # gameauthapi -# Deploy -- git pull -- dotnet publish -c Release -- sudo systemctl restart gameapi.service - -# Check logs -journalctl -u gameapi.service -b --no-pager --lines=100 - ## Spawnables Spawnables describe items that can appear in the world. Along with the @@ -18,4 +10,5 @@ performs the required collect action. - **CollectResults** – a list of possible outcomes when the collect action succeeds. Each entry defines: - **Result** – textual description of the outcome. - - **SuccessRate** – percentage chance (0-100) for that outcome. \ No newline at end of file + - **SuccessRate** – percentage chance (0-100) for that outcome. +- **Uses** – optional number of times the item can be successfully acted on before being removed. `0` means it never expires unless `ConsumeOnSuccess` is `true`. diff --git a/Services/AdminService.cs b/Services/AdminService.cs new file mode 100644 index 0000000..eee5359 --- /dev/null +++ b/Services/AdminService.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace GameAuthApi.Services; + +public class AdminService +{ + public virtual Task> GetStatusAsync() + { + var status = new Dictionary + { + {"status", "ok"} + }; + return Task.FromResult(status); + } +} +