feat: Add Swagger API documentation
This commit introduces Swagger API documentation for all endpoints in the application. - Installs and . - Configures Swagger in to generate and serve API documentation at . - Adds JSDoc-style Swagger annotations to all routes in and the directory (, , , , , ). - Defines a cookie-based security scheme for authenticated routes. This allows for interactive API documentation and testing via the endpoint.
This commit is contained in:
100
routes/songs.js
100
routes/songs.js
@@ -15,6 +15,25 @@ DB.getDB.then((DB)=>{
|
||||
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Songs
|
||||
* description: Song management
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /songs:
|
||||
* get:
|
||||
* summary: Get all songs
|
||||
* tags: [Songs]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/", async (req, res) => {
|
||||
let profileId = req.params.id;
|
||||
let songs = await DB.getSongs();
|
||||
@@ -24,6 +43,24 @@ DB.getDB.then((DB)=>{
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /songs:
|
||||
* post:
|
||||
* summary: Create a new song
|
||||
* tags: [Songs]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/", async (req, res) => {
|
||||
let post = {
|
||||
userid: getUserId(req),
|
||||
@@ -39,6 +76,24 @@ DB.getDB.then((DB)=>{
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /songs/{id}:
|
||||
* get:
|
||||
* summary: Get a specific song by ID
|
||||
* tags: [Songs]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/:id", async (req, res) => {
|
||||
let profileId = req.params.id;
|
||||
let profile = await DB.getProfile(profileId);
|
||||
@@ -53,6 +108,24 @@ DB.getDB.then((DB)=>{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /songs/{id}:
|
||||
* delete:
|
||||
* summary: Delete a song
|
||||
* tags: [Songs]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.delete("/:id", async (req, res) => {
|
||||
const userid = getUserId(req);
|
||||
const songId = req.params.id;
|
||||
@@ -66,6 +139,33 @@ DB.getDB.then((DB)=>{
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /songs/{id}:
|
||||
* post:
|
||||
* summary: Update a song
|
||||
* tags: [Songs]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* content:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/:id", async (req, res) => {
|
||||
const userid = getUserId(req);
|
||||
const songId = req.params.id;
|
||||
|
||||
Reference in New Issue
Block a user