Skip to content

Commit

Permalink
#19 updated docs for add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroves committed Sep 22, 2023
1 parent 1a3a10d commit 63f2bfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 16 additions & 2 deletions Conduit/Conduit.Web/Articles/Controllers/CommentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,29 @@ public CommentsController(IAuthService authService, IMediator mediator)
_mediator = mediator;
}

/// <summary>
/// Add comment to an article
/// </summary>
/// <remarks>
/// <a href="https://realworld-docs.netlify.app/docs/specs/backend-specs/endpoints#add-comments-to-an-article">Conduit spec for Add Comments to an Article</a>
/// </remarks>
/// <param name="slug">Article slug</param>
/// <param name="comment">Body of the comment</param>
/// <returns>A view of the created comment</returns>
/// <response code="200">Successful created, returns the created Comment</response>
/// <response code="401">Unauthorized, likely because credentials are incorrect</response>
/// <response code="404">Article wasn't found</response>
/// <response code="422">Article was unable to be created</response>
/// <response code="500">Something went wrong while creating the article</response>
[HttpPost]
[Route("/api/articles/{slug}/comments")]
[Authorize]
public async Task<IActionResult> AddComment([FromRoute] string slug, [FromBody] CommentBodyModel body)
public async Task<IActionResult> 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)
Expand Down
3 changes: 3 additions & 0 deletions Conduit/Conduit.Web/Articles/ViewModels/CommentBodyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ public class CommentBodyModel

public class CommentBody
{
/// <summary>
/// Body of the comment, required, must be less than 1000 characters
/// </summary>
public string Body { get; set; }
}

0 comments on commit 63f2bfc

Please sign in to comment.