ajout gestion des commentaires dans l'API

This commit is contained in:
Julien LEICHER 2021-12-14 16:06:36 +01:00
parent 05d068e817
commit a9ad4a39c1
No known key found for this signature in database
GPG Key ID: BE0761B6A007EB96
4 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,17 @@
using HackerNet.Application;
using Microsoft.AspNetCore.Mvc;
namespace HackerNet.Api.Controllers;
[ApiController]
[Route("/api/comments")]
public class CommentsController : ControllerBase
{
[HttpGet("{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<LinkComment> GetById(Guid id)
{
throw new NotImplementedException();
}
}

View File

@ -1,3 +1,4 @@
using System.ComponentModel.DataAnnotations;
using HackerNet.Application; using HackerNet.Application;
using HackerNet.Infrastructure.AspNet.Filters; using HackerNet.Infrastructure.AspNet.Filters;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -39,6 +40,36 @@ public class LinksController : ControllerBase
return _linkService.GetLinkDetail(id); return _linkService.GetLinkDetail(id);
} }
/// <summary>
/// Récupère les commentaires associés au lien.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id:guid}/comments")]
public ActionResult<LinkComment[]> GetLinkComments(Guid id)
{
return _linkService.GetLinkComments(id);
}
[HttpPost("{id:guid}/comments")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public ActionResult PublishComment(Guid id, PublishCommentBody cmd)
{
var commentId = _linkService.PublishComment(new PublishCommentCommand
{
LinkId = id,
Content = cmd.Content
});
return CreatedAtAction(
nameof(CommentsController.GetById),
"Comments",
new { id = commentId },
null
);
}
/// <summary> /// <summary>
/// Publie un nouveau lien sur la plateforme /// Publie un nouveau lien sur la plateforme
/// </summary> /// </summary>
@ -53,4 +84,10 @@ public class LinksController : ControllerBase
return CreatedAtAction(nameof(GetLinkDetail), new { id = id }, null); return CreatedAtAction(nameof(GetLinkDetail), new { id = id }, null);
} }
}
public class PublishCommentBody
{
[Required]
public string Content { get; set; }
} }

View File

@ -12,6 +12,7 @@
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7252;http://localhost:5230", "applicationUrl": "https://localhost:7252;http://localhost:5230",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

View File

@ -14,4 +14,13 @@ Content-Type: application/json
### ###
GET {{url}}/api/links/7f92770b-e3ef-4443-ab5d-8aca6449530f GET {{url}}/api/links/7f92770b-e3ef-4443-ab5d-8aca6449530f
###
POST {{url}}/api/links/03a79c72-99e2-482e-8c58-1a099004448f/comments
Content-Type: application/json
{
"content": "Contenu du commentaire"
}