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:Endpoint config
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)" }Validation Rules:
content: Required, 1-500 characters topicId: Required, must exist User must be authenticatedResponses
- 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:Endpoint config
GET /commentsQuery Parameters
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 commentsRequest Headers
Authorization: Bearer {token}Validation Rules
topicId: Required, must exist User must be authenticatedResponses
Response (200 OK)
[ { "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" } } ]Error Responses
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 commentsExplicação:
Este endpoint
GET /commentspermite 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
parentIdfor 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
parentIdfor fornecido, a requisição retornará todos os comentários que são filhos diretos do comentário com oparentIdespecificado.
A autenticação via Bearer Token é obrigatória para acessar este endpoint, e o
topicIddeve ser um ID de tópico existente no sistema. - Se o parâmetro
-
Criação do endpoint DELETE
/comments/{commentId}:Endpoint config
DELETE /comments/{commentId}- Request Headers
Authorization: Bearer {token}Validation Rules:
commentId: Required, must exist User must be authenticated and be either: - The author of the comment OR - An admin/moderatorResponses
- 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 headerAuthorizationdas requisições subsequentes.