{ "swagger": "2.0", "info": { "description": "\n## How to use the API\n1- Click which endpoint you want to use.\n2- Click \"Try it out\" button.\n3- Add your request body or your parameters which are showed and required by the endpoint.\n4- Click \"Execute\" button.\n5- You will see the response.\n\nSome endpoints require authentication. In this case, you need to log in first.\nI created two types of users for this project: admin and regular user.\nJust send a POST request as below at [here](http://localhost:3000/swagger/index.html/).\nAfter login, you will get a JWE token in cookies.\nIf you're using cookie-based auth, the cookie will be sent automatically.\nAlternatively, you can use Bearer Token authentication via the \"Authorize\" button.\n\n### Login Request For Admin\n```json\n{\n\"email\": \"admin@admin.com\",\n\"password\": \"admin123\"\n}\n```\n\n### Login Request For User\n```json\n{\n\"email\": \"user@user.com\",\n\"password\": \"user1234\"\n}\n```\n\n## Error Handling\nAll error responses will follow this JSON format:\n\n```json\n{\n\"message\": string,\n\"code\": int\n}\n```\n### Example\n```json\n{\n\"message\": \"invalid request\",\n\"code\": 400\n}\n```\n\n## Reminder\nI did not use `/api` prefix for the endpoint routes. Because I love to host my API on \"api\" subdomain.\nStatus code with `2xx` is a success code.\nStatus code with `4xx` is a client error code.\nStatus code with `5xx` is a server error code.", "title": "Advanced Todo API", "contact": {}, "version": "1.0" }, "paths": { "/admin/users": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Fetch users with pagination", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Get users for admin", "parameters": [ { "type": "integer", "description": "Page number", "name": "page", "in": "query", "required": true }, { "type": "integer", "description": "Page size", "name": "limit", "in": "query", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/user.User" } } }, "400": { "description": "Bad Request" }, "500": { "description": "Internal Server Error" } } } }, "/admin/users/{id}": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves user details by ID for admin purposes.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Get user details by ID for admin", "parameters": [ { "type": "string", "description": "User ID", "name": "id", "in": "path", "required": true } ], "responses": { "200": { "description": "User details", "schema": { "$ref": "#/definitions/user.GetUserResponse" } }, "404": { "description": "Not Found" }, "500": { "description": "Internal Server Error" } } } }, "/auth/login": { "post": { "description": "Login a user or admin", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Auth" ], "summary": "Login", "parameters": [ { "description": "Login Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/auth.LoginRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/auth.LoginResponse" } }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "404": { "description": "Not Found" }, "500": { "description": "Internal Server Error" } } } }, "/auth/logout": { "post": { "description": "Removes the refresh token from the database and clears the refresh token cookie.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Auth" ], "summary": "Logout user", "responses": { "204": { "description": "No Content" }, "500": { "description": "Internal Server Error" } } } }, "/auth/refresh": { "post": { "description": "Generate a new access token using a valid refresh token.\nThe API takes refresh token from the cookie and sets a new access token.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Auth" ], "summary": "Refresh access token", "responses": { "204": { "description": "No Content" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/auth/signup": { "post": { "description": "Signup a new user", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Auth" ], "summary": "Signup", "parameters": [ { "description": "Signup request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/auth.SignupRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/auth.SignupResponse" } }, "400": { "description": "Bad Request" }, "409": { "description": "Conflict" }, "500": { "description": "Internal Server Error" } } } }, "/healthcheck": { "get": { "description": "Check the health of the service", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Healthcheck" ], "summary": "Healthcheck", "responses": { "200": { "description": "OK" }, "500": { "description": "Internal Server Error" } } } }, "/todos": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves all todos for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Get all todos", "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/todo.Todo" } } }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal server error" } } }, "post": { "security": [ { "BearerAuth": [] } ], "description": "Creates a new todo item for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Create a new todo", "parameters": [ { "description": "Todo details", "name": "CreateTodoRequest", "in": "body", "required": true, "schema": { "$ref": "#/definitions/todo.CreateTodoRequest" } } ], "responses": { "201": { "description": "Todo created successfully" }, "400": { "description": "Invalid request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal server error" } } } }, "/todos/{id}": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves a todo item by its ID for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Get a todo by ID", "parameters": [ { "type": "string", "description": "Todo ID", "name": "id", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/todo.GetTodoByIdResponse" } }, "400": { "description": "Invalid request" }, "401": { "description": "Unauthorized" }, "404": { "description": "Todo not found" }, "500": { "description": "Internal server error" } } }, "put": { "security": [ { "BearerAuth": [] } ], "description": "Updates an existing todo item for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Update an existing todo", "parameters": [ { "type": "string", "description": "Todo ID", "name": "id", "in": "path", "required": true }, { "description": "Todo details", "name": "UpdateTodoRequest", "in": "body", "required": true, "schema": { "$ref": "#/definitions/todo.UpdateTodoRequest" } } ], "responses": { "204": { "description": "Todo updated successfully" }, "400": { "description": "Invalid request" }, "401": { "description": "Unauthorized" }, "404": { "description": "Todo not found" }, "500": { "description": "Internal server error" } } }, "delete": { "security": [ { "BearerAuth": [] } ], "description": "Deletes a todo item for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Delete a todo", "parameters": [ { "type": "string", "description": "Todo ID", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "Todo deleted successfully" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal server error" } } }, "patch": { "security": [ { "BearerAuth": [] } ], "description": "Toggles the completion status of a todo item for the authenticated user.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "Todo" ], "summary": "Toggle todo completion status", "parameters": [ { "type": "string", "description": "Todo ID", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "Todo completion status toggled" }, "400": { "description": "Invalid request" }, "401": { "description": "Unauthorized" }, "404": { "description": "Todo not found" }, "500": { "description": "Internal server error" } } } }, "/users/account": { "delete": { "security": [ { "BearerAuth": [] } ], "description": "Delete a user's account", "tags": [ "User" ], "summary": "Delete User Account", "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } }, "patch": { "security": [ { "BearerAuth": [] } ], "description": "Update a user's account information", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Update User Account", "parameters": [ { "description": "Update User Account Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/user.UpdateFullNameRequest" } } ], "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/users/forgot-password": { "post": { "description": "It sends a password reset link to the user's email address.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Forgot Password", "parameters": [ { "description": "Forgot Password Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/user.ForgotPasswordRequest" } } ], "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/users/password": { "patch": { "security": [ { "BearerAuth": [] } ], "description": "Change the password of a user", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Change User Password", "parameters": [ { "description": "Change User Password Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/user.ChangePasswordRequest" } } ], "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" }, "500": { "description": "Internal Server Error" } } } }, "/users/profile": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Get the current user. Requires Bearer token authentication.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Get Current User", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/user.GetCurrentUserResponse" } }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/users/reset-password": { "post": { "description": "It resets a user's password using a token.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Reset Password", "parameters": [ { "description": "Reset Password Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/user.ResetPasswordRequest" } } ], "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/users/send-verification-email": { "post": { "security": [ { "BearerAuth": [] } ], "description": "Sends a verification email to the user", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Send Verification Email", "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } }, "/users/verify-email": { "post": { "description": "Verifies a user's email address using a token", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "User" ], "summary": "Verify user email", "parameters": [ { "description": "Verify Email Request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/user.VerifiyEmailRequest" } } ], "responses": { "204": { "description": "No Content" }, "400": { "description": "Bad Request" }, "401": { "description": "Unauthorized" }, "500": { "description": "Internal Server Error" } } } } }, "definitions": { "auth.LoginRequest": { "type": "object", "required": [ "email", "password" ], "properties": { "email": { "type": "string" }, "password": { "type": "string" } } }, "auth.LoginResponse": { "type": "object", "properties": { "role": { "type": "string" } } }, "auth.SignupRequest": { "type": "object", "required": [ "email", "fullName", "password" ], "properties": { "email": { "type": "string" }, "fullName": { "type": "string" }, "password": { "type": "string" } } }, "auth.SignupResponse": { "type": "object", "properties": { "role": { "type": "string" } } }, "todo.CreateTodoRequest": { "type": "object", "required": [ "title" ], "properties": { "title": { "type": "string", "maxLength": 100, "minLength": 1 } } }, "todo.GetTodoByIdResponse": { "type": "object", "properties": { "completed": { "type": "boolean" }, "completed_at": { "type": "string" }, "created_at": { "type": "string" }, "id": { "type": "string" }, "title": { "type": "string" } } }, "todo.Todo": { "type": "object", "properties": { "completed": { "type": "boolean" }, "completed_at": { "type": "string" }, "created_at": { "type": "string" }, "id": { "type": "string" }, "title": { "type": "string" } } }, "todo.UpdateTodoRequest": { "type": "object", "required": [ "title" ], "properties": { "title": { "type": "string" } } }, "user.ChangePasswordRequest": { "type": "object", "required": [ "new_password", "old_password" ], "properties": { "new_password": { "type": "string" }, "old_password": { "type": "string" } } }, "user.ForgotPasswordRequest": { "type": "object", "required": [ "email" ], "properties": { "email": { "type": "string" } } }, "user.GetCurrentUserResponse": { "type": "object", "properties": { "createdAt": { "type": "string" }, "email": { "type": "string" }, "fullName": { "type": "string" }, "id": { "type": "string" }, "isEmailVerified": { "type": "boolean" }, "role": { "type": "string" } } }, "user.GetUserResponse": { "type": "object", "properties": { "email": { "type": "string" }, "full_name": { "type": "string" }, "id": { "type": "string" }, "is_email_verified": { "type": "boolean" } } }, "user.ResetPasswordRequest": { "type": "object", "required": [ "password", "token" ], "properties": { "password": { "type": "string", "minLength": 8 }, "token": { "type": "string" } } }, "user.UpdateFullNameRequest": { "type": "object", "required": [ "address", "full_name" ], "properties": { "address": { "type": "string" }, "full_name": { "type": "string" } } }, "user.User": { "type": "object", "properties": { "email": { "type": "string" }, "full_name": { "type": "string" }, "id": { "type": "string" } } }, "user.VerifiyEmailRequest": { "type": "object", "required": [ "token" ], "properties": { "token": { "type": "string" } } } }, "securityDefinitions": { "BearerAuth": { "description": "Enter your Bearer token in the format **Bearer \u0026lt;token\u0026gt;**", "type": "apiKey", "name": "Authorization", "in": "header" } } }