ajout gestion des commentaires dans l'API
This commit is contained in:
parent
05d068e817
commit
a9ad4a39c1
17
Apps/HackerNet.Api/Controllers/CommentsController.cs
Normal file
17
Apps/HackerNet.Api/Controllers/CommentsController.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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; }
|
||||||
}
|
}
|
||||||
@ -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"
|
||||||
|
|||||||
@ -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"
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user