diff --git a/database/db_scripts/webshop_test-data.sql b/database/db_scripts/webshop_test-data.sql index 2e4bd83..d94c6b2 100644 --- a/database/db_scripts/webshop_test-data.sql +++ b/database/db_scripts/webshop_test-data.sql @@ -2,15 +2,15 @@ USE webshop; -- Product Categories INSERT INTO product_category (id, name) -VALUES (1, 'Electronics'); +VALUES (1, 'Motorräder'); INSERT INTO product_category (id, name) -VALUES (2, 'Home Appliances'); +VALUES (2, 'Oldtimer'); INSERT INTO product_category (id, name) -VALUES (3, 'Clothing'); +VALUES (3, 'Sportwägen'); INSERT INTO product_category (id, name) -VALUES (4, 'Sports'); +VALUES (4, 'LKWs'); INSERT INTO product_category (id, name) -VALUES (5, 'Books'); +VALUES (5, 'Kleinwägen'); -- Discounts INSERT INTO discount (id, name, description, discount_percent, active) diff --git a/public/bestellformular/bestellformular.html b/public/bestellformular/bestellformular.html index f3f07e4..048152c 100644 --- a/public/bestellformular/bestellformular.html +++ b/public/bestellformular/bestellformular.html @@ -1,55 +1,262 @@ - - - Bestellformular - - - - + + + Bestellformular + + + +
- - + + -
-
-
-

Bestellformular

+
+
+ +

Bestellformular

- - + + - - + + - - + + - - + + - - + + - - + + - - + +
+ + + +
+
- - + + Bestellung absenden + +
+
+ + + +
diff --git a/public/bestellung/bestellung.html b/public/bestellung/bestellung.html new file mode 100644 index 0000000..0827942 --- /dev/null +++ b/public/bestellung/bestellung.html @@ -0,0 +1,104 @@ + + + + + + Ihre Bestellung + + + + + + +
+ +
+

Ihre Bestellung:

+
+ +
+

Kundennummer:

+

Produkt-ID:

+

Produktname:

+

Preis:

+
+
+
+ + + + + + + diff --git a/public/header_footer/header.html b/public/header_footer/header.html index ceedb74..40e272c 100644 --- a/public/header_footer/header.html +++ b/public/header_footer/header.html @@ -24,6 +24,7 @@ 0
+ @@ -57,4 +58,3 @@ - diff --git a/public/login/login.html b/public/login/login.html index 6e128de..08c1c7b 100644 --- a/public/login/login.html +++ b/public/login/login.html @@ -17,6 +17,7 @@ + Login @@ -31,13 +32,13 @@
- +
- +
@@ -52,7 +53,38 @@ - + + + diff --git a/public/registrieren/passwordValidation.js b/public/registrieren/passwordValidation.js deleted file mode 100644 index e69de29..0000000 diff --git a/public/registrieren/registrieren.html b/public/registrieren/registrieren.html index 4c23097..b2b7b62 100644 --- a/public/registrieren/registrieren.html +++ b/public/registrieren/registrieren.html @@ -29,47 +29,41 @@
-

Registrieren

+
+

Registrieren

- -
- - -
+
+ + +
+
+ + +
+
+ + +
+
+ + +
- -
- - -
+ +
+ + +
- -
- - -
+ - -
- - -
- - -
- - -
- - - - - - + + +
diff --git a/public/shop/shop.html b/public/shop/shop.html index 896fd16..eadd094 100644 --- a/public/shop/shop.html +++ b/public/shop/shop.html @@ -56,6 +56,7 @@

${product.name}

Preis: ${product.price}€

${product.description}

+

Artikel Nr: ${product.id}

`; // Karte in den Container einfügen diff --git a/public/shop/shop_lkw.html b/public/shop/shop_lkw.html index f32d052..0f15d10 100644 --- a/public/shop/shop_lkw.html +++ b/public/shop/shop_lkw.html @@ -47,18 +47,17 @@ // Für jedes Produkt eine Karte erstellen products.forEach(product => { - const card = document.createElement('div'); - card.classList.add('card'); - // Die Karte mit Produktdaten füllen - card.innerHTML = ` - ${product.name} -

${product.name}

-

Preis: ${product.price}€

-

${product.description}

- - `; - // Die Karte in den Container einfügen - container.appendChild(card); + const card = document.createElement('div'); + card.classList.add('card'); + card.innerHTML = ` + ${product.name} +

${product.name}

+

Preis: ${product.price}€

+

${product.description}

+

Artikel Nr: ${product.id}

