using Microsoft.AspNetCore.Mvc; using SQLiteEF; using static Microsoft.AspNetCore.Http.StatusCodes; namespace API.Controllers; [ApiController] [Route("[controller]")] public class DataController(Context databaseContext) : ApiController(typeof(DataController)) { [HttpGet("Players")] [ProducesResponseType(Status200OK)] public IActionResult GetPlayers() { return Ok(databaseContext.Players.ToArray()); } [HttpGet("Player/{steamId}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetPlayer(ulong steamId) { if (databaseContext.Players.Find(steamId) is not { } player) return NotFound(); return Ok(player); } [HttpGet("Player/{steamId}/Games")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetGamesPlayedByPlayer(ulong steamId) { if (databaseContext.Players.Find(steamId) is not { } player) return NotFound(); databaseContext.Entry(player).Collection(p => p.Games).Load(); return Ok(player.Games.ToArray()); } [HttpGet("Games")] [ProducesResponseType(Status200OK)] public IActionResult GetGames() { return Ok(databaseContext.Games.ToArray()); } [HttpGet("Game/{appId}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetGame(ulong appId) { if (databaseContext.Games.Find(appId) is not { } game) return NotFound(); return Ok(game); } [HttpGet("Game/{appId}/Players")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetPlayersPlayingGame(ulong appId) { if (databaseContext.Games.Find(appId) is not { } game) return NotFound(); databaseContext.Entry(game).Collection(g => g.PlayedBy).Load(); return Ok(game.PlayedBy.ToArray()); } }