add GET /api/users/:id
This commit is contained in:
@@ -101,6 +101,39 @@ router.get("/healthcheck", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/users/{id}:
|
||||||
|
* get:
|
||||||
|
* summary: Get a user by ID
|
||||||
|
* parameters:
|
||||||
|
* - name: id
|
||||||
|
* in: path
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: integer
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: User data
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* example:
|
||||||
|
* id: 1
|
||||||
|
* username: "john_doe"
|
||||||
|
* 400:
|
||||||
|
* description: Invalid user ID
|
||||||
|
* 404:
|
||||||
|
* description: User not found
|
||||||
|
*/
|
||||||
|
router.get("/users/:id", asyncHandler(async (req, res) => {
|
||||||
|
const userId = parseInt(req.params.id, 10);
|
||||||
|
if (isNaN(userId)) throw new ApiError(400, "Invalid user ID");
|
||||||
|
|
||||||
|
const [rows] = await pool.query("SELECT * FROM users WHERE id = ?", [userId]);
|
||||||
|
if (!rows.length) throw new ApiError(404, "User not found");
|
||||||
|
|
||||||
|
res.json(rows[0]);
|
||||||
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
|
|||||||
Reference in New Issue
Block a user