59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
// MonitoringController.cs
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace FreelancerListServer.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class MonitoringController : ControllerBase
|
|
{
|
|
private readonly LiteDbManager _dbManager;
|
|
private readonly Logger _logger;
|
|
|
|
public MonitoringController(LiteDbManager dbManager, Logger logger)
|
|
{
|
|
_dbManager = dbManager;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult<IEnumerable<MonitoringInfo>> GetMonitoringData()
|
|
{
|
|
try
|
|
{
|
|
var monitoringData = _dbManager.GetCollection<MonitoringInfo>("monitoring").FindAll().ToList();
|
|
_logger.Log($"API: Retrieved {monitoringData.Count} monitoring entries.");
|
|
return Ok(monitoringData);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Log($"API: Error retrieving monitoring data: {ex.Message}");
|
|
return StatusCode(500, new { error = "Internal server error" });
|
|
}
|
|
}
|
|
|
|
[HttpGet("{gameId}")]
|
|
public ActionResult<MonitoringInfo> GetMonitoringDataByGameId(string gameId)
|
|
{
|
|
try
|
|
{
|
|
var monitoringData = _dbManager.GetCollection<MonitoringInfo>("monitoring").FindOne(x => x.GameId == gameId);
|
|
if (monitoringData == null)
|
|
{
|
|
_logger.Log($"API: Monitoring data for GameId={gameId} not found.");
|
|
return NotFound(new { error = $"Monitoring data for GameId={gameId} not found" });
|
|
}
|
|
_logger.Log($"API: Retrieved monitoring data for GameId={gameId}.");
|
|
return Ok(monitoringData);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Log($"API: Error retrieving monitoring data for GameId={gameId}: {ex.Message}");
|
|
return StatusCode(500, new { error = "Internal server error" });
|
|
}
|
|
}
|
|
}
|
|
} |