Express App Assignment

 

Todo Application

Given an

app.js
file and database file
todoApplication.db
with a table
todo
.

Write APIs to perform operations on the table

todo
, with the following columns,

Todo Table

ColumnType
idINTEGER
todoTEXT
categoryTEXT
priorityTEXT
statusTEXT
due_dateDATE
Note
  • Replace the spaces in URL with 
    %20
    .
  • Possible values for 
    priority
     are 
    HIGH
    MEDIUM
    , and 
    LOW
    .
  • Possible values for 
    status
     are 
    TO DO
    IN PROGRESS
    , and 
    DONE
    .
  • Possible values for 
    category
     are 
    WORK
    HOME
    , and 
    LEARNING
    .
  • Use the format 
    yyyy-MM-dd
     for formating with date-fns 
    format
     function.
  • The user may request with due date value as 
    2021-1-21
    , format the date to 
    2021-01-21
     and perform Create, Read, Update operations on the database.
Quick Tip
Use 
date-fns
 format function to format the date. Refer to the documentation link for the usage of the 
format
 function.

Invalid scenarios for all APIs

  • Invalid Status
    • Response
    • Status code 
      400
    • Body 
      Invalid Todo Status
  • Invalid Priority
    • Response
    • Status code 
      400
    • Body 
      Invalid Todo Priority
  • Invalid Category

    • Response
    • Status code 
      400
    • Body 
      Invalid Todo Category
  • Invalid Due Date

    • Response
    • Status code
      400
    • Body
      Invalid Due Date

API 1

Path: 
/todos/

Method: 
GET

  • Scenario 1

    • Sample API 
      /todos/?status=TO%20DO
    • Description:

    Returns a list of all todos whose status is 'TO DO'

    • Response
    [
    {
    "id": 2,
    "todo": "Buy a Car",
    "priority": "MEDIUM",
    "status": "TO DO",
    "category": "HOME",
    "dueDate": "2021-09-22"
    },
    ...
    ]
     
  • Scenario 2

    • Sample API 
      /todos/?priority=HIGH
    • Description:

    Returns a list of all todos whose priority is 'HIGH'

    • Response
    [
    {
    "id": 1,
    "todo": "Learn Node JS",
    "priority": "HIGH",
    "status": "IN PROGRESS",
    "category": "LEARNING",
    "dueDate": "2021-03-16"
    },
    ...
    ]
     
  • Scenario 3

    • Sample API 
      /todos/?priority=HIGH&status=IN%20PROGRESS
    • Description:

    Returns a list of all todos whose priority is 'HIGH' and status is 'IN PROGRESS'

    • Response
    [
    {
    "id": 1,
    "todo": "Learn Node JS",
    "priority": "HIGH",
    "status": "IN PROGRESS",
    "category": "LEARNING",
    "dueDate": "2021-03-16"
    },
    ...
    ]
     
  • Scenario 4

    • Sample API 
      /todos/?search_q=Buy
    • Description:

    Returns a list of all todos whose todo contains 'Buy' text

    • Response
    [
    {
    "id": 2,
    "todo": "Buy a Car",
    "priority": "MEDIUM",
    "status": "TO DO",
    "category": "HOME",
    "dueDate": "2021-09-22"
    },
    ...
    ]
     
  • Scenario 5

    • Sample API 
      /todos/?category=WORK&status=DONE
    • Description:

    Returns a list of all todos whose category is 'WORK' and status is 'DONE'

    • Response
    {
    "id": 4,
    "todo": "Fix the bug",
    "priority": "MEDIUM",
    "status": "DONE",
    "category": "WORK",
    "dueDate": "2021-01-25"
    },
    ...
    ]
     
  • Scenario 6

    • Sample API 
      /todos/?category=HOME
    • Description:

    Returns a list of all todos whose category is 'HOME'

    • Response
    [
    {
    "id": 2,
    "todo": "Buy a Car",
    "priority": "MEDIUM",
    "status": "TO DO",
    "category": "HOME",
    "dueDate": "2021-09-22"
    },
    ...
    ]
     
  • Scenario 7

    • Sample API 
      /todos/?category=LEARNING&priority=HIGH
    • Description:

    Returns a list of all todos whose category is 'LEARNING' and priority is 'HIGH'

    • Response
    [
    {
    "id": 1,
    "todo": "Learn Node JS",
    "priority": "HIGH",
    "status": "IN PROGRESS",
    "category": "LEARNING",
    "dueDate": "2021-03-16"
    },
    ...
    ]
     

API 2

Path: 
/todos/:todoId/

Method: 
GET

Description:

Returns a specific todo based on the todo ID

Response

{
"id": 1,
"todo": "Learn Node JS",
"priority": "HIGH",
"status": "IN PROGRESS",
"category": "LEARNING",
"dueDate": "2021-03-16"
}

API 3

Path: 
/agenda/

Method: 
GET

Description:

Returns a list of all todos with a specific due date in the query parameter

/agenda/?date=2021-12-12

Response

{
"id": 3,
"todo": "Clean the garden",
"priority": "LOW",
"status": "TO DO",
"category": "HOME",
"dueDate": "2021-12-12"
},
...
]
 

API 4

Path: 
/todos/

Method: 
POST

Description:

Create a todo in the todo table,

Request

{
"id": 6,
"todo": "Finalize event theme",
"priority": "LOW",
"status": "TO DO",
"category": "HOME",
"dueDate": "2021-02-22"
}

Response

Todo Successfully Added

API 5

Path: 
/todos/:todoId/

Method: 
PUT

Description:

