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

Mock ap is #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
309 changes: 303 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,303 @@
var http = require('http');
http.createServer(function (req, res) {
console.log(`Just got a request at ${req.url}!`)
res.write('Yo!');
res.end();
}).listen(process.env.PORT || 3000);
const express = require("express");
const app = express();

app.get("/products", (req, res) => {
console.log("Just got a GET request!");
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 3,
name: "old product",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 20,
createdAt: "2023-04-10T23:31:34.000Z",
updatedAt: "2023-04-10T23:31:34.000Z",
brand_id: 2,
category_id: 2,
},
]);
});

app.get("/products/limited", (req, res) => {
return res.status(200).json([
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 3,
name: "old product",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 20,
createdAt: "2023-04-10T23:31:34.000Z",
updatedAt: "2023-04-10T23:31:34.000Z",
brand_id: 2,
category_id: 2,
},
]);
});

app.get("/products/handpicked", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
]);
});

app.get("/products/popular", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
]);
});

app.get("/products/new", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
]);
});

app.get("/products/search", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
brand: {
id: 1,
name: "Zara",
description: "clothing company",
img: "https://logos-world.net/zara-logo/",
},
},
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
brand: {
id: 1,
name: "Zara",
description: "clothing company",
img: "https://logos-world.net/zara-logo/",
},
},
]);
});
app.get("/products/categories", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "T-shirts",
description: "no need to describe a T-shirts category :)",
img: "https://blog.treasurie.com/types-of-t-shirts/",
},
{
id: 2,
name: "test categorey",
description: "qqqqqqqqqqqqqqqqqqqq",
img: null,
},
]);
});
app.get("/products/brands", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara",
description: "clothing company",
img: "https://logos-world.net/zara-logo/",
},
{
id: 2,
name: "my brand",
description: "non of your bussnis",
img: null,
},
]);
});
app.get("/brands/products/1", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
]);
});
app.get("/categories/products/1", (req, res) => {
return res.status(200).json([
{
id: 1,
name: "Zara simple T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 19.99,
quantity: 100,
rating: 4.7,
discount: 0,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
{
id: 2,
name: "second Zara T-shirt",
tittle: "Zara T-shirt",
description: "casual T-shirt ",
price: 29.99,
quantity: 10,
rating: 4.4,
discount: 15,
createdAt: "2023-07-10T23:31:34.000Z",
updatedAt: "2023-07-10T23:31:34.000Z",
brand_id: 1,
category_id: 1,
},
]);
});
app.use((req, res) => {
res.status(404).json({ message: "Not Found" });
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
Loading