From d1d2355ded176d62dddad0aaae67ae0600b95166 Mon Sep 17 00:00:00 2001 From: Tim Adams <zfac125@live.rhul.ac.uk> Date: Wed, 31 Jan 2024 23:58:53 +0000 Subject: [PATCH] still migrating all important elements from the frontend to the backend --- js/controllers/pagesCtrlFile.js | 31 ++++++++++++ js/routes/pages.js | 16 ++++++ js/server.js | 31 +----------- products.js | 86 +++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 30 deletions(-) create mode 100644 js/controllers/pagesCtrlFile.js create mode 100644 js/routes/pages.js create mode 100644 products.js diff --git a/js/controllers/pagesCtrlFile.js b/js/controllers/pagesCtrlFile.js new file mode 100644 index 0000000..ffd0e31 --- /dev/null +++ b/js/controllers/pagesCtrlFile.js @@ -0,0 +1,31 @@ +exports.hCtrlFunction = (req, res) => { + res.render('index'); +} + +exports.cartCtrlFunction = (req, res) => { + res.render('cart'); +} + +exports.kidsSCtrlFunction = (req, res) => { + res.render('kids-shoes'); +} + +exports.kidsCtrlFunction = (req, res) => { + res.render('kids'); +} + +exports.menSCtrlFunction = (req, res) => { + res.render('men-shoes'); +} + +exports.menCtrlFunction = (req, res) => { + res.render('men'); +} + +exports.womenSCtrlFunction = (req, res) => { + res.render('women-shoes'); +} + +exports.womenCtrlFunction = (req, res) => { + res.render('women'); +} \ No newline at end of file diff --git a/js/routes/pages.js b/js/routes/pages.js new file mode 100644 index 0000000..8945d3b --- /dev/null +++ b/js/routes/pages.js @@ -0,0 +1,16 @@ +const express = require('express'); +//const { modules } = require('node:module'); +const { hCtrlFunction, cartCtrlFunction, kidsSCtrlFunction, kidsCtrlFunction, menSCtrlFunction, menCtrlFunction, womenSCtrlFunction, womenCtrlFunction } = require('../controllers/pagesCtrlFile'); + +const router = express.Router(); + +router.get('/', hCtrlFunction); +router.get('/cart', cartCtrlFunction); +router.get('/kids-shoes', kidsSCtrlFunction); +router.get('/kids', kidsCtrlFunction); +router.get('/men-shoes', menSCtrlFunction); +router.get('/men', menCtrlFunction); +router.get('/women-shoes', womenSCtrlFunction); +router.get('/women', womenCtrlFunction); + +module.exports = router; \ No newline at end of file diff --git a/js/server.js b/js/server.js index 7621506..adb4b96 100644 --- a/js/server.js +++ b/js/server.js @@ -7,37 +7,8 @@ console.log(publicDirectory); */ app.use(express.static(publicDirectory)); app.set('view engine', 'hbs'); -app.get("/", (req, res) => { - res.render('index'); -}) +app.use('/', require('./routes/pages')); -app.get("/men", (req, res) => { - res.render('men'); -}) - -app.get("/women", (req, res) => { - res.render('women'); -}) - -app.get("/kids", (req, res) => { - res.render('kids'); -}) - -app.get("/men-shoes", (req, res) => { - res.render('men-shoes'); -}) - -app.get("/women-shoes", (req, res) => { - res.render('women-shoes'); -}) - -app.get("/kids-shoes", (req, res) => { - res.render('kids-shoes'); -}) - -app.get("/cart", (req, res) => { - res.render('cart'); -}) app.listen(5000, () => { console.log("Server is listening on port 5000"); }) \ No newline at end of file diff --git a/products.js b/products.js new file mode 100644 index 0000000..503c1ef --- /dev/null +++ b/products.js @@ -0,0 +1,86 @@ +exports.productList = [ + { + name: 'Blue Shirt', + description: 'This is a Blue Shirt', + tag: 'BlueShirt', + price: 29.99, + inCart: 0 + }, + { + name: 'Black Shirt', + description: 'This is a Black Shirt', + tag: 'BlackShirt', + price: 23.99, + inCart: 0 + }, + { + name: 'White Shirt', + description: 'This is a White Shirt', + tag: 'WhiteShirt', + price: 89.99, + inCart: 0 + }, + { + name: 'Denim jeans', + description: 'This is a Denim jeans', + tag: 'DenimJeans', + price: 150.00, + inCart: 0 + }, + { + name: 'Light blue jeans', + description: 'This is a Light blue jeans', + tag: 'LightBlue', + price: 50.00, + inCart: 0 + }, + { + name: 'Cotton jeans', + description: 'This is a Cotton jeans', + tag: 'Cottonjeans', + price: 200.00, + inCart: 0 + }, + { + name: 'Blue blouse', + description: 'This is a Blue blouse', + tag: 'Blueblouse', + price: 59.99, + inCart: 0 + }, + { + name: 'Off White blouse', + description: 'This is an Off White blouse', + tag: 'OffWhiteblouse', + price: 73.99, + inCart: 0 + }, + { + name: 'White blouse', + description: 'This is a White blouse', + tag: 'Whiteblouse', + price: 89.99, + inCart: 0 + }, + { + name: 'Brown trouser', + description: 'This is a Brown trouser', + tag: 'Browntrouser', + price: 140.00, + inCart: 0 + }, + { + name: 'Cream trouser', + description: 'This is a Cream trouser', + tag: 'Creamtrouser', + price: 59.00, + inCart: 0 + }, + { + name: 'Grey trouser', + description: 'This is a Grey trouser', + tag: 'Greytrouser', + price: 201.00, + inCart: 0 + } +] \ No newline at end of file -- GitLab