Updates the details of a specific todo based on the todo ID

  • Scenario 1

    • Request 
      { "status": "DONE" }
    • Response
    Status Updated
  • Scenario 2

    • Request 
      { "priority": "HIGH" }
    • Response
    Priority Updated
  • Scenario 3

    • Request
    {
    "todo": "Clean the garden"
    }
    • Response
    Todo Updated
  • Scenario 4

    • Request 
      { "category": "LEARNING" }
    • Response
    Category Updated
  • Scenario 5

    • Request 
      { "dueDate": "2021-01-12" }
    • Response
    Due Date Updated

API 6

Path: 
/todos/:todoId/

Method: 
DELETE

Description:

Deletes a todo from the todo table based on the todo ID

Response

Todo Deleted

Use

npm install
to install the packages.

Export the express instance using the default export syntax.

Use Common JS module syntax.

Twitter

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

ColumnType
user_idINTEGER
nameTEXT
usernameTEXT
passwordTEXT
genderTEXT

Follower Table

ColumnType
follower_id
INTEGER
follower_user_id
INTEGER
following_user_id
INTEGER

Here, if user1 follows user2 then,

follower_user_id
is the user ID of user1 and
following_user_id
is the user ID of user2.

Tweet Table

ColumnType
tweet_idINTEGER
tweetTEXT
user_idINTEGER
date_timeDATETIME

Reply Table

ColumnType
reply_idINTEGER
tweet_idINTEGER
replyTEXT
user_idINTEGER
date_timeDATETIME

Like Table

ColumnType
like_idINTEGER
tweet_idINTEGER
user_idINTEGER
date_timeDATETIME

Sample Valid User Credentials

{
"username":"JoeBiden",
"password":"biden@123"
}

API 1

Path: 
/register/

Method: 
POST

Request

{
"username": "adam_richard",
"password": "richard_567",
"name": "Adam Richard",
"gender": "male"
}
  • Scenario 1

    • Description:

      If the username already exists

    • Response

      • Status code
        400
      • Body
        User already exists

  • Scenario 2

    • Description:

      If the registrant provides a password with less than 6 characters

    • Response

      • Status code
        400
      • Body
        Password is too short

  • Scenario 3

    • Description:

      Successful registration of the registrant

    • Response

      • Status code

        200
      • Body

        User created successfully

API 2

Path: 
/login/

Method: 
POST

Request

{
"username":"JoeBiden",
"password":"biden@123"
}
  • Scenario 1

    • Description:

      If the user doesn't have a Twitter account

    • Response

      • Status code
        400
      • Body
        Invalid user

  • Scenario 2

    • Description:

      If the user provides an incorrect password

    • Response

      • Status code
        400
      • Body
        Invalid password

  • Scenario 3

    • Description:

      Successful login of the user

    • Response

      Return the JWT Token

      {
      "jwtToken": "ak2284ns8Di32......"
      }
       

Authentication with JWT Token

Write a middleware to authenticate the JWT token.

  • Scenario 1

    • Description:

      If the JWT token is not provided by the user or an invalid JWT token is provided

    • Response

      • Status code
        401
      • Body
        Invalid JWT Token

  • Scenario 2

    • After successful verification of JWT token, proceed to next middleware or handler

API 3

Path: 
/user/tweets/feed/

Method: 
GET

Description:

Returns the latest tweets of people whom the user follows. Return 4 tweets at a time

Response

[
{
username: "SrBachchan",
tweet: "T 3859 - do something wonderful, people may imitate it ..",
dateTime: "2021-04-07 14:50:19"
},
...
]
 

API 4

Path: 
/user/following/

Method: 
GET

Description:

Returns the list of all names of people whom the user follows

Response

[
{
"name": "Narendra Modi"
},
...
]

API 5

Path: 
/user/followers/

Method: 
GET

Description:

Returns the list of all names of people who follows the user

Response

[
{
"name": "Narendra Modi"
},
...
]

API 6

Path: 
/tweets/:tweetId/

Method: 
GET

  • Scenario 1

    • Description:

      If the user requests a tweet other than the users he is following

    • Response

      • Status code
        401
      • Body
        Invalid Request

  • Scenario 2

    • Description:

      If the user requests a tweet of the user he is following, return the tweet, likes count, replies count and date-time

    • Response

      { "tweet": "T 3859 - do something wonderful, people may imitate it ..", "likes": 3, "replies": 1, "dateTime": "2021-04-07 14:50:19" }

API 7

Path: 
/tweets/:tweetId/likes/

Method: 
GET

  • Scenario 1

    • Description:

      If the user requests a tweet other than the users he is following

    • Response

      • Status code
        401
      • Body
        Invalid Request

  • Scenario 2

    • 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 8

Path: 
/tweets/:tweetId/replies/

Method: 
GET

  • Scenario 1

    • Description:

      If the user requests a tweet other than the users he is following

    • Response

      • Status code
        401
      • Body
        Invalid Request

  • Scenario 2

    • Description:

      If the user requests a tweet of a user he is following, return the list of replies.

    • Response

      ```
      {
      "replies": [
      {
      "name": "Narendra Modi",
      "reply": "When you see it.."
      },
      ...]
      }
      ```
       

API 9

Path: 
/user/tweets/

Method: 
GET

Description:

Returns a list of all tweets of the user

Response

[
{
"tweet": "Ready to don the Blue and Gold",
"likes": 3,
"replies": 4,
"dateTime": "2021-4-3 08:32:44"
},
...
]
 

API 10

Path: 
/user/tweets/

Method: 
POST

Description:

Create a tweet in the tweet table

Request

{
"tweet": "The Mornings..."
}

Response

Created a Tweet

API 11

Path: 
/tweets/:tweetId/

Method: 
DELETE

  • Scenario 1

    • Description:

      If the user requests to delete a tweet of other users

    • Response

      • Status code
        401
      • Body
        Invalid Request

  • Scenario 2

    • 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.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form