From 63f2bfc9c5cfaa0e0c05e08792144d5bd017ed7b Mon Sep 17 00:00:00 2001 From: "Matthew D. Groves" Date: Fri, 22 Sep 2023 10:13:34 -0400 Subject: [PATCH] #19 updated docs for add comment --- .../008_CreateCollectionForComments.cs | 2 +- .../Articles/Controllers/CommentsController.cs | 18 ++++++++++++++++-- .../Articles/ViewModels/CommentBodyModel.cs | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Conduit/Conduit.Migrations/008_CreateCollectionForComments.cs b/Conduit/Conduit.Migrations/008_CreateCollectionForComments.cs index 5d4c400d13..bfc6305c21 100644 --- a/Conduit/Conduit.Migrations/008_CreateCollectionForComments.cs +++ b/Conduit/Conduit.Migrations/008_CreateCollectionForComments.cs @@ -2,7 +2,7 @@ namespace Conduit.Migrations; -// Manual alternative: create a Favorites collection in _default scope +// Manual alternative: create a Comments collection in _default scope [Migration(8)] public class CreateCollectionForComments: MigrateBase { diff --git a/Conduit/Conduit.Web/Articles/Controllers/CommentsController.cs b/Conduit/Conduit.Web/Articles/Controllers/CommentsController.cs index 57a4089094..d624d1823f 100644 --- a/Conduit/Conduit.Web/Articles/Controllers/CommentsController.cs +++ b/Conduit/Conduit.Web/Articles/Controllers/CommentsController.cs @@ -22,15 +22,29 @@ public CommentsController(IAuthService authService, IMediator mediator) _mediator = mediator; } + /// + /// Add comment to an article + /// + /// + /// Conduit spec for Add Comments to an Article + /// + /// Article slug + /// Body of the comment + /// A view of the created comment + /// Successful created, returns the created Comment + /// Unauthorized, likely because credentials are incorrect + /// Article wasn't found + /// Article was unable to be created + /// Something went wrong while creating the article [HttpPost] [Route("/api/articles/{slug}/comments")] [Authorize] - public async Task AddComment([FromRoute] string slug, [FromBody] CommentBodyModel body) + public async Task AddComment([FromRoute] string slug, [FromBody] CommentBodyModel comment) { var claims = _authService.GetAllAuthInfo(Request.Headers["Authorization"]); var username = claims.Username.Value; - var addCommentRequest = new AddCommentRequest(username, body, slug); + var addCommentRequest = new AddCommentRequest(username, comment, slug); var addCommentResponse = await _mediator.Send(addCommentRequest); if (addCommentResponse.ValidationErrors?.Any() ?? false) diff --git a/Conduit/Conduit.Web/Articles/ViewModels/CommentBodyModel.cs b/Conduit/Conduit.Web/Articles/ViewModels/CommentBodyModel.cs index 5dc333e12a..cc95bd16a5 100644 --- a/Conduit/Conduit.Web/Articles/ViewModels/CommentBodyModel.cs +++ b/Conduit/Conduit.Web/Articles/ViewModels/CommentBodyModel.cs @@ -7,5 +7,8 @@ public class CommentBodyModel public class CommentBody { + /// + /// Body of the comment, required, must be less than 1000 characters + /// public string Body { get; set; } } \ No newline at end of file