Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Twitter Given an app.js file and a database file twitterClone.db consisting of five tables user, follower, tweet, reply, and like. Write APIs to perform operations
Twitter
Given an app.js file and a database file twitterClone.db consisting of five tables user, follower, tweet, reply, and like.
Write APIs to perform operations on the tables user, follower, tweet, reply, and like containing the following columns,
User Table
Column Type
userid INTEGER
name TEXT
username TEXT
password TEXT
gender TEXT
Follower Table
Column Type
followerid INTEGER
followeruserid INTEGER
followinguserid INTEGER
Here, if user follows user then,
followeruserid is the user ID of user and followinguserid is the user ID of user
Tweet Table
Column Type
tweetid INTEGER
tweet TEXT
userid INTEGER
datetime DATETIME
Reply Table
Column Type
replyid INTEGER
tweetid INTEGER
reply TEXT
userid INTEGER
datetime DATETIME
Like Table
Column Type
likeid INTEGER
tweetid INTEGER
userid INTEGER
datetime DATETIME
Sample Valid User Credentials
API
API
Authentication with JWT Token
API
API
API
API
API
API
API
API
API
API
Path: register
Method: POST
Request
Scenario
Description:
If the username already exists
Response
Status code
Body
User already exists
Scenario
Description:
If the registrant provides a password with less than characters
Response
Status code
Body
Password is too short
Scenario
Description:
Successful registration of the registrant
Response
Status code
Body
User created successfully
API
Path: login
Method: POST
Request
Scenario
Description:
If the user doesn't have a Twitter account
Response
Status code
Body
Invalid user
Scenario
Description:
If the user provides an incorrect password
Response
Status code
Body
Invalid password
Scenario
Description:
Successful login of the user
Response
Return the JWT Token
Authentication with JWT Token
Write a middleware to authenticate the JWT token.
Scenario
Description:
If the JWT token is not provided by the user or an invalid JWT token is provided
Response
Status code
Body
Invalid JWT Token
Scenario
After successful verification of JWT token, proceed to next middleware or handler
API
Path: usertweetsfeed
Method: GET
Description:
Returns the latest tweets of people whom the user follows. Return tweets at a time
Response
API
Path: userfollowing
Method: GET
Description:
Returns the list of all names of people whom the user follows
Response
API
Path: userfollowers
Method: GET
Description:
Returns the list of all names of people who follows the user
Response
API
Path: tweets:tweetId
Method: GET
Scenario
Description:
If the user requests a tweet other than the users he is following
Response
Status code
Body
Invalid Request
Scenario
Description:
If the user requests a tweet of the user he is following, return the tweet, likes count, replies count and datetime
Response
"tweet": T do something wonderful, people may imitate it
"likes":
"replies":
"dateTime": ::
API
Path: tweets:tweetIdlikes
Method: GET
Scenario
Description:
If the user requests a tweet other than the users he is following
Response
Status code
Body
Invalid Request
Scenario
Description:
If the user requests a tweet of a user he is following, return the list of usernames who liked the tweet
Response
"likes": albert
API
Path: tweets:tweetIdreplies
Method: GET
Scenario
Description:
If the user requests a tweet other than the users he is following
Response
Status code
Body
Invalid Request
Scenario
Description:
If the user requests a tweet of a user he is following, return the list of replies.
Response
API
Path: usertweets
Method: GET
Description:
Returns a list of all tweets of the user
Response
API ii
Path: usertweets
Method: POST
Description:
Create a tweet in the tweet table
Request
Response
API
Path: tweets:tweetId
Method: DELETE
Scenario
Description:
If the user requests to delete a tweet of other users
Response
Status code
Body
Invalid Request
Scenario
Description:
If the user deletes his tweet
Response
Tweet Removed
Use npm install to install the packages.
Export the express instance using the default export syntax.
Use Common JS module syntax.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started