GithubHelp home page GithubHelp logo

nodejs-intern-assignment-3-submission's Introduction

#Nodejs intern assignment-3 submission To design and implement a RESTful APII for a basic social networking application using Node.js and MongoDB. The application should have the following functionalities:

  1. User registration
  2. User login
  3. Post a message
  4. Get all posts of a user
  5. Follow a user
  6. Get all followers of a user
  7. Get all followings of a user
  8. Get the posts of a user

Table of Contents

Deployment Link

The application has been deployed on render. The application can be accessed using the following link: https://nodejs-intern-assignment-3-submission-igb7.onrender.com

Installation

  1. Clone the repository
git clone https://github.com/0ju1c3/Nodejs-intern-assignment-3-submission.git
  1. Install the dependencies
npm install
  1. Start the server
npm start

ENV Variables

The following environment variables are required for the application to run:

JWT_SECRET=your-secret-key
CONNECTION_STRING=mongodb://username:password@host:port/database?options
PORT=3000

Usage

The application can be used to create a basic social networking application. The application can be used to register users, login, post messages, follow users, get followers, get followings, and get posts of a user.

API Endpoints

The following are the API endpoints of the application:

  1. User registration

Endpoint : /users/register Method: POST Description: Register a new user Request Body:

{
    "username":"string",
    "bio":"string",
    "profilePictureUrl":"string",
    "password":"string",
    "confirmPassword":"string"
}

Response Format:

{
    "accessToken": "string"
}
  1. User login Endpoint : /users/login Method: POST Description: Login a user Request Body:
{
    "username":"string",
    "password":"string"
}

response format:

{
    "accessToken": "string"
}
  1. Profile Endpoint : /users/profile Method: GET Description: Get the profile of the logged in user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Format:

{
    "userId": "string",
    "username": "string",
    "bio": "string",
    "profilePictureUrl": "string",
    "NoFollowers":"number",
    "NoFollowings":"number",
    "NoPosts":"number"
}
  1. Update Profile Endpoint : /users/profile Method: PUT Description: Update the profile of the logged in user Request Headers:
{
    "Authorization":"Bearer accessToken"
    "bio":"string",
    "profilePictureUrl":"string",
    "password":"string",
}

Response Format:

{
    "userId": "string",
    "username": "string",
    "bio": "string",
    "profilePictureUrl": "string",
    "NoFollowers":"number",
    "NoFollowings":"number",
    "NoPosts":"number"
}
  1. Post a message Endpoint : /posts Method: POST Description: Post a message Request Headers:
{
    "Authorization":"Bearer accessToken"
    "title":"string",
    "content":"string"
}

Response Format:

{
    "userId": "string",
    "username": "string",
    "title": "string",
    "content": "string",
    "_id": "string",
    "createdAt": "string",
    "updatedAt": "string"
}
  1. Get a post of a user Endpoint : /posts/:postId Method: GET Description: Get a post of a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "userId": "string",
    "username": "string",
    "title": "string",
    "content": "string",
    "_id": "string",
    "createdAt": "string",
    "updatedAt": "string"
}
  1. Get all posts of a user Endpoint : /posts Method: GET Description: Get all posts of a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    {

        "userId": "string",
            "username": "string",
            "title": "string",
            "content": "string",
            "_id": "string",
            "createdAt": "string",
            "updatedAt": "string"
    },
}
  1. Update a post Endpoint : /posts/:postId Method: PUT Description: Update a post Request Headers:
{
    "Authorization":"Bearer accessToken",
    "title":"string",
    "content":"string"
}

Response Headers:

{
    "_id": "string",
    "userId": "string",
    "username": "string",
    "title": "string",
    "content": "string",
    "createdAt": "string",
    "updatedAt": "string"
}
  1. Delete a post Endpoint : /posts/:postId Method: DELETE Description: Delete a post Request Headers:
{
    "Authorization":"Bearer accessToken"
}   

Response Headers:

{
    "message": "Post removed"
}
  1. Get all Users Endpoint : /follow Method: GET Description: Get all users Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "users": [
        {
            "_id": "string",
            "userId": "string",
            "username": "string",
            "bio": "string",
            "profilePictureUrl": "string",
        }
    ]
}
  1. Get a User Endpoint : /follow/:userId Method: GET Description: Get a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "user": {
        "_id": "string",
        "userId": "string",
        "username": "string",
        "bio": "string",
        "profilePictureUrl": "string",
        "NoFollowers":"number",
        "NoFollowings":"number",
        "NoPosts":"number"
    }
}
  1. Follow a user Endpoint : /follow/user/:userId Method: POST Description: Follow a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "userId":"string",
    "username":"string",
    "followingId":"string",
    "following":"string"
}
  1. Get followings of a user Endpoint : /follow/followings Method: GET Description: Get followings of a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    {
        "followingId":"string",
        "following":"string"
    }
}
  1. Get followers of a user Endpoint : /follow/followers Method: GET Description: Get followers of a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    {
        "followerId":"string",
        "follower":"string"
    }
}
  1. Unfollow a user Endpoint : /follow/:userId Method: DELETE Description: Unfollow a user Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "message": "User unfollowed"
}
  1. Get posts of followings Endpoint : /follow/posts Method: GET Description: Get posts of followings Request Headers:
{
    "Authorization":"Bearer accessToken"
}

Response Headers:

{
    "posts": [
        {
            "userId": "string",
            "username": "string",
            "title": "string",
            "content": "string",
        }
    ]
}

Database Schema

User-Fields

The users collection stores information about registered users.

  • _id: ObjectId (automatically generated)
  • userId: String (generated using uuidv4, required, unique) - Unique identifier for the user.
  • username: String (required, unique) - The username of the user.
  • bio: String - The biography or additional information about the user.
  • profilePictureUrl: String - The URL of the user's profile picture.
  • password: String (required) - The hashed password of the user.
  • NoFollowers: Number (default: 0) - The number of followers for the user.
  • NoFollowing: Number (default: 0) - The number of users the user is following.
  • NoPosts: Number (default: 0) - The total number of posts created by the user.
  • createdAt: Date (automatically generated) - The timestamp when the user was created.
  • updatedAt: Date (automatically generated) - The timestamp when the user was last updated.

Post-Fields

The posts collection stores information about the posts created by users.

  • _id: ObjectId (automatically generated)
  • userId: String (required, reference to User collection) - The unique identifier of the user who created the post.
  • username: String (required, reference to User collection) - The username of the user who created the post.
  • title: String (required) - The title of the post.
  • content: String (required) - The content or body of the post.
  • createdAt: Date (automatically generated) - The timestamp when the post was created.
  • updatedAt: Date (automatically generated) - The timestamp when the post was last updated.

Relationships

  • userId: References the User collection using the userId field.
  • username: References the User collection using the username field.

Follow-Fields

The follows collection stores information about the users that a user is following and the users that are following the user.

  • _id: ObjectId (automatically generated)
  • followerId: String (required, reference to User collection) - The unique identifier of the follower user.
  • follower: String (required, reference to User collection) - The username of the follower user.
  • followingId: String (required, reference to User collection) - The unique identifier of the user being followed.
  • following: String (required, reference to User collection) - The username of the user being followed.
  • createdAt: Date (automatically generated) - The timestamp when the follow relationship was created.
  • updatedAt: Date (automatically generated) - The timestamp when the follow relationship was last updated.

Relationships

  • followerId: References the User collection using the followerId field.
  • follower: References the User collection using the follower field.
  • followingId: References the User collection using the followingId field.
  • following: References the User collection using the following field.

Integration Testing

The application has been tested using Collection Runner in Postman. The tests include the following:

  1. User registration
  2. User login
  3. User profile
  4. Update profile
  5. Delete user
  6. Post a message
  7. Update a post
  8. Get all Posts
  9. Get a post
  10. Delete a post
  11. Get all Users
  12. Get a User
  13. Follow a user
  14. Get followings of the current user
  15. Get followers of the current user
  16. Unfollow a user
  17. Get posts of followings

The tests have been written to ensure that the API endpoints are working as expected and that the responses are correct. To run the tests, import the Node Assignment.postman_collection.json file in the test directiory and run the collection.

nodejs-intern-assignment-3-submission's People

Contributors

0ju1c3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.