Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
84 changes: 81 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,84 @@
## Product List
# Product Inventory App

This is a simple web application that allows users to browse and filter through a list of products fetched from a MongoDB database. The backend is built with Express.js to handle API requests and interact with the MongoDB database, while the frontend is developed using React.js for a dynamic user interface.

This project has been created by a student at Parsity, an online software engineering course. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the repository that this project forks.
## Features

If you have any questions about this project or the program in general, visit [parsity.io](https://parsity.io/) or email hello@parsity.io.
- Fetches a list of products from the backend.
- Displays products in a paginated list on the frontend.
- Users can filter products by category.
- Users can sort products by price.
- Users can search for products by name.

## Technologies Used

- React.js
- MongoDB
- Express.js

## Installation

1. Clone this repository to your local machine:

```
git clone https://github.com/AdamC7313/product-list.git
```

2. Navigate to the project directory:

```
cd product-list
```

3. Install dependencies for both backend and front end:

```
npm install

cd product-list-ui
npm install
```

## Usage

1. Start the backend server (make sure you are in the root folder):

```
server node.js
```

2. Start the NextJS dev server:

```
cd product-list-ui
npm run dev
```

3. Open your web browser and navigate to 'http://localhost:3000' to view the application

## Backend API Endpoints

- '**GET /products/:product**': Returns a specific product by its id
- '**GET /products/:product/reviews**': Returns ALL the reviews for a product, but limited to 4 at a time. This one will be a little tricky as you'll have to retrieve them out of the products. You should be able to pass in an optional page query parameter to paginate.
- '**POST /products**': Creates a new product in the database
- '**POST /products/:product/reviews**': Creates a new review in the database by adding it to the correct product's reviews array.
- '**DELETE /products/:product**': Deletes a product by id
- '**DELETE /reviews/:review**': Deletes a review by id

## Directory Structure
```
product-list/
├── models/ # MongoDB models
├── routes/ # Express routes
├── test/ # Server test file
└── server.js # Express server setup
└── product-list-ui/ # Frontend NextJS code
├── app/ # Main application files
└── layout.js
└── page.js
├── components/ # Building blocks to main app
└── ProductList.js
└── ProductListItem.js
├── public/
├── package.json
```
13 changes: 13 additions & 0 deletions models/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const ProductSchema = new Schema({
id: Number,
category: String,
name: String,
price: Number,
image: String,
reviews: [{ type: Schema.Types.ObjectId, ref: "Review" }]
});

module.exports = mongoose.model("Product", ProductSchema);
11 changes: 11 additions & 0 deletions models/review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const ReviewSchema = new Schema({
id: Number,
userName: String,
text: String,
product: Number
});

module.exports = mongoose.model('Review', ReviewSchema);
16 changes: 16 additions & 0 deletions node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/_mocha.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/_mocha.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/.bin/flat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/flat.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/flat.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/.bin/he

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/he.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/he.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/js-yaml.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/js-yaml.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading