using System.Text.Json; using Microsoft.AspNetCore.Mvc; using TuringMachine.Core; namespace TuringMachine.Server.Controllers { [ApiController] [Route("api/[controller]")] public class ExamplesController : ControllerBase { private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; private readonly IWebHostEnvironment _env; public ExamplesController(IWebHostEnvironment env) { _env = env; } /// /// Reads and returns the example list from a JSON file. /// The file is read on every request so changes are reflected without server restart. /// [HttpGet] public async Task>> GetExamples() { var filePath = Path.Combine(_env.ContentRootPath, "Examples", "Examples.json"); if (!System.IO.File.Exists(filePath)) { return NotFound("Examples.json not found."); } var json = await System.IO.File.ReadAllTextAsync(filePath); var examples = JsonSerializer.Deserialize>(json, JsonOptions); return Ok(examples ?? new List()); } } }