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:
382
routes/post.js
382
routes/post.js
@@ -77,6 +77,25 @@ DB.getDB.then((DB) => {
|
||||
return mergedPosts;
|
||||
};
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Posts
|
||||
* description: Post management
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/organic:
|
||||
* get:
|
||||
* summary: Get the organic feed for the current user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/organic", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
let organicPosts = await DB.getFeed(profileid);
|
||||
@@ -86,6 +105,18 @@ DB.getDB.then((DB) => {
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post:
|
||||
* get:
|
||||
* summary: Get the feed with promotional content
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
//Add non-organic posts
|
||||
@@ -95,6 +126,26 @@ DB.getDB.then((DB) => {
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/tag/{tag}:
|
||||
* get:
|
||||
* summary: Get posts with a specific tag
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: tag
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 400:
|
||||
* description: Tag is required
|
||||
*/
|
||||
router.get("/tag/:tag", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
const tag = req.query.tag || req.params.tag;
|
||||
@@ -109,6 +160,24 @@ DB.getDB.then((DB) => {
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/usr/{id}:
|
||||
* get:
|
||||
* summary: Get posts from a specific user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/usr/:id", async (req, res) => {
|
||||
const profileId = req.params.id;
|
||||
const viewerProdileId = getProfileId(req);
|
||||
@@ -124,6 +193,24 @@ DB.getDB.then((DB) => {
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/usr/{id}/images:
|
||||
* get:
|
||||
* summary: Get all image posts from a user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/usr/:id/images", async (req, res) => {
|
||||
const profileid = req.params.id;
|
||||
const viewerProfileId = getProfileId(req);
|
||||
@@ -134,6 +221,24 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/usr/{id}/embedded:
|
||||
* get:
|
||||
* summary: Get all embedded posts from a user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/usr/:id/embedded", async (req, res) => {
|
||||
const profileid = req.params.id;
|
||||
const viewerProfileId = getProfileId(req);
|
||||
@@ -144,6 +249,24 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/usr/{id}/media:
|
||||
* get:
|
||||
* summary: Get all media posts from a user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/usr/:id/media", async (req, res) => {
|
||||
const profileid = req.params.id;
|
||||
const viewerProfileId = getProfileId(req);
|
||||
@@ -154,11 +277,49 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/video/{id}:
|
||||
* get:
|
||||
* summary: Get video details by ID
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/video/:id", async (req, res) => {
|
||||
videoId = req.params.id;
|
||||
return res.json([]);
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post:
|
||||
* post:
|
||||
* summary: Create a new post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 403:
|
||||
* description: Not authorized to post to this group
|
||||
*/
|
||||
router.post("/", async (req, res) => {
|
||||
let post = {
|
||||
profileid: getProfileId(req),
|
||||
@@ -198,6 +359,27 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/react:
|
||||
* post:
|
||||
* summary: React to a post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/react", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -212,6 +394,27 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/unreact:
|
||||
* post:
|
||||
* summary: Remove a reaction from a post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/unreact", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -221,6 +424,27 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/bookmark:
|
||||
* post:
|
||||
* summary: Bookmark a post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/bookmark", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -230,6 +454,27 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
})
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/unbookmark:
|
||||
* post:
|
||||
* summary: Remove a bookmark from a post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/unbookmark", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -239,6 +484,29 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/comment:
|
||||
* post:
|
||||
* summary: Add a comment to a post
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* content:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/comment/", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -258,6 +526,30 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/comment/react:
|
||||
* post:
|
||||
* summary: React to a comment
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* commentDate:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/comment/react", async (req, res) => {
|
||||
let userid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -272,6 +564,30 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/comment/unreact:
|
||||
* post:
|
||||
* summary: Remove a reaction from a comment
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* postid:
|
||||
* type: string
|
||||
* commentDate:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.post("/comment/unreact", async (req, res) => {
|
||||
let profileid = getProfileId(req);
|
||||
let postid = req.body.postid;
|
||||
@@ -282,6 +598,18 @@ DB.getDB.then((DB) => {
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/images:
|
||||
* get:
|
||||
* summary: Get all image posts for the current user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/images", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
const posts = await DB.getMediaTagPostOfUser(profileid, profileid);
|
||||
@@ -291,6 +619,18 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/embedded:
|
||||
* get:
|
||||
* summary: Get all embedded posts for the current user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/embedded", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
const posts = await DB.getMediaTagPostOfUser(profileid, profileid, "@iframe:");
|
||||
@@ -300,6 +640,18 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/media:
|
||||
* get:
|
||||
* summary: Get all media posts for the current user
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/media", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
const posts = await DB.getMediaTagPostOfUser(profileid, profileid, "@youtube:|@vimeo:|@hls:");
|
||||
@@ -309,6 +661,18 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/course/recent:
|
||||
* get:
|
||||
* summary: Get recently watched media from courses
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/course/recent", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
const profile = await DB.getProfileCache(profileid);
|
||||
@@ -356,6 +720,24 @@ DB.getDB.then((DB) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /post/{id}:
|
||||
* get:
|
||||
* summary: Get a specific post by ID
|
||||
* tags: [Posts]
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
*/
|
||||
router.get("/:id", async (req, res) => {
|
||||
const postId = req.params.id;
|
||||
const post = await DB.getPost(postId);
|
||||
|
||||
Reference in New Issue
Block a user