Adding admin controller and service
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+2
-1
@@ -54,6 +54,7 @@ builder.Services.AddSingleton<ItemService>();
|
|||||||
builder.Services.AddSingleton<BlacklistService>();
|
builder.Services.AddSingleton<BlacklistService>();
|
||||||
builder.Services.AddSingleton<AuctionService>();
|
builder.Services.AddSingleton<AuctionService>();
|
||||||
builder.Services.AddSingleton<ChatService>();
|
builder.Services.AddSingleton<ChatService>();
|
||||||
|
builder.Services.AddSingleton<AdminService>();
|
||||||
|
|
||||||
var jwtKey = builder.Configuration["Jwt:Key"];
|
var jwtKey = builder.Configuration["Jwt:Key"];
|
||||||
var keyBytes = Encoding.UTF8.GetBytes(jwtKey);
|
var keyBytes = Encoding.UTF8.GetBytes(jwtKey);
|
||||||
@@ -108,4 +109,4 @@ app.UseAuthorization();
|
|||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
# gameauthapi
|
# 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
|
||||||
|
|
||||||
Spawnables describe items that can appear in the world. Along with the
|
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
|
- **CollectResults** – a list of possible outcomes when the collect action
|
||||||
succeeds. Each entry defines:
|
succeeds. Each entry defines:
|
||||||
- **Result** – textual description of the outcome.
|
- **Result** – textual description of the outcome.
|
||||||
- **SuccessRate** – percentage chance (0-100) for that 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`.
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user