From 078ab6358069b743f025ae594c03359f06697a47 Mon Sep 17 00:00:00 2001 From: jonasChristoph <91590709+jonasChristoph@users.noreply.github.com> Date: Wed, 30 Mar 2022 13:29:00 +0200 Subject: [PATCH] =?UTF-8?q?Startseite=20-=20automatisches=20EInf=C3=BCgen?= =?UTF-8?q?=20der=20Produktbilder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 28 ++++++--- views/index.ejs | 148 +++++++++++++++++++++++++++--------------------- 2 files changed, 103 insertions(+), 73 deletions(-) diff --git a/index.js b/index.js index 3e002f0..21938af 100644 --- a/index.js +++ b/index.js @@ -113,15 +113,29 @@ function notAuthenticatedHandler(req, res, next){ app.get("/", authNoRedirectHandler, (req, res) => { mysql_handler.con.query("SELECT * FROM products", function(err, result){ if(err) throw err; - - let dict = { - title: "Startseite", - user: req.user, - products: JSON.parse(JSON.stringify(result)) - } - res.render('index', dict) + let products = JSON.parse(JSON.stringify(result)); + mysql_handler.con.query("SELECT * FROM product_images", function(err, result){ + if(err) throw err; + let dict = { + title: "Startseite", + user: req.user, + products: products, + product_images: JSON.parse(JSON.stringify(result)), + } + res.render('index', dict) + }) }); }); +app.get("/productImage/:productId", (req,res) => { + mysql_handler.con.query(`SELECT url FROM product_images WHERE product_id = ${req.params.productId} `,(err,result) =>{ + if (result.length > 0){ + res.redirect(JSON.parse(JSON.stringify(result))[0].url) + } + else { + res.redirect("/images/examples.jpg") + } + }) +}) // Account app.get("/account", authenticatedHandler, (req, res) => { diff --git a/views/index.ejs b/views/index.ejs index db077e7..1e375e4 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,103 +1,119 @@ -
- <%- include('partials/head'); %> + + + <%- include('partials/head'); %> - - <%- include('partials/header'); %> - -<%= products[i].name %>
- -
+ + <%= products[i].name %> +
+<%= products[randomNr].name %>
+<%= products[randomNr].name %>
+
-
','_self')">
-
-
','_self')">
-
-
','_self')">
-
- <%= products[randomNr].name %>
+
-
- <%= products[randomNr].name %>
+<%= products[randomNr].name %>
+