Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smoke221/all-sports-backend
https://github.com/smoke221/all-sports-backend
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/smoke221/all-sports-backend
- Owner: Smoke221
- Created: 2024-07-24T07:04:57.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-24T14:16:23.000Z (5 months ago)
- Last Synced: 2024-07-25T13:22:53.055Z (5 months ago)
- Language: JavaScript
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# E-Commerce Application for Allsport.in Backend Engineer Position
## Overview
This is an e-commerce application with RESTful API endpoints to manage products and categories. It includes functionality for user registration and login using JWT for authentication.
---
## Project Setup
### Prerequisites
- Node.js (v14.x or later)
- MySQL (v8.x or later)### Installation
1. **Clone the Repository**
```bash
git clone https://github.com/Smoke221/all-sports-backend
cd all-sports-backend
```2. **Install Dependencies**
```bash
npm install
```3. Setup Environment Variables
Create a `.env` file in the root directory of the project and add the following variables:
```plaintext
DB_HOST=your_mysql_host
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=your_mysql_database
JWT_SECRET=your_jwt_secret
```4. **Database Setup**
Make sure MySQL is running and create the required database and tables. You can use the provided SQL scripts or manually create them.Example SQL for creating categories and products tables:
```
CREATE TABLE categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL
);CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
category_id INT,
FOREIGN KEY (category_id) REFERENCES categories(id)
);
```
5. **Start the application**
```
npm start
```## API Endpoints
Try out using Swagger [here](http://localhost:5700/api-docs/#/)
### Authentication
- **Register a New User**
- **Endpoint:** `POST /auth/register`- **Login User**
- **Endpoint:** `POST /auth/login`### Categories
- **Retrieve All Categories**
- **Endpoint:** `GET /categories`- **Retrieve a Category by ID**
- **Endpoint:** `GET /categories/{id}`- **Create a New Category**
- **Endpoint:** `POST /categories`- **Update a Category by ID**
- **Endpoint:** `PUT /categories/{id}`- **Delete a Category by ID**
- **Endpoint:** `DELETE /categories/{id}`### Products
- **Retrieve All Products**
- **Endpoint:** `GET /products`- **Retrieve a Product by ID**
- **Endpoint:** `GET /products/{id}`- **Create a New Product**
- **Endpoint:** `POST /products`- **Update a Product by ID**
- **Endpoint:** `PUT /products/{id}`- **Delete a Product by ID**
- **Endpoint:** `DELETE /products/{id}`