#Project Overview
The project is a simple web application for managing categories and products. It allows users to perform CRUD (Create, Read, Update, Delete) operations on categories and products.
##Project Structure
project/ │ ├── controllers/ # Contains controller logic │ ├── category_controller.js │ └── product_controller.js | └── home_controller.js │
├── models/ # Contains database models │ ├── db.js │
│ ├── routes/ # Contains route definitions │ ├── category.js │ └── product.js | └── index.js │
├── views/ # Contains view templates │ ├── category.ejs │ ├── editCategory.ejs │ ├── index.ejs │ ├── product.ejs │ └── editProduct.ejs |
├── index.js # Main application file ├── package.json # npm package file └── README.md # Project README
Required Files:
app.js: Main application file where the Express app is created and configured.
Controller files (category_controller.js and product_controller.js): Logic for handling HTTP requests and responses.
Model files (category.js and product.js): Database models using an ORM (Object-Relational Mapping) like Sequelize or Mongoose.
Route files (category_routes.js and product_routes.js): Route definitions for different endpoints.
View templates (.ejs files): HTML templates to render dynamic content.
Configuration file (db.js): Database configuration details.
API Endpoints:
Categories:
Get All Categories
Method: GET Endpoint: /categories Description: Retrieves all categories from the database. Input: None
Create Category
Method: POST Endpoint: /categories Description: Creates a new category in the database. Input: String: name (string): The name of the category.
Get Category by ID
Method: GET Endpoint: /categories/:id Description: Retrieves a specific category by its ID. Input: none.
Update Category by ID
Method: POST Endpoint: /categories/:id Description: Updates a category with the specified ID. Input: name (string): The updated name of the category.
Delete Category by ID
Method: DELETE Endpoint: /categories/:id Description: Deletes a category with the specified ID. Input: Path parameter id (integer): The ID of the category to delete. Products:
Get All Products
Method: GET Endpoint: /products Description: Retrieves all products from the database. Input: None
Create Product
Method: POST Endpoint: /products Description: Creates a new product in the database. Input: string: name (string): The name of the product.
get Product by id Method: GET Endpoint: /products/:id Description: Retrieves a specific product by its ID. Input: Path parameter id (integer): The ID of the product to retrieve.
Update Product by ID
Method: POST Endpoint: /products/:id Description: Updates a product with the specified ID. Input: updated name name (string): The updated name of the product. categoryId (integer): The updated ID of the category to which the product belongs.
Delete Product by ID
Method: DELETE Endpoint: /products/:id Description: Deletes a product with the specified ID.
Categories:
GET /categories: Get all categories
POST /categories: Create a new category
GET /categories/:id: Get a category by ID
POST /categories/:id: Update a category by ID
DELETE /categories/:id: Delete a category by ID
Products:
GET /products: Get all products
POST /products: Create a new product
GET /products/:id: Get a product by ID
POST /products/:id: Update a product by ID
DELETE /products/:id: Delete a product by ID
Project Setup Guide:
Clone the project repository from version control (e.g., Git).
Install Node.js and npm if not already installed on your system.
Navigate to the project directory in the terminal.
Run npm install to install project dependencies.
Set up your database and configure database connection details in config/db.js.
Run the database migration scripts to create the necessary tables.
Start the server by running npm start or node app.js.
Access the application in your web browser using the specified port (default is 3000).
This setup guide assumes you have Node.js, npm, and a database (e.g., MySQL) installed and configured on your system. Make sure to replace placeholder values with actual values according to your environment.
With this setup, you should have a functional web application for managing categories and products, with API endpoints for performing CRUD operations.