+ + `; + container.appendChild(card); }); }) // Fehlerbehandlung diff --git a/public/shop/shop_motorrad.html b/public/shop/shop_motorrad.html index 96c69c3..5af6521 100644 --- a/public/shop/shop_motorrad.html +++ b/public/shop/shop_motorrad.html @@ -38,27 +38,25 @@ + diff --git a/scripts/routes/other/route-index.js b/scripts/routes/other/route-index.js index cfa9071..2052bcf 100644 --- a/scripts/routes/other/route-index.js +++ b/scripts/routes/other/route-index.js @@ -70,4 +70,7 @@ router.get('/bestellformular', (req, res) => { res.sendFile(path.join(__dirname, '../../../public/bestellformular/bestellformular.html')); }) +router.get('/bestellung', (req, res) => { + res.sendFile(path.join(__dirname, '../../../public/bestellung/bestellung.html')); +}) module.exports = router; \ No newline at end of file diff --git a/server.js b/server.js index b48590a..18ea71f 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,7 @@ const session = require('express-session'); const router = require('express').Router(); const path = require('path'); -require('dotenv').config({path:'process.env'}); +require('dotenv').config({path: 'process.env'}); const app = express(); const mysql = require('mysql'); @@ -32,7 +32,7 @@ app.use(session({ })); app.use(express.json()); -app.use(express.urlencoded({ extended: true })); +app.use(express.urlencoded({extended: true})); app.use(express.static(path.join(__dirname, '/scripts'))); app.use(express.static(path.join(__dirname, '/static'))); @@ -132,6 +132,161 @@ app.get('/api/products/sportwagen', async (req, res) => { }); }); +app.post('/api/user/registration', (req, res) => { + // SQL-Query für Nutzerregistration + const {name, lower_name, email, passwd} = req.body; + const sql = "INSERT INTO webshop.user (name, lower_name, email, passwd, passwd_hash_algo) VALUES (?, ?, ?, ?, 'none')" + + // Query abschicken + db.query(sql, [name, lower_name, email, passwd], (err, results) => { + if (err) { + console.error('Fehler beim Schreiben in die Datenbank: ', err); + res.status(500).send('Fehler beim Schreiben in die Datenbank'); + return; + } + res.status(201).json({message: 'Nutzer erfolgreich hinzugefügt', id: results.insertId}) + }) +}) + +app.post('/api/user/login', (req, res) => { + const {email, password} = req.body + const sql = 'SELECT * FROM user WHERE email = ?' + + db.query(sql, [email], (err, results) => { + if (err) { + console.error('Fehler beim Abrufen des Nutzers: ', err) + return res.status(500).json({message: 'Serverfehler'}) + } + if (results.length === 0) { + return res.status(401).json({message: 'E-Mail nicht gefunden'}) + } + const user = results[0] + + if (user.passwd !== password) { + return res.status(401).json({message: 'Falsches Passwort'}) + } + + req.session.userId = user.id; + req.session.email = user.email; + + res.json({message: 'Login erfolgreich', id: user.id}) + }) +}) + +app.post('/api/bestellung', (req, res) => { + const { user_id, produkte } = req.body; + // produkte erwartet als Array: [{product_id: 1, quantity: 2}, {product_id: 5, quantity: 1}, ...] + + if (!user_id || !Array.isArray(produkte) || produkte.length === 0) { + return res.status(400).json({ message: 'Ungültige Anfrage: user_id oder Produkte fehlen.' }); + } + + // Preise der Produkte abrufen + const productIds = produkte.map(p => p.product_id); + + const priceQuery = 'SELECT id, price FROM webshop.product WHERE id IN (?)'; + db.query(priceQuery, [productIds], (err, priceResults) => { + if (err) { + console.error('Fehler beim Abrufen der Produktpreise:', err); + return res.status(500).json({ message: 'Serverfehler beim Abrufen der Produktpreise.' }); + } + + if (priceResults.length !== productIds.length) { + return res.status(400).json({ message: 'Eines oder mehrere Produkte existieren nicht.' }); + } + + // Total berechnen + let total = 0; + produkte.forEach(p => { + const dbProduct = priceResults.find(pr => pr.id === p.product_id); + if (dbProduct) { + total += dbProduct.price * p.quantity; + } + }); + + const payment_id = 1; // Zahlungssystem-ID (z.B. 1 = Rechnung, 2 = PayPal, ...) + + const sqlOrder = 'INSERT INTO webshop.order_details (user_id, payment_id, total) VALUES (?, ?, ?)'; + db.query(sqlOrder, [user_id, payment_id, total], (err1, result1) => { + if (err1) { + console.error('Fehler beim Erstellen der Bestellung:', err1); + return res.status(500).json({ message: 'Fehler beim Erstellen der Bestellung.' }); + } + + const orderId = result1.insertId; + + const values = produkte.map(p => [user_id, p.product_id, p.quantity, orderId]); + const sqlItems = 'INSERT INTO webshop.order_items (user_id, product_id, quantity, order_id) VALUES ?'; + + db.query(sqlItems, [values], (err2, result2) => { + if (err2) { + console.error('Fehler beim Einfügen der Order-Items:', err2); + return res.status(500).json({ message: 'Fehler beim Hinzufügen der Produkte zur Bestellung.' }); + } + + res.status(201).json({ message: 'Bestellung erfolgreich!', order_id: orderId, total: total.toFixed(2) }); + }); + }); + }); +}); + +app.post('/api/bestellung/daten', (req, res) => { + const { user_id } = req.body; + + const sql = ` + SELECT + od.id AS order_id, + od.total AS order_total, + oi.product_id, + oi.quantity, + p.name AS product_name, + p.price AS product_price + FROM + webshop.order_details od + INNER JOIN + webshop.order_items oi ON od.id = oi.order_id + INNER JOIN + webshop.product p ON oi.product_id = p.id + WHERE + od.user_id = ? + ORDER BY + od.id DESC + `; + + db.query(sql, [user_id], (err, results) => { + if (err) { + console.error('Fehler beim Abrufen der Bestellungen: ', err); + return res.status(500).json({ message: 'Fehler beim Abrufen der Bestellungen' }); + } + + if (results.length === 0) { + return res.status(404).json({ message: 'Keine Bestellungen gefunden.' }); + } + + res.json(results); + }); +}); + +app.get('/api/pruefe-artikel', (req, res) => { + const artikelnummer = req.query.nummer; + + if (!artikelnummer) { + return res.status(400).json({ error: 'Keine Artikelnummer angegeben.' }); + } + + const query = 'SELECT id FROM product WHERE id = ?'; + + db.query(query, [artikelnummer], (err, results) => { + if (err) { + console.error('Fehler bei der Artikelsuche:', err); + return res.status(500).json({ error: 'Serverfehler bei der Artikelsuche.' }); + } + + const verfuegbar = results.length > 0; + res.json({ verfuegbar }); + }); +}); + const getIndexRoute = require('./scripts/routes/other/route-index'); app.use('/', getIndexRoute); diff --git a/static/Styles/bestellformular/bestellformular.css b/static/Styles/bestellformular/bestellformular.css index 66d08a3..c320ca7 100644 --- a/static/Styles/bestellformular/bestellformular.css +++ b/static/Styles/bestellformular/bestellformular.css @@ -8,7 +8,7 @@ body { } .wrapper { - flex: 1; /* Der Hauptinhalt (Formular) nimmt den verfügbaren Platz ein */ + flex: 1; /* Der Hauptinhalt nimmt den verfügbaren Platz ein */ } .form-container { @@ -42,20 +42,22 @@ textarea { box-sizing: border-box; } -input[type="submit"] { +/* NEU: Styling für den Absende-Link */ +.button-submit { + display: inline-block; margin-top: 20px; background-color: #ff6600; color: white; - border: none; + text-decoration: none; padding: 12px; border-radius: 5px; font-size: 16px; cursor: pointer; width: 100%; + text-align: center; + box-sizing: border-box; /* Damit Breite + Padding sauber passen */ } -input[type="submit"]:hover { - background-color: #ff5500; /* Ein leicht dunklerer Farbton beim Hover */ +.button-submit:hover { + background-color: #ff6600; } - - diff --git a/static/Styles/bestellung/bestellung.css b/static/Styles/bestellung/bestellung.css new file mode 100644 index 0000000..849719f --- /dev/null +++ b/static/Styles/bestellung/bestellung.css @@ -0,0 +1,49 @@ +/* Allgemeine Layout-Stile */ +body { + font-family: Arial, sans-serif; + background-color: #f2f2f2; + padding: 20px; + margin: 0; + display: flex; + flex-direction: column; + min-height: 100vh; +} + +/* Container für die Bestellinformationen */ +#bestellung { + background-color: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + margin-top: 20px; +} + +/* Titel */ +h2 { + text-align: center; + margin-bottom: 30px; + margin-top: 20px; +} + +/* Karte für Bestellinformationen */ +.bestell-info-card { + background-color: #fafafa; + padding: 15px; + border-radius: 8px; + margin-bottom: 15px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +/* Bestellinformationen formatieren */ +.bestell-info-card p { + font-size: 16px; + margin: 10px 0; +} + +/* Stile für die Label und Platzhalter */ +.bestell-info-card span { + font-weight: bold; + color: #333; +} + +