Skip to content

This Api is for the Socio social media application. It provides endpoints for user authentication, post management, user management, and more.

Notifications You must be signed in to change notification settings

gurdeepsingh-hub/Socio-Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socio API

This repository contains the backend code for the Socio social media application. It provides endpoints for user authentication, post management, user management, and more.

Technologies Used:

  • Express.js: Framework for building the RESTful API.
  • MongoDB: NoSQL database used for storing user data, posts, and comments.
  • Mongoose: MongoDB object modeling tool used for interacting with the database.
  • Bcrypt: Library for hashing passwords.
  • JSON Web Tokens (JWT): Used for user authentication and authorization.
  • Nodemailer: Module for sending emails, used for features like password reset.
  • Multer: Middleware for handling file uploads.
  • Helmet: Middleware for securing Express apps with various HTTP headers.
  • Morgan: HTTP request logger middleware.

Project Structure:

  • index.js: Entry point of the application. Sets up the Express server, connects to MongoDB, defines middleware, and specifies route handling.
  • models: Directory containing Mongoose schemas for defining the structure of data stored in MongoDB.
    • Post.js: Defines the schema for posts, including fields like user ID, description, image, likes, and comments.
    • User.js: Defines the schema for users, including fields like username, email, password, profile picture, followers, and following.
  • routes: Directory containing route handlers for different endpoints.
    • auth.js: Handles user registration, login, username/email availability checks, and password reset.
    • email.js: Provides functionality for sending emails, including a test email feature.
    • posts.js: Handles CRUD operations for posts, including creation, updating, deletion, liking, commenting, and retrieval.
    • users.js: Handles user-related operations such as updating user profiles, deleting accounts, searching for users, following/unfollowing users, and retrieving user details.
  • public/images: Directory for storing uploaded images.
  • assets: Directory containing helper functions for JWT token creation and email sending.

Setup:

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Set up a MongoDB database and provide the connection URL in a .env file.
  4. Set up SMTP credentials for sending emails and provide them in the .env file.
  5. Run the server using npm start.

API Endpoints:

  • /api/auth/register: POST request to register a new user.
  • /api/auth/login: POST request to log in an existing user.
  • /api/auth/relogin: POST request to re-login a user.
  • /api/auth/forgot-password: POST request to initiate the password reset process.
  • /api/posts: POST request to create a new post.
  • /api/posts/:id: PUT request to update a post, DELETE request to delete a post, GET request to retrieve a post by ID.
  • /api/posts/:id/like: PUT request to like/unlike a post.
  • /api/posts/:id/comment: PUT request to add a comment to a post, PUT request to delete a comment from a post.
  • /api/posts/timeline/:userId: GET request to retrieve timeline posts for a user.
  • /api/posts/profile/:userId: GET request to retrieve profile posts for a user.
  • /api/users/:id: PUT request to update a user profile, DELETE request to delete a user account, GET request to retrieve user details.
  • /api/users/:identifier/search: GET request to search for users by username or first name.
  • /api/users/:id/follow: PUT request to follow a user, /api/users/:id/unfollow: PUT request to unfollow a user.

API Request Structures

This section outlines the structure of requests for each endpoint in the Socio API.

User Authentication

Register User

  • Endpoint: /api/auth/register
  • Method: POST
  • Request Body:
    {
      "username": "String",
      "email": "String",
      "password": "String",
      "firstName": "String",
      "lastName": "String",
      "dob": "Date"
    }
  • Response: Newly created user object

User Login

  • Endpoint: /api/auth/login
  • Method: POST
  • Request Body:
    {
      "email": "String",
      "password": "String"
    }
  • Response: User object if successful, error message otherwise

User Relogin

  • Endpoint: /api/auth/relogin
  • Method: POST
  • Request Body:
    {
      "email": "String",
      "password": "String"
    }
  • Response: User object if successful, error message otherwise

Forgot Password

Post Management

Create Post

  • Endpoint: /api/posts
  • Method: POST
  • Request Body:
    {
      "userId": "String",
      "desc": "String",
      "img": "String"
    }
  • Response: Newly created post object

Update Post

  • Endpoint: /api/posts/:id
  • Method: PUT
  • Request Body:
    {
      "userId": "String",
      "desc": "String",
      "img": "String"
    }
  • Response: Status message

Delete Post

Get Post

Like/Unlike Post

  • Endpoint: /api/posts/:id/like
  • Method: PUT
  • Request Body:
    {
      "userId": "String"
    }
  • Response: Status message

Add Comment

  • Endpoint: /api/posts/:id/comment
  • Method: PUT
  • Request Body:
    {
      "userId": "String",
      "comment": "String",
      "virtId": "String"
    }
  • Response: Status message

Delete Comment

  • Endpoint: /api/posts/:id/del-comment
  • Method: PUT
  • Request Body:
    {
      "userId": "String",
      "comment": "String"
    }
  • Response: Status message

Get Timeline Posts

Get Profile Posts

User Management

Update User Profile

  • Endpoint: /api/users/:id
  • Method: PUT
  • Request Body:
    {
      "userId": "String",
      "username": "String",
      "email": "String",
      "password": "String",
      "firstName": "String",
      "lastName": "String",
      "dob": "Date",
      "profilePicture": "String",
      "coverPicture": "String",
      "desc": "String",
      "state": "String",
      "relationship": "Number"
    }
  • Response: Status message

Delete User Account

Get User Details

Search Users

Follow User

  • Endpoint: /api/users/:id/follow
  • Method: PUT
  • Request Body:
    {
      "userId": "String"
    }
  • Response: Status message

Unfollow User

Note:

  • Ensure proper configuration of environment variables for database connection, SMTP server, etc., before running the server.
  • Implement appropriate security measures, such as input validation, error handling, and authentication/authorization checks, to ensure the security of the application.
  • This README provides an overview of the API and its functionality. For detailed usage instructions and endpoint documentation, consider generating API documentation using tools like Swagger or Postman.

About

This Api is for the Socio social media application. It provides endpoints for user authentication, post management, user management, and more.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published