Adding admin controller and service

This commit is contained in:
hz
2025-08-20 16:32:30 -05:00
parent 34742c0759
commit 1e4b8463ee
5 changed files with 71 additions and 10 deletions
+27
View File
@@ -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<IActionResult> GetStatus()
{
var status = await _adminService.GetStatusAsync();
return Ok(status);
}
}
+23
View File
@@ -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<string, string> { { "status", "ok" } };
var mockService = new Mock<AdminService>();
mockService.Setup(s => s.GetStatusAsync()).ReturnsAsync(expected);
var controller = new AdminController(mockService.Object);
var result = await controller.GetStatus();
var ok = Assert.IsType<OkObjectResult>(result);
Assert.Equal(expected, ok.Value);
}
}
+1
View File
@@ -54,6 +54,7 @@ builder.Services.AddSingleton<ItemService>();
builder.Services.AddSingleton<BlacklistService>();
builder.Services.AddSingleton<AuctionService>();
builder.Services.AddSingleton<ChatService>();
builder.Services.AddSingleton<AdminService>();
var jwtKey = builder.Configuration["Jwt:Key"];
var keyBytes = Encoding.UTF8.GetBytes(jwtKey);
+1 -8
View File
@@ -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
@@ -19,3 +11,4 @@ performs the required collect action.
succeeds. Each entry defines:
- **Result** – textual description of the outcome.
- **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`.
+17
View File
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GameAuthApi.Services;
public class AdminService
{
public virtual Task<Dictionary<string, string>> GetStatusAsync()
{
var status = new Dictionary<string, string>
{
{"status", "ok"}
};
return Task.FromResult(status);
}
}