Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • B backend
  • Project information
    • Project information
    • Activity
    • Labels
    • Planning hierarchy
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Lobo-guará
  • backend
  • Merge requests
  • !13

Closed
Created Apr 25, 2025 by Felipe Conzatti Frison@felipe.frisonDeveloper
  • Report abuse
Report abuse

Feat/us14 crud comentario

  • Overview 2
  • Commits 10
  • Pipelines 4
  • Changes 14

Descrição:

Foi feito o seguinte:

  1. Correções no modelo de mensagens:

    • Adição dos campos deleted (booleano) e deletedAt (timestamp) à tabela messages.
    • Correção de typos identificados no modelo existente.
    • Realizadas duas migrações no Prisma em razão disso.
  2. 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 authenticated

    Responses

    • 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
  3. Criação do endpoint GET /comments:

    Endpoint config

    GET /comments

    Query 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 comments

    Request Headers

    Authorization: Bearer {token}

    Validation Rules

    topicId: Required, must exist
    User must be authenticated

    Responses

    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 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 o parentId 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.

  4. 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/moderator

    Responses

    • 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 header Authorization das requisições subsequentes.
Edited Apr 25, 2025 by Felipe Conzatti Frison
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: feat/US14-CRUD-comentario