using System; using Application; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Api.Controllers { [Route("api/links")] [ApiController] public class LinksController : ControllerBase { private readonly LinkService _linkService; private readonly CommentService _commentService; public LinksController(LinkService linkService, CommentService commentService) { _linkService = linkService; _commentService = commentService; } /// /// Récupère la liste liste des derniers liens publiés. /// /// [HttpGet] public LinkDTO[] GetLatest() { return _linkService.GetAllLinks(); } /// /// Récupère les détails d'un lien. /// /// /// [HttpGet("{id:guid}")] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status200OK)] public LinkDTO GetById(Guid id) { return _linkService.GetLinkById(id); } /// /// Récupère tous les commentaires associés à un lien. /// /// /// [HttpGet("{id:guid}/comments")] public CommentDTO[] Comments(Guid id) { return _commentService.GetAllLinkComments(id); } /// /// Permet de publier un nouveau lien sur la plateforme. /// /// /// [HttpPost] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status201Created)] public IActionResult Create(PublishLinkCommand cmd) { var linkId = _linkService.PublishLink(cmd); return CreatedAtAction(nameof(GetById), new { id = linkId }, null); } } }