Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New API] : E-commerse product Api #336

Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions New_APIs/e-commerse-Api/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@


# E-Commerce Product Provider API

This API provides functionalities for managing products in an e-commerce platform. It supports creating, reading, updating, and deleting product information.

## Features

- Get and Build Our Projects.
- Search for products by name, category, or other attributes
- Pagination support for product listings
- Authentication and authorization

## Setup

1. Navigate to the project directory:
```bash
cd e-commerce-product-provider-api
```
2. Install dependencies:

```bash
npm install
```

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

```env
DB=Your_MONGODB_URL
```

4. Run the Project

```bash
node index.js
```

## Routes
```js
Routes:{
all_product:"/products",
category:"/products/category/:category",
specidic_product:"/products/product/:id"
}
```

## Methods

```bash
GET /
GET /products/category/:category
GET /products/product/:id
```

## Output

- **All Products**
![Screenshot from 2024-07-21 21-49-42](https://github.com/user-attachments/assets/3f955ed3-1dd8-46ae-97d7-cd1ce3e0207c)

- **Category**
![Screenshot from 2024-07-21 21-50-39](https://github.com/user-attachments/assets/23ccbe33-355e-4279-bb30-6c46c2db8343)

- **Specific Product**
![Screenshot from 2024-07-21 21-51-49](https://github.com/user-attachments/assets/5a0feb6b-30b9-455b-874b-5a053b259882)


## Contributing

[Sivaprasath2004](https://github.com/sivaprasath2004)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions New_APIs/e-commerse-Api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const express=require('express')
const app=express()
require('dotenv').config()
const mongoose=require('mongoose')
const products=require('./mongodb/shopping')
const cors=require('cors')
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({extended:true}))
app.get("/",(req,res)=>{res.send({
author:"sivaprasath2004",
category:["mobile","laptop","toys","fashion","furniture"],
Routes:{
all_product:"/products",
category:"/products/category/:category",
specidic_product:"/products/product/:id"
}
})})
app.get("/products",async(req,res)=>{
await mongoose.connect(process.env.DB)
try{
let product=await products.find()
res.send(product)
throw new Error('Something went wrong!');
}catch(err){
res.send(err)
}
})
app.get("/products/category/:category",async(req,res)=>{
await mongoose.connect(process.env.DB)
try{
let product=await products.find({category:req.params.category})
res.send(product)
throw new Error('Something went wrong!');
}catch(err){
res.send(err)
}
})
app.get("/products/product/:id",async(req,res,next)=>{
await mongoose.connect(process.env.DB)
try{
let product=await products.findById(req.params.id)
if(product){
res.send(product)
}else{res.send("Sorry no more products available")}
throw new Error('Something went wrong!');
}catch(err){
res.send(err)
}
})
app.listen(5000,()=>{console.log("app listen in 5000")})
44 changes: 44 additions & 0 deletions New_APIs/e-commerse-Api/mongodb/shopping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const mongoose=require('mongoose')
const user_schema=new mongoose.Schema({
category:String,
productName:String,
brand:String,
details:[{
'color':String,
"material":String,
"length": String,
"display": String,
}],
camera:[{
front:String,
back:String
}],
size:[String],
battery:String,
warrenty:String,
img:[
{
url:String,
caption:String
},
{
url:String,
caption:String
}
],
cards:[
{
url:String,
caption:String
},
{
url:String,
caption:String
}
],
MRPprize:Number,
SELLprize:Number,
stock:String,
})
module.exports=mongoose.model('users',user_schema)

Loading
Loading