Skip to content

Khalil-IT/pc-hardware-store-api

 
 

Repository files navigation

[PC Hardware Store API]

API Documentation

For detailed API documentation, visit API Documentation.

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login a user
  • POST /api/v1/auth/logout - Logout a user

Products

  • POST /api/v1/products - Create a new product (Admin only)
  • GET /api/v1/products - Get all products
  • GET /api/v1/products/:id - Get a single product by ID
  • PATCH /api/v1/products/:id - Update a product by ID (Admin only)
  • DELETE /api/v1/products/:id - Delete a product by ID (Admin only)
  • POST /api/v1/products/uploadImage - Upload an image for a product

Categories

  • POST /api/v1/categories - Create a new category (Admin only)
  • GET /api/v1/categories - Get all categories
  • GET /api/v1/categories/:id - Get a single category by ID
  • PATCH /api/v1/categories/:id - Update a category by ID (Admin only)
  • DELETE /api/v1/categories/:id - Delete a category by ID (Admin only)

Orders

  • POST /api/v1/orders - Create a new order
  • GET /api/v1/orders - Get all orders (Admin only)
  • GET /api/v1/orders/:id - Get a single order by ID
  • PATCH /api/v1/orders/:id - Update order status by ID (Admin only)

Reviews

  • POST /api/v1/reviews - Create a new review
  • GET /api/v1/reviews - Get all reviews
  • GET /api/v1/reviews/:id - Get a single review by ID
  • PATCH /api/v1/reviews/:id - Update a review by ID
  • DELETE /api/v1/reviews/:id - Delete a review by ID
  • GET /api/v1/reviews/product/:id - Get all reviews for a single product

Description

The PC Hardware Store API is a comprehensive backend solution for managing an e-commerce platform that specializes in selling PC hardware components. It provides a robust set of features for handling user authentication, product management, order processing, category management, and reviews. The API integrates with Stripe for payment processing and Cloudinary for image uploads.

Features :

User Authentication and Management

  • Register: Create a new user account.
  • Login: Authenticate a user and generate a JWT token.
  • Logout: Invalidate the current user session.
  • Get All Users: Retrieve a list of all registered users (Admin only).
  • Get Single User: Retrieve details of a specific user (Admin only).
  • Show Current User: Retrieve details of the currently authenticated user.
  • Update User: Update user details (username and email).
  • Update User Password: Change the password of the currently authenticated user.

Product Management

  • Create Product: Add a new product to the catalog (Admin only).
  • Get All Products: Retrieve a list of all products with pagination, filtering, and sorting options.
  • Get Single Product: Retrieve details of a specific product.
  • Update Product: Update details of a specific product (Admin only).
  • Delete Product: Remove a product from the catalog (Admin only).
  • Upload Image: Upload an image for a product to Cloudinary.

Category Management

  • Create Category: Add a new category (Admin only).
  • Get All Categories: Retrieve a list of all categories.
  • Get Category By ID: Retrieve details of a specific category.
  • Update Category: Update details of a specific category (Admin only).
  • Delete Category: Remove a category (Admin only).

Order Management

  • Create Order: Create a new order with Stripe payment integration.
  • Get All Orders: Retrieve a list of all orders with product and user details (Admin only).
  • Get Order By ID: Retrieve details of a specific order.
  • Update Order Status: Update the payment status of an order (Admin only).

Review Management

  • Create Review: Add a new review for a product.
  • Get All Reviews: Retrieve a list of all reviews.
  • Get Review By ID: Retrieve details of a specific review.
  • Update Review: Update details of a specific review.
  • Delete Review: Remove a review.
  • Get Reviews for a Product: Retrieve all reviews for a specific product.

Technologies Used

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • Stripe API (for payment processing)
  • Cloudinary (for image uploads)
  • JWT (for authentication)
  • Postman (for testing API endpoints)

Filtering, Sorting, Pagination:

Paginate Products: GET /api/v1/products?limit=10&page=2

Sort Products: GET /api/v1/products?sort=price,-rating

Select Specific Fields: GET /api/v1/products?fields=name,price

Filter Products: In Stock: GET /api/v1/products?stockStatus=inStock By Brand: GET /api/v1/products?brand=Intel By Category: GET /api/v1/products?category=66a927e7efa8d286f95935cc By Name: GET /api/v1/products?name=Intel

Numeric Filters: GET /api/v1/products?numericFilters=price>100,rating>=4

Installation

1- Clone the repository: git clone https://github.com/HazemSarhan/pc-hardware-store-api.git cd pc-hardware-store-api

2- Install dependencies: npm install

3- Set up environment variables: Create a .env file in the root directory and add the following:

  • PORT=5000
  • MONGO_URI=your-mongodb-uri
  • JWT_SECRET=your-jwt-secret
  • JWT_LIFETIME=1d or 3d
  • STRIPE_SECRET_KEY=your-stripe-secret-key
  • CLOUD_NAME=your-cloudinary-cloud-name
  • CLOUD_API_KEY=your-cloudinary-api-key
  • CLOUD_API_SECRET=your-cloudinary-api-secret

4- Start the application: npm start

Usage

1- Register an account: Use the /api/v1/auth/register endpoint to create a new user account.

2- Login: Use the /api/v1/auth/login endpoint to authenticate a user and receive a JWT token.

3- Manage Products: Use the /api/v1/products endpoints to create, read, update, and delete products. Only admin users can create, update, and delete products.

4- Manage Categories: Use the /api/v1/categories endpoints to create, read, update, and delete categories. Only admin users can create, update, and delete categories.

5- Manage Orders: Use the /api/v1/orders endpoints to create and view orders. Only admin users can view all orders and update order status.

6- Manage Reviews: Use the /api/v1/reviews endpoints to create, read, update, and delete reviews. Users can leave reviews for products they have purchased.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.2%
  • HTML 1.9%
  • CSS 0.9%