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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README
Empty file.
22 changes: 22 additions & 0 deletions app/initial-data/brands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"id": "1",
"name": "Oakley"
},
{
"id": "2",
"name": "Ray Ban"
},
{
"id": "3",
"name": "Levi's"
},
{
"id": "4",
"name": "DKNY"
},
{
"id": "5",
"name": "Burberry"
}
]
134 changes: 134 additions & 0 deletions app/initial-data/products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[
{
"id": "1",
"categoryId": "1",
"name": "Superglasses",
"description": "The best glasses in the world",
"price": 150,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "2",
"categoryId": "1",
"name": "Black Sunglasses",
"description": "The best glasses in the world",
"price": 100,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "3",
"categoryId": "1",
"name": "Brown Sunglasses",
"description": "The best glasses in the world",
"price": 50,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "4",
"categoryId": "2",
"name": "Better glasses",
"description": "The best glasses in the world",
"price": 1500,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "5",
"categoryId": "2",
"name": "Glasses",
"description": "The most normal glasses in the world",
"price": 150,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "6",
"categoryId": "3",
"name": "glas",
"description": "Pretty awful glasses",
"price": 10,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "7",
"categoryId": "3",
"name": "QDogs Glasses",
"description": "They bark",
"price": 1500,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "8",
"categoryId": "4",
"name": "Coke cans",
"description": "The thickest glasses in the world",
"price": 110,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "9",
"categoryId": "4",
"name": "Sugar",
"description": "The sweetest glasses in the world",
"price": 125,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "10",
"categoryId": "5",
"name": "Peanut Butter",
"description": "The stickiest glasses in the world",
"price": 103,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
},
{
"id": "11",
"categoryId": "5",
"name": "Habanero",
"description": "The spiciest glasses in the world",
"price": 153,
"imageUrls": [
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg",
"https://image.shutterstock.com/z/stock-photo-yellow-sunglasses-white-backgound-600820286.jpg"
]
}
]
104 changes: 104 additions & 0 deletions app/initial-data/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[
{
"gender": "female",
"cart": [],
"name": {
"title": "mrs",
"first": "susanna",
"last": "richards"
},
"location": {
"street": "2343 herbert road",
"city": "duleek",
"state": "donegal",
"postcode": 38567
},
"email": "[email protected]",
"login": {
"username": "yellowleopard753",
"password": "cry",
"salt": "eNuMvema",
"md5": "a8be2a69c8c91684588f4e1a29442dd7",
"sha1": "f9a60bbf8b550c10712e470d713784c3ba78a68e",
"sha256": "4dca9535634c102fbadbe62dc5b37cd608f9f3ced9aacf42a5669e5a312690a0"
},
"dob": "1954-10-09 10:47:17",
"registered": "2003-08-03 01:12:24",
"phone": "031-941-6700",
"cell": "081-032-7884",
"picture": {
"large": "https://randomuser.me/api/portraits/women/55.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/55.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/55.jpg"
},
"nat": "IE"
},
{
"gender": "male",
"cart": [],
"name": {
"title": "mr",
"first": "salvador",
"last": "jordan"
},
"location": {
"street": "9849 valley view ln",
"city": "burkburnett",
"state": "delaware",
"postcode": 78623
},
"email": "[email protected]",
"login": {
"username": "lazywolf342",
"password": "tucker",
"salt": "oSngghny",
"md5": "30079fb24f447efc355585fcd4d97494",
"sha1": "dbeb2d0155dad0de0ab9bbe21c062e260a61d741",
"sha256": "4f9416fa89bfd251e07da3ca0aed4d077a011d6ef7d6ed75e1d439c96d75d2b2"
},
"dob": "1955-07-28 22:32:14",
"registered": "2010-01-10 06:52:31",
"phone": "(944)-261-2164",
"cell": "(888)-556-7285",
"picture": {
"large": "https://randomuser.me/api/portraits/men/4.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/4.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/4.jpg"
},
"nat": "US"
},
{
"gender": "female",
"cart": [],
"name": {
"title": "mrs",
"first": "natalia",
"last": "ramos"
},
"location": {
"street": "7934 avenida de salamanca",
"city": "madrid",
"state": "aragón",
"postcode": 43314
},
"email": "[email protected]",
"login": {
"username": "greenlion235",
"password": "waters",
"salt": "w10ZFgoO",
"md5": "19f6fb510c58be44b2df1816d88b739d",
"sha1": "18e545aee27156ee6be35596631353a14ee03007",
"sha256": "2b23b25939ece8ba943fe9abcb3074105867c267d122081a2bc6322f935ac809"
},
"dob": "1947-03-05 15:23:07",
"registered": "2004-07-19 02:44:19",
"phone": "903-556-986",
"cell": "696-867-013",
"picture": {
"large": "https://randomuser.me/api/portraits/women/54.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/54.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/54.jpg"
},
"nat": "ES"
}
]
16 changes: 16 additions & 0 deletions app/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const jwt = require('jsonwebtoken');

const authenticateToken = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];

if (token == null) return res.sendStatus(401);

jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
if (err) return res.sendStatus(403);
req.user = user;
next();
});
};

module.exports = authenticateToken;
27 changes: 27 additions & 0 deletions app/routes/brands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require('express');
const path = require('path');
const router = express.Router();

// Load data files using relative paths
const brands = require(path.join(__dirname, '../initial-data/brands.json'));
const products = require(path.join(__dirname, '../initial-data/products.json'));

// Get all brands
router.get('/', (req, res) => {
res.json(brands);
});

// Get products by brand name
router.get('/:brandName/products', (req, res) => {
const brandName = req.params.brandName.toLowerCase();
const brand = brands.find(b => b.name.toLowerCase() === brandName);

if (!brand) {
return res.status(404).json({ message: 'Brand not found' });
}

const filteredProducts = products.filter(p => p.categoryId === brand.id);
res.json(filteredProducts);
});

module.exports = router;
Loading