[PC Hardware Store API]
For detailed API documentation, visit API Documentation.
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login a userPOST /api/v1/auth/logout
- Logout a user
POST /api/v1/products
- Create a new product (Admin only)GET /api/v1/products
- Get all productsGET /api/v1/products/:id
- Get a single product by IDPATCH /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
POST /api/v1/categories
- Create a new category (Admin only)GET /api/v1/categories
- Get all categoriesGET /api/v1/categories/:id
- Get a single category by IDPATCH /api/v1/categories/:id
- Update a category by ID (Admin only)DELETE /api/v1/categories/:id
- Delete a category by ID (Admin only)
POST /api/v1/orders
- Create a new orderGET /api/v1/orders
- Get all orders (Admin only)GET /api/v1/orders/:id
- Get a single order by IDPATCH /api/v1/orders/:id
- Update order status by ID (Admin only)
POST /api/v1/reviews
- Create a new reviewGET /api/v1/reviews
- Get all reviewsGET /api/v1/reviews/:id
- Get a single review by IDPATCH /api/v1/reviews/:id
- Update a review by IDDELETE /api/v1/reviews/:id
- Delete a review by IDGET /api/v1/reviews/product/:id
- Get all reviews for a single product
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.
- 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.
- 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.
- 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).
- 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).
- 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.
- Node.js
- Express.js
- MongoDB
- Mongoose
- Stripe API (for payment processing)
- Cloudinary (for image uploads)
- JWT (for authentication)
- Postman (for testing API endpoints)
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
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
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.
This project is licensed under the MIT License.