Recipe fix

This commit is contained in:
dingo
2025-12-28 09:01:40 -05:00
parent 0589ecb783
commit f1b2749526
3 changed files with 85 additions and 7 deletions
+34 -1
View File
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using DataServer.Data;
using DataServer.Data.Entities;
using Server.Services.Auth;
using Server.Game.Dungeon;
namespace Server.Api;
@@ -15,11 +16,43 @@ public class AdminController : ControllerBase
{
private readonly GameDbContext _db;
private readonly IAdminAuthService _adminAuth;
private readonly CraftingHandler? _craftingHandler;
public AdminController(GameDbContext db, IAdminAuthService adminAuth)
public AdminController(GameDbContext db, IAdminAuthService adminAuth, CraftingHandler? craftingHandler = null)
{
_db = db;
_adminAuth = adminAuth;
_craftingHandler = craftingHandler;
}
/// <summary>
/// Refresh server caches (recipes, items, etc.)
/// </summary>
[HttpPost("cache/refresh")]
public async Task<IActionResult> RefreshCache([FromQuery] string? type = null)
{
var auth = await ValidateAdminAsync(AccountRole.Admin);
if (!auth.IsAuthorized) return Unauthorized(new { error = auth.Error });
var refreshed = new List<string>();
// Refresh recipe cache
if (type == null || type.Equals("recipes", StringComparison.OrdinalIgnoreCase))
{
if (_craftingHandler != null)
{
await _craftingHandler.RefreshRecipeCacheAsync();
refreshed.Add("recipes");
}
}
// Add more cache types here as needed (items, mobs, etc.)
return Ok(new {
message = "Cache refreshed",
refreshed,
timestamp = DateTime.UtcNow
});
}
/// <summary>