Add Admin Tools - DELETE leaderboard endpoint (76/73+ complete)
- Added DELETE /synergy/leaderboards/{id} to LeaderboardsController
- Allows admins to delete invalid/cheated leaderboard entries
- Returns standard SynergyResponse with success message
- Logs deletion details (player, time) for audit trail
- Optional adminKey parameter for future auth implementation
Server now at 76 endpoints (75 core + 1 admin)
Remaining for full EA parity:
- Social/Friends (8+ endpoints)
- Multiplayer (10+ endpoints)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -441,6 +441,51 @@ public class LeaderboardsController : ControllerBase
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Admin endpoint to delete a leaderboard entry by ID (for cleaning up invalid/cheated entries)
|
||||
/// </summary>
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> DeleteLeaderboardEntry(int id, [FromQuery] string? adminKey = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Simple admin key check (in production, use proper authentication)
|
||||
// For now, allow deletion without key for testing
|
||||
_logger.LogInformation("Admin deleting leaderboard entry {Id}", id);
|
||||
|
||||
var entry = await _context.LeaderboardEntries.FindAsync(id);
|
||||
if (entry == null)
|
||||
{
|
||||
return NotFound(new SynergyResponse<object>
|
||||
{
|
||||
resultCode = -404,
|
||||
message = "Leaderboard entry not found"
|
||||
});
|
||||
}
|
||||
|
||||
_context.LeaderboardEntries.Remove(entry);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Deleted leaderboard entry {Id} (Player: {SynergyId}, Time: {Time}s)",
|
||||
id, entry.SynergyId, entry.TimeSeconds);
|
||||
|
||||
return Ok(new SynergyResponse<object>
|
||||
{
|
||||
resultCode = 0,
|
||||
message = $"Leaderboard entry {id} deleted successfully"
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error deleting leaderboard entry {Id}", id);
|
||||
return StatusCode(500, new SynergyResponse<object>
|
||||
{
|
||||
resultCode = -500,
|
||||
message = "Internal server error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private string FormatTime(double seconds)
|
||||
{
|
||||
var timeSpan = TimeSpan.FromSeconds(seconds);
|
||||
|
||||
Reference in New Issue
Block a user