hngprojects / hng_boilerplate_golang_web

Apache License 2.0
77 stars 49 forks source link

[FEAT] HELP CENTER - UPDATE TOPIC #273

Closed uloamaka closed 1 month ago

uloamaka commented 1 month ago

Description

Backend logic to handle topic Updating (Admin only)

Acceptance Criteria

Admin can Update topics

Purpose

Endpoint to allow superadmin to update existing topic

Requirements

Only an authorized individual can update an topic updated topic replaces the old topic in the database

Expected Outcome

Updated topics should reflect on the database

EndPoint

PATCH /api/v1/help-center/topics/:id

Authentication Required: Yes (JWT Token)

Authorization Required: Yes (Admin Role)

Headers:

Content-Type: application/json Authorization: Bearer Request:

{
  "title": "string",
  "content": "string",
  "author": "string"
}

Response: status: 200 OK

{
  "success": true,
  "data": {
    "id": "string",
    "title": "string",
    "content": "string",
    "author": "string",
    "created_at": "datetime",
    "updated_at": "datetime",
  },
  "status_code": 200
}

status: 401 Unauthorized (No token provided or token is invalid)

{
  "success": false,
  "message": "Access denied. No token provided or token is invalid",
  "status_code": 401
}

status: 403 Forbidden (User does not have the required role of admin)

{
  "success": false,
  "message": "Access denied",
  "status_code": 403
}

status: 404 Not-Found

{
  "success": false,
  "message": "Article not found",
  "status_code": 404
}

422 Bad Request: Invalid input data.

{
  "success": false,
  "message": "Invalid input data",
  "status_code": 422
}

Database Schema Table name: articles_table

article_id:

constraints: string(uuid), unique, primary-key, not null title:

constraints: string, unique, not null, text content:

constraints: string, not null, text createdAt:

constraints: datetime updatedAt:

constraints: datetime Database Diagram Database image

Testing

Unit Tests

uloamaka commented 1 month ago

ticket has been approved #121