package api import ( "fmt" "net/http" "github.com/gin-gonic/gin" "github.com/simpletodoapp/go-todo-app/internal/config" ) // SetupDocs sets up the API documentation func SetupDocs(router *gin.Engine, cfg *config.Config) { // Simple documentation page router.GET("/docs", func(c *gin.Context) { html := fmt.Sprintf(` %s API Documentation

%s API Documentation

%s

Version: %s

Endpoints

Health Check

GET /health

Check the health of the application and database.

Response

{
  "status": "healthy",
  "db_status": "healthy"
}

List Todos

GET /api/todos

Retrieve a list of todos with optional filtering and pagination.

Query Parameters

Response

[
  {
    "id": 1,
    "title": "Learn Go",
    "description": "Learn Go programming language",
    "completed": false,
    "created_at": "2023-09-10T12:00:00Z",
    "updated_at": "2023-09-10T12:00:00Z"
  }
]

Get Todo

GET /api/todos/:id

Retrieve a specific todo by ID.

Path Parameters

Response

{
  "id": 1,
  "title": "Learn Go",
  "description": "Learn Go programming language",
  "completed": false,
  "created_at": "2023-09-10T12:00:00Z",
  "updated_at": "2023-09-10T12:00:00Z"
}

Create Todo

POST /api/todos

Create a new todo item.

Request Body

{
  "title": "Learn Go",
  "description": "Learn Go programming language",
  "completed": false
}

Response

{
  "id": 1,
  "title": "Learn Go",
  "description": "Learn Go programming language",
  "completed": false,
  "created_at": "2023-09-10T12:00:00Z",
  "updated_at": "2023-09-10T12:00:00Z"
}

Update Todo

PUT /api/todos/:id

Update an existing todo.

Path Parameters

Request Body

{
  "title": "Updated title",  // Optional
  "description": "Updated description",  // Optional
  "completed": true  // Optional
}

Response

{
  "id": 1,
  "title": "Updated title",
  "description": "Updated description",
  "completed": true,
  "created_at": "2023-09-10T12:00:00Z",
  "updated_at": "2023-09-10T12:05:00Z"
}

Delete Todo

DELETE /api/todos/:id

Delete a todo.

Path Parameters

Response

No content (HTTP 204)

`, cfg.AppName, cfg.AppName, cfg.AppDescription, cfg.AppVersion) c.Header("Content-Type", "text/html") c.String(http.StatusOK, html) }) }