Feat/us14 crud comentario
Descrição:
Foi feito o seguinte:
-
Correções no modelo de mensagens:
- Adição dos campos
deleted
(booleano) edeletedAt
(timestamp) à tabelamessages
. - Correção de typos identificados no modelo existente.
- Realizadas duas migrações no Prisma em razão disso.
- Adição dos campos
-
Criação do endpoint POST
/comments
:POST /comments
- Request Headers
Authorization: Bearer {token}
- Request body
{ "topicId": "topic-uuid", "content": "This is a comment with text and an image [https://example.com/image.jpg](https://example.com/image.jpg)", "parentId" : "id of the parent, if it exists. Otherwise, no the field can be non existent;", "userId" : "temporarily, this field must the informed by the request (when the auth system is ready, it no longer will be necessary)" }
content: Required, 1-500 characters topicId: Required, must exist User must be authenticated
- Response (201 Created)
{ "id": "comment-uuid", "topicId": "topic-uuid", "userId": "user-uuid", "content": "This is a comment with text and an image [https://example.com/image.jpg](https://example.com/image.jpg)", "createdAt": "2025-04-21T10:00:00Z" }
- Error Responses
400 Bad Request - Empty content, exceeds 500 chars, or missing topicId 401 Unauthorized - Missing/invalid token 404 Not Found - Topic doesn't exist 422 Unprocessable Entity - Validation errors
-
Criação do endpoint GET
/comments
:GET /comments
topicId: Required - The ID of the topic to get comments for parentId: Optional - If provided, returns comments with this parentId. If "null" or not provided, returns root comments
Authorization: Bearer {token}
topicId: Required, must exist User must be authenticated
[ { "id": "comment-uuid", "content": "This is a comment with text and an image [https://example.com/image.jpg](https://example.com/image.jpg)", "creationAt": "2025-04-21T10:00:00Z", "parentId": null, "_count": { "children": 2 }, "author": { "id": "user-uuid", "name": "John Doe" } }, { "id": "comment-uuid-2", "content": "Another comment", "creationAt": "2025-04-21T09:45:00Z", "parentId": null, "_count": { "children": 0 }, "author": { "id": "user-uuid-2", "name": "Jane Smith" } } ]
400 Bad Request - The specified topic does not exist 400 Bad Request - The specified parent comment does not exist 500 Internal Server Error - Error finding the comments
Explicação:
Este endpoint
GET /comments
permite recuperar comentários associados a um tópico específico (topicId
). A recuperação dos comentários é feita em níveis hierárquicos:- Se o parâmetro
parentId
for omitido ou explicitamente definido como"null"
, a requisição retornará apenas os comentários de nível raiz, ou seja, aqueles que não possuem um comentário pai. - Se um
parentId
for fornecido, a requisição retornará todos os comentários que são filhos diretos do comentário com oparentId
especificado.
A autenticação via Bearer Token é obrigatória para acessar este endpoint, e o
topicId
deve ser um ID de tópico existente no sistema. - Se o parâmetro
-
Criação do endpoint DELETE
/comments/{commentId}
:DELETE /comments/{commentId}
- Request Headers
Authorization: Bearer {token}
commentId: Required, must exist User must be authenticated and be either: - The author of the comment OR - An admin/moderator
- Response (200 OK)
{ "message": "Comment deleted successfully", "deletedCount": 1 }
- Error Responses
400 Bad Request - The specified message does not exist 403 Forbidden - The provided user is not authorized to delete such message
Observações Adicionais:
- Todos os endpoints de comentários estão protegidos por autenticação JWT. É necessário realizar um
login
(Basic Auth) para obter o token e incluí-lo no headerAuthorization
das requisições subsequentes.