# Simple Twitter RESTful API doc ###### tags: `webAppDev` `alphaCamp` ## Get Started ### api for development (for Backend to dev) - BASE_URL: https://krll-twitter-api-dev.herokuapp.com/ - API Data: `seeders` `Authentication` `admin` `tweets` `replies` `users` `like` `follow` `tweets2.0` `replies2.0` `auth2.0` - test for socket.io `/socket.io/?EIO=4&transport=websocket` ### api for production (for Frontend to axios) - BASE_URL: https://krll-twitter-api.herokuapp.com/ - API Data: `seeders` `Authentication` `admin` `tweets` `replies` `users` `like` `follow` `tweets2.0` `replies2.0` `auth2.0` ### Vue app on GitHub Page - Link: https://russelllin7789.github.io/twitter-front-end-vue/ #### Seed - Admin: `@root` - Users: `@user1`, `@user2`, ... , `@user5` - password: `12345678` ## Update Timestamp - 2020-12-16 14:23 [Authentication](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Authentication): update responses - 2020-12-16 22:03 [Admin](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Admin) - [readUsers](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readUsers): update responses - 2020-12-16 22:48 [Tweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Tweets) - [readTweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readTweets): update responses - 2020-12-16 23:16 [Tweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Tweets) - [postTweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#postTweets): update responses - 2020-12-16 23:37 [Replies](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Replies) - [readReplies](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readReplies): update responses - 2020-12-16 23:48 [Replies](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Replies) - [postReplies](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#postReplies): update responses - 2020-12-17 11:19 [Likes](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Likes) - [like](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#like): update responses - 2020-12-17 11:19 [Likes](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Likes) - [unlike](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#unlike): update responses - 2020-12-17 15:58 [Admin](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Admin): update all responses - 2020-12-18 11:35 [Tweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Tweets): update all responses - 2020-12-18 17:40 [Users](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Users) - [readUser](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readUser), [readTweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readTweets), [readRepliedTweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readRepliedTweets), [readLikes](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readLikes): update all responses - 2020-12-22 11:34 [Users](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Users) - [readRepliedTweets](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readRepliedTweets), [readLikes](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readLikes): update all responses - 2020-12-22 13:03 [Users](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Users) - [updateUser](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#updateUser): update [params](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Parameters---for-account-setting) for account setting & profile setting - 2020-12-23 16:36 [Authentication](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Authentication): add [getCurrentUser](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#getCurrentUser) - 2020-12-24 14:29 [Users](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Users) - [updateUser](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#updateUser): update [params](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Parameters---for-account-setting) for account setting - 2020-12-24 20:24 [Users](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#Users): add [readTopUsers](https://hackmd.io/9GUKdrftR56pX0WX85K_xQ?both#readTopUsers) ## ERD ![Simple Twitter EDR_201208](https://i.imgur.com/rucEixZ.png) &nbsp; <br> ## Authentication ``` path: routes/auth.js controller: controllers/authController.js ``` ### login #### Method & URL ``` POST /api/login ``` #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | account | require | String | | password | require | String | #### Response ##### Success ``` { "status": "success", "message": "user1, welcome!", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTEsImlhdCI6MTYwODEwODQ2NywiZXhwIjoxNjA4MTEyMDY3fQ.OxbxT5vEj3_icl4ZaZDRaz7KGEZ5i0bB9aQeTrETqQI", "user": { "id": 11, "email": "user1@example.com", "password": "$2a$10$2tdllKdK2VPeGKsJeec2XObzIK3kA4lt5W8PVu/.OPWkRQjbCsiDq", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=60.45057970816829", "introduction": "Quia consequatur optio consequatur dolor commodi et.", "account": "@user1", "cover": "https://loremflickr.com/320/240/background/?random=34.0538352094005", "role": "user", "createdAt": "2020-12-16T08:46:08.000Z", "updatedAt": "2020-12-16T08:46:08.000Z" } } ``` ##### Failure ``` { "status": "failure", "message": "all fields are required" }, { "status": "failure", "message": "account or password is wrong" } ``` ### register #### Method & URL ``` POST /api/users ``` #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | account | require | String | | name | require | String | | email | require | String | | password | require | String | | checkPassword | require | String | #### Response ##### Success ``` { "status": "success", "message": "account: '@root' is registered successfully!" } ``` ##### Failure ``` { "status": "failure", "message": "password & checkPassword are different!" }, { "status": "failure", "message": "email: 'root@example.com' has already existed!" }, { "status": "failure", "message": "account: '@root' has already existed!" } ``` ### getCurrentUser #### Method & URL ``` GET /api/current_user ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "id": 53, "email": "wolverine@xmen.org", "name": "Logan", "avatar": "https://i.imgur.com/qrr11vy.jpg", "introduction": null, "account": "@wolverine", "cover": "https://i.imgur.com/GjR3HLs.jpg", "role": "user" } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` &nbsp; <br> ## Admin ``` path: routes/admin.js controller: controllers/adminController.js ``` ### readUsers #### Method & URL ``` GET /api/admin/users ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | require | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 21, "email": "user2@example.com", "password": "$2a$10$pqbQcf73EeNMDX8nxb0g7.wQSBFnXkrdW.E1eUJRbwuzSjwFaBUtm", "name": "user2", "avatar": "https://loremflickr.com/320/240/avatar/?random=66.74408201076929", "introduction": "Et debitis error dolor sint voluptatem eveniet minima.", "account": "@user2", "cover": "https://loremflickr.com/320/240/background/?random=79.62272419337143", "role": "user", "createdAt": "2020-12-16T08:46:08.000Z", "updatedAt": "2020-12-16T08:46:08.000Z", "tweetsCount": 10, "likesCount": 0, "followersCount": 0, "followingsCount": 0 }, {...}, {...} ] ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### readTweets #### Method & URL ``` GET /api/admin/tweets ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | require | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 1, "UserId": 11, "description": "Molestias dolor voluptatibus eveniet et cupiditate ipsum aperiam eius necessitatibus. Facilis voluptas exercitationem ut consequatur maxime eligendi optio. Provident reiciendis labore voluptates mollitia quasi harum sed rerum debitis. Et voluptas aut placeat. Id cum animi soluta consequuntur odit est porro.", "createdAt": "2020-12-16T08:46:08.000Z", "updatedAt": "2020-12-16T08:46:08.000Z", "User": { "id": 11, "account": "@user1", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=60.45057970816829" } }, {...}, {...} ] ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### deleteTweet #### Method & URL ``` DELETE /api/admin/tweets/:id ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | require | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "status": "success", "message": "tweets/111 is deleted successfully", "tweet": { "id": 111, "UserId": 21, "description": "Aut quod officia soluta quo necessitatibus amet eligendi. Distinctio quis eveniet. Alias dolores quas expedita blanditiis.\n \rNeque maiores magni reprehenderit optio voluptas tenetur possimus eaque aspernatur. Voluptas et dolores perferendis est quos molestiae. Rem maiores inventore quasi nihil maxime ea voluptatem. Non minima eos earum quasi dolores qui voluptas est.\n \rSit rerum delectus facere ipsa odit et recusandae excepturi. Et velit quia cupiditate eveniet quod aperiam. Rerum aspernatur vel et. Illum veniam omnis ullam ut tempore non facere. Odio et dolorem.", "createdAt": "2020-12-16T08:46:08.000Z", "updatedAt": "2020-12-16T08:46:08.000Z" } } ``` ##### Failure ``` { "status": "failure", "message": "tweets/111 do not exit!", "tweet": null } ``` &nbsp; <br> ## Users ``` path: routes/users.js controller: controllers/userController.js ``` ### readUser #### Method & URL ``` GET /api/users/:id ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "id": 11, "email": "user1@example.com", "password": "$2a$10$cZksAwlWHx2ydqpHAE7N1uX7i2AB/hom/Zx6s4TqjBaxK5F9ttgja", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=63.61217037673732", "introduction": "Officiis pariatur delectus ex itaque.", "account": "@user1", "cover": "https://loremflickr.com/320/240/background/?random=19.89156475064535", "role": "user", "createdAt": "2020-12-16T08:28:16.000Z", "updatedAt": "2020-12-16T08:28:16.000Z", "isSelf": true, "isFollowed": false, "tweetsCount": 8, "followingsCount": 1, "followersCount": 0 } ``` ##### Failure ``` { // status code: 404 "message": "this user(id: 111) do not exist!" } ``` ### readTweets #### Method & URL ``` GET /api/users/:id/tweets ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 21, "UserId": 11, "description": "Dolor eos dolores reiciendis accusantium a aut expedita. Excepturi ratione architecto ducimus est est ea dolorum. Necessitatibus sunt et. Molestiae nemo sunt consectetur unde quibusdam omnis tempore modi.", "createdAt": "2020-12-16T08:28:17.000Z", "updatedAt": "2020-12-16T08:28:17.000Z", "repliesCount": 3, "likesCount": 0, "isLike": false }, { "id": 31, "UserId": 11, "description": "Omnis et dolor in sint.", "createdAt": "2020-12-16T08:28:17.000Z", "updatedAt": "2020-12-16T08:28:17.000Z", "repliesCount": 3, "likesCount": 1, "isLike": true }, {...}, {...} ] ``` ##### Failure ``` { // status code: 404 "message": "tweets of user(id: 111) do not exist!" } ``` ### readRepliedTweets #### Method & URL ``` GET /api/users/:id/replied_tweets ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 101, "UserId": 11, "TweetId": 31, "comment": "sunt", "createdAt": "2020-12-16T08:28:17.000Z", "updatedAt": "2020-12-16T08:28:17.000Z", "Tweet": { "id": 31, "UserId": 11, "description": "Omnis et dolor in sint.", "createdAt": "2020-12-16T08:28:17.000Z", "updatedAt": "2020-12-16T08:28:17.000Z", "User": { "id": 11, "account": "@user1", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=63.61217037673732" }, "repliesCount": 3, "likesCount": 1, "isLike": true }, }, {...}, {...}, ] ``` ##### Failure ``` { // status code: 404 "message": "replies of user(id: 111) do not exist!" } ``` ### readLikes #### Method & URL ``` GET /api/users/:id/likes ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 3, "UserId": 11, "TweetId": 41, "createdAt": "2020-12-16T08:28:16.000Z", "updatedAt": "2020-12-16T08:28:16.000Z", "Tweet": { "id": 41, "UserId": 11, "description": "a quibusdam numquam", "createdAt": "2020-12-16T08:28:17.000Z", "updatedAt": "2020-12-16T08:28:17.000Z", "User": { "id": 11, "account": "@user1", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=63.61217037673732" }, "repliesCount": 3, "likesCount": 1, "isLike": false }, }, {...}, {...}, ] ``` ##### Failure ``` { // status code: 404 "message": "likes of user(id: 111) do not exist!" } ``` ### readFollowings #### Method & URL ``` GET /api/users/:id/followings ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "status": "success", "message": "OK", "followings": [ { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "followerId": "1", "followingId": "7" }, {...}, {...}, ... ] } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### readFollowers #### Method & URL ``` GET /api/users/:id/followers ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "status": "success", "message": "OK", "followers": [ { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "followerId": "1", "followingId": "7", "follower": {...}, "isFollowed": true }, {...}, {...}, ... ] } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### readTopUsers #### Method & URL ``` GET /api/users/top ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 51, "account": "@user5", "name": "user5", "avatar": "https://loremflickr.com/320/240/avatar/?random=87.13309242457343", "followersCount": 5, "isFollowed": true }, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...} ] ``` ### updateUser #### Method & URL ``` PUT /api/user/:id ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Parameters - for account setting | Params | Require | Type | | ------------- | ------------ | -------- | | account | require | String | | name | require | String | | email | require | String | | oldPassword | x | String | | newPassword | if old exist | String | | checkPassword | if old exist | String | #### Parameters - for profile setting | Params | Require | Type | | ------------ | -------- | -------- | | name | require | String | | introduction | x | Text | | avatar | x | String | | cover | x | String | #### Response ##### Success ``` { "status": "success", "message": "Your accont is update successfully!", "user": { "id": "1", "account": "@user1", "name": "user1", "email": "user1@example.com", "password": "12345678", "isAdmin": "false", "introduction": "My name is user1", "avatar": "https://i.imgur.com/user1.jpg", "cover": "https://i.imgur.com/user1_cover.jpg" } } ``` ##### Failure ``` { "status": "failure", "message": "Password & ConfirmPassword are different!" }, { "status": "failure", "message": "email: 'root@example.com' has already existed!" }, { "status": "failure", "message": "account: '@root' has already existed!" } ``` &nbsp; <br> ## Tweets ``` path: routes/tweets.js controller: controllers/tweetController.js ``` ### readTweets #### Method & URL ``` GET /api/tweets ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` [ { "id": 1, "UserId": 11, "description": "Molestias dolor voluptatibus eveniet et cupiditate ipsum aperiam eius necessitatibus. Facilis voluptas exercitationem ut consequatur maxime eligendi optio. Provident reiciendis labore voluptates mollitia quasi harum sed rerum debitis. Et voluptas aut placeat. Id cum animi soluta consequuntur odit est porro.", "createdAt": "2020-12-16T08:46:08.000Z", "updatedAt": "2020-12-16T08:46:08.000Z", "User": { "id": 11, "account": "@user1", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=60.45057970816829" }, "isLiked": false, "repliedCount": 3, "LikeCount": 0 }, {...}, {...}, ... ] ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### postTweet #### Method & URL ``` POST /api/tweets ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | description | require | String | #### Response ##### Success ``` { "message": "tweet was successfully created", "tweet": { "id": 501, "description": "1234567", "UserId": 11, "updatedAt": "2020-12-18T03:29:44.175Z", "createdAt": "2020-12-18T03:29:44.175Z" } } ``` ##### Failure ``` { "status": "failure", "message": "number of the words is between 1 ~ 140" }, { "status": "failure", "message": "description didn't exist" } ``` ### readTweet #### Method & URL ``` GET /api/tweets/:id ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "id": 501, "UserId": 11, "description": "1234567", "createdAt": "2020-12-18T03:29:44.000Z", "updatedAt": "2020-12-18T03:29:44.000Z", "User": { "id": 11, "account": "@user1", "name": "user1", "avatar": "https://loremflickr.com/320/240/avatar/?random=60.45057970816829" }, "isLiked": false, "repliedCount": 0, "LikeCount": 0 } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### updateTweet* #### Method & URL ``` PUT /api/tweets/:tweetId ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | description | require | String | #### Response ##### Success ``` { "message": "OK", "tweets": { "id": "1", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "UserId": "1", } } ``` ##### Failure ``` { "status": "failure", "message": "number of the words is between 1 ~ 140" } ``` ### deleteTweet* #### Method & URL ``` DELETE /api/tweets/:id ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Response ##### Success ``` { "message": "OK", "tweets": { "id": "1", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "UserId": "1", } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` &nbsp; <br> ## Replies ``` path: routes/tweets.js controller: controllers/replyController.js ``` ### readReplies #### Method & URL ``` GET /api/tweets/:id/replies ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Response ##### Success ``` { "message": "OK", "replies": [ { "id": 31, "UserId": 41, "TweetId": 11, "comment": "Sed voluptas dignissimos vitae quod sed possimus necessitatibus incidunt quis. Velit optio fugiat. Quo dolore ut error nisi dolorem beatae qui fugit. Similique assumenda tenetur nemo illum eligendi adipisci. Blanditiis voluptatem porro beatae.", "createdAt": "2020-12-16T07:38:05.000Z", "updatedAt": "2020-12-16T07:38:05.000Z", "User": { "id": 41, "email": "user4@example.com", "password": "$2a$10$J/h9rW.IX.OrE2xVNhcrBue/4VWKXOMW.bs1.UPqRoKuBHVzQRyFe", "name": "user4", "avatar": "https://loremflickr.com/320/240/avatar/?random=44.52934043122782", "introduction": "Illo laborum nesciunt dolor nihil.", "isAdmin": false, "account": "@user4", "cover": "https://loremflickr.com/320/240/background/?random=83.0081940325029", "createdAt": "2020-12-16T07:38:05.000Z", "updatedAt": "2020-12-16T07:38:05.000Z" } }, {...}, {...}, ... ] } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### postReply #### Method & URL ``` POST /api/tweets/:tweetId/replies ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | x | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | comment | require | String | #### Response ##### Success ``` { "message": "OK", "reply": { "id": 1492, "comment": "123456", "TweetId": "11", "UserId": 21, "updatedAt": "2020-12-16T15:47:05.468Z", "createdAt": "2020-12-16T15:47:05.468Z" } } ``` ##### Failure ``` { "status": "failure", "message": "number of the words can't be less than 1" } ``` ### updateReply* #### Method & URL ``` PUT /api/tweets/:tweetId/replies/:replyId ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | comment | require | String | #### Response ##### Success ``` { "message": "OK", "reply": { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "UserId": "1", "TweetId": "7" } } ``` ##### Failure ``` { "status": "failure", "message": "number of the words can't be less than 1" } ``` ### deleteReply* #### Method & URL ``` DELETE /api/tweets/:tweetId/replies/:replyId ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | or | | authUser | isTheLoginUser | or | #### Response ##### Success ``` { "message": "OK", "reply": { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "comment": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "UserId": "1", "TweetId": "7" } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` &nbsp; <br> ## Likes ``` path: routes/tweets.js controller: controllers/likeController.js ``` ### like #### Method & URL ``` POST /api/tweets/:tweetId/like ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Response ##### Success ``` { "message": "OK", "like": { "id": 12, "UserId": 11, "TweetId": "11", "updatedAt": "2020-12-16T16:03:25.337Z", "createdAt": "2020-12-16T16:03:25.337Z" } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" }, { "status": "failure", "message": "Already Liked" } ``` ### unlike #### Method & URL ``` POST /api/tweets/:tweetId/unlike ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Response ##### Success ``` { "message": "OK", "unliked": { "id": 23, "UserId": 11, "TweetId": 11, "createdAt": "2020-12-17T03:13:12.000Z", "updatedAt": "2020-12-17T03:13:12.000Z" } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` &nbsp; <br> ## Followship ``` path: routes/followships.js controller: controllers/followshipController.js ``` ### follow #### Method & URL ``` POST /api/followships ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | id | require | Integer | #### Response ##### Success ``` { "message": "OK", "following": { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "followerId": "1", "followingId": "7" } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` ### unfollow #### Method & URL ``` DELETE /api/followships/:followingId ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isTheLoginUser | require | #### Response ##### Success ``` { "message": "OK", "following": { "id": "3", "ceatedAt": "Wed Dec 09 2020 14:34:22 GMT+0800 (Taipei Standard Time)", "followerId": "1", "followingId": "7" } } ``` ##### Failure ``` { "status": "failure", "message": "Errors" } ``` &nbsp; <br> ## Chat ``` path: routes/chat.js controller: controllers/chatController.js ``` ### initiate #### Method & URL ``` GET /api/chat/initiate ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isUser | require | #### Model.static ```javascript= ChatRoomModel.initiateChat(allUserIds, type, chatInitiator) ``` ### getRecentConversation #### Method & URL ``` GET /api/chat ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isUser | require | #### Model.static ```javascript= ChatRoomModel.getChatRoomsByUserId(currentLoggedUser) ChatMessageModel.getRecentConversation(roomIds, options, currentLoggedUser) ``` ### getConversationByRoomId #### Method & URL ``` GET /api/chat/:roomId ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isUser | require | #### Model.static ```javascript= ChatRoomModel.getChatRoomByRoomId(roomId) UserModel.getUserByIds(room.userIds) ChatMessageModel.getConversationByRoomId(roomId, options) ``` ### postMessage #### Method & URL ``` POST /api/chat/:roomId/message ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isUser | require | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | | require | | #### Model.static ```javascript= ChatMessageModel.createPostInChatRoom(roomId, messagePayload, currentLoggedUser) ``` #### Socket ```javascript= global.io.sockets.in(roomId).emit('new message', { message: post }) ``` ### markConversationReadByRoomId #### Method & URL ``` POST /api/chat/:roomId/mark-read ``` #### Authentication | Middleware | status | Require | | ------------- | -------------- | -------- | | authenticate | isLogin | require | | authAdmin | isAdmin | x | | authUser | isUser | require | #### Parameters | Params | Require | Type | | -------- | -------- | -------- | | | require | | #### Model.static ```javascript= ChatRoomModel.getChatRoomByRoomId(roomId) ChatMessageModel.markMessageRead(roomId, currentLoggedUser) ```