| | | 1 | | using Chronicis.Api.Services; |
| | | 2 | | using Chronicis.Shared.DTOs; |
| | | 3 | | using Microsoft.AspNetCore.Authorization; |
| | | 4 | | using Microsoft.AspNetCore.Mvc; |
| | | 5 | | |
| | | 6 | | namespace Chronicis.Api.Controllers; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// API endpoints for resolving contextual tutorial content. |
| | | 10 | | /// </summary> |
| | | 11 | | [ApiController] |
| | | 12 | | [Route("tutorials")] |
| | | 13 | | [Authorize] |
| | | 14 | | public class TutorialsController : ControllerBase |
| | | 15 | | { |
| | | 16 | | private readonly ITutorialService _tutorialService; |
| | | 17 | | private readonly ILogger<TutorialsController> _logger; |
| | | 18 | | |
| | 1 | 19 | | public TutorialsController(ITutorialService tutorialService, ILogger<TutorialsController> logger) |
| | | 20 | | { |
| | 1 | 21 | | _tutorialService = tutorialService; |
| | 1 | 22 | | _logger = logger; |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// GET /api/tutorials/resolve?pageType={pageType} - Resolves the tutorial article for the current page context. |
| | | 27 | | /// </summary> |
| | | 28 | | [HttpGet("resolve")] |
| | | 29 | | public async Task<ActionResult<TutorialDto>> Resolve([FromQuery] string pageType) |
| | | 30 | | { |
| | | 31 | | try |
| | | 32 | | { |
| | | 33 | | var tutorial = await _tutorialService.ResolveAsync(pageType); |
| | | 34 | | if (tutorial == null) |
| | | 35 | | { |
| | | 36 | | return NotFound(new { error = "Tutorial not found" }); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | return Ok(tutorial); |
| | | 40 | | } |
| | | 41 | | catch (Exception ex) |
| | | 42 | | { |
| | | 43 | | _logger.LogErrorSanitized(ex, "Error resolving tutorial for page type {PageType}", pageType); |
| | | 44 | | return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | } |