Skip to content

This is Social media app Backend here user can register with valid credentials and user can add post , make friends , send friend request ,see all the friends lists and comment on their post , edit comment , delete comment and remove friend from friend lists.

Notifications You must be signed in to change notification settings

Amanmandal-M/Mock_9_Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Social Media App Backend

About


This is Social media app Backend here user can register with valid credentials and user can add post , make friends , send friend request ,see all the friends lists and comment on their post , edit comment , delete comment and remove friend from friend lists.


Clone a Repository

https://github.com/Amanmandal-M/Mock_9_Backend.git

Installation

npm install

Note : Don't need to install packages if you only use this command all the packages automatically install if you want to add more packages then you have to write this command npm install <your package name>.

Start the Backend server

npm run start

npm run server

node index.js

nodemon start

nodemon index.js

Note : You can use any of them .


MVC Structure

├── index.js
├── configs
|    └── db.js
├── models
|    └── userModel.js
|    └── postModel.js
├── routes
|    └── userRoute.js
|    └── postRoute.js
├──middlewares
|    └── authenticationMiddleware.js
├──controllers
|    └── userController.js
|    └── postController.js

Note :

  • Before doing anything first create .env file and put PORT , MONGO_URL.
  • PORT is for listening the server.
  • MONGO_URL is for running database and store your data in database so put your mongo link.

Schema Design


User Schema

{
  _id: ObjectId,
  name: String,
  email: String,
  password: String,
  dob: Date,
  bio: String,
  posts: [{ type: ObjectId, ref: 'Post' }],
  friends: [{ type: ObjectId, ref: 'User' }],
  friendRequests: [{ type: ObjectId, ref: 'User' }]
}

Post Schema

{
  _id: ObjectId,
  user: { type: ObjectId, ref: 'User' },
  text: String,
  image: String,
  createdAt: Date,
  likes: [{ type: ObjectId, ref: 'User' }],
  comments: [{
    user: { type: ObjectId, ref: 'User' },
    text: String,
    createdAt: Date
  }]
}

Endpoints

METHOD ENDPOINT DESCRIPTION STATUS CODE
POST /api/register This endpoint should allow users to register. Hash the password on store. 201
POST /api/login This endpoint should allow users to login. Return JWT token on successful login 201
GET /api/users This endpoint should return a list of all registered users. 200
GET /api/users/:id/friends This endpoint should return a list of all registered users. 200
POST /api/users/:id/friends This endpoint should return a list of all friends of a specific user identified by its ID. 201
PUT / PATCH /api/users/:id/friends/:friendId This endpoint should allow the user to send a friend request to another user identified by its ID. (Protected Route) 204
GET /api/posts This endpoint should return a list of all posts. 200
POST /api/posts This endpoint should return a list of all posts. 201
PUT / PATCH /api/posts/:id This endpoint should allow users to update the text or image of a specific post identified by its ID. (Protected Route) 204
DELETE /api/posts/:id This endpoint should allow users to delete a specific post identified by its ID. (Protected Route) 202
POST /api/posts/:id/like This endpoint should allow users to like a specific post identified by its ID. (Protected Route) 201
POST /api/posts/:id/comment This endpoint should allow users to comment on a specific post identified by its ID.(Protected Route) 201
GET /api/posts/:id This endpoint should return the details of a specific post identified by its ID. 200

Problem Statement :

About

This is Social media app Backend here user can register with valid credentials and user can add post , make friends , send friend request ,see all the friends lists and comment on their post , edit comment , delete comment and remove friend from friend lists.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published