Workflow is an app that allows teams to manage and track their work efficiently. The commenting system enables team members to discuss issues, provide updates, and collaborate on solutions. Currently, this feature is not functioning correctly, affecting team communication and collaboration.
Issue Summary:
When users attempt to add comments to issues or edit their own comments, the changes do not appear or persist. Fix the comment creation and editing feature in the backend.
Requirements & HTTP Error Handling:
1. POST /api/issues/{issueId}/comments:
- Authentication: If user is not authenticated, return 401 Unauthorized with {"message": "Not authenticated"}.
- Validation: If content is empty, null, or whitespace only, return 400 Bad Request with {"message": "Content is required"}.
- Persistence: Associate comment with the issue and authenticated user. Return 201 Created with the saved comment.
2. PUT /api/comments/{commentId}:
- Authentication: If user is not authenticated, return 401 Unauthorized with {"message": "Not authenticated"}.
- Validation: If content is empty or missing, return 400 Bad Request with {"message": "Content is required"}.
- Existence: If comment does not exist, return 404 Not Found with {"message": "Comment not found"}.
- Authorization: If authenticated user is NOT the creator/owner of the comment, return 403 Forbidden with {"message": "Not authorized"}.
- Persistence: Update content, set isEdited = true, update updatedAt timestamp, save and return 200 OK.
POST /api/issues/1/comments
Headers: Authorization: Bearer <valid_token>
Body: {"content": "Initial update on investigation"}HTTP 201 Created
{
"id": 101,
"content": "Initial update on investigation",
"isEdited": false,
"user": {"email": "[email protected]"}
}Authenticated user creates comment with valid content. Comment is persisted and returned with 201 status.
PUT /api/comments/101
Headers: Authorization: Bearer <other_user_token>
Body: {"content": "Unauthorized edit attempt"}HTTP 403 Forbidden
{"message": "Not authorized"}User attempting edit is not comment owner. Access is forbidden.
1. In CommentService, implement addComment(Long issueId, CommentRequest request, User currentUser): - Check currentUser != null, throw UnauthorizedException('Not authenticated') if missing. - Check request.getContent() != null && !request.getContent().trim().isEmpty(), throw BadRequestException('Content is required'). - Fetch issue by issueId or throw NotFoundException('Issue not found'). - Build Comment entity with issue, user, isEdited=false, save via commentRepository. 2. In CommentService, implement editComment(Long commentId, CommentRequest request, User currentUser): - Check currentUser != null, throw UnauthorizedException('Not authenticated'). - Check request.getContent() != null && !request.getContent().trim().isEmpty(), throw BadRequestException('Content is required'). - Fetch comment by commentId or throw NotFoundException('Comment not found'). - Verify comment.getUser().getId().equals(currentUser.getId()), throw ForbiddenException('Not authorized') if mismatch. - Update content, isEdited=true, updatedAt=Instant.now(), save and return comment.