From fc16e08f6aa18db2e58d6ee512e18df2b9c1fe00 Mon Sep 17 00:00:00 2001 From: 65160381 <65160381@go.buu.ac.th> Date: Tue, 25 Mar 2025 02:56:33 +0700 Subject: [PATCH] 9.1 --- app.js | 1 + public/Post.html | 54 --------------- public/index.html | 6 +- public/styles/cart.css | 147 ----------------------------------------- 4 files changed, 4 insertions(+), 204 deletions(-) delete mode 100644 public/Post.html delete mode 100644 public/styles/cart.css diff --git a/app.js b/app.js index 1c162ab..0353af6 100644 --- a/app.js +++ b/app.js @@ -71,6 +71,7 @@ app.get('/register', (req, res) => { app.get('/post-product', (req, res) => { res.sendFile(path.join(__dirname, 'public', 'post-product.html')); }); + // Route สำหรับการ logout app.get('/logout', (req, res) => { // ลบข้อมูลใน session diff --git a/public/Post.html b/public/Post.html deleted file mode 100644 index 61f1720..0000000 --- a/public/Post.html +++ /dev/null @@ -1,54 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Post a New Product</title> - <link rel="stylesheet" href="styles/login®ister.css"> -</head> -<body> - <h1>Post a New Product</h1> - - <!-- ฟอร์มสำหรับโพสต์สินค้า --> - <form id="postProductForm" action="/api/products" method="POST" enctype="multipart/form-data"> - <label for="productName">Product Name:</label> - <input type="text" id="productName" name="productName" required> - - <label for="productPrice">Price:</label> - <input type="number" id="productPrice" name="productPrice" required> - - <label for="productImg">Product Image:</label> - <input type="file" id="productImg" name="productImg" required> - - <button type="submit">Post Product</button> - </form> - - <script> - // การส่งข้อมูลฟอร์มโดยใช้ JavaScript (ใช้ fetch API) - const form = document.getElementById('postProductForm'); - form.addEventListener('submit', async function(event) { - event.preventDefault(); // ป้องกันการ submit ฟอร์มแบบปกติ - - const formData = new FormData(form); // สร้าง FormData จากฟอร์ม - try { - const response = await fetch('/api/products', { - method: 'POST', - body: formData - }); - - const data = await response.json(); - if (response.ok) { - alert('Product posted successfully!'); - console.log(data); - } else { - alert('Failed to post product!'); - console.error(data); - } - } catch (error) { - console.error('Error:', error); - alert('An error occurred while posting the product.'); - } - }); - </script> -</body> -</html> diff --git a/public/index.html b/public/index.html index 1a056c0..72f362c 100644 --- a/public/index.html +++ b/public/index.html @@ -27,10 +27,10 @@ </div> </header> - <div class="Post"> - <button onclick="window.location.href='Post.html'">Post New Product</button> + <div class="post-product"> + <button onclick="window.location.href='post-product.html'">Post New Product</button> </div> - + <div class="products" id="product-list"> <!-- Products will be dynamically loaded here --> </div> diff --git a/public/styles/cart.css b/public/styles/cart.css deleted file mode 100644 index a136c56..0000000 --- a/public/styles/cart.css +++ /dev/null @@ -1,147 +0,0 @@ -/* General Styles */ -body { - font-family: Arial, sans-serif; - background-color: #f4f4f4; - margin: 0; - padding: 0; - color: #333; -} - -header { - background-color: #007bff; - color: white; - padding: 20px; - display: flex; - justify-content: space-between; - align-items: center; -} - -header h1 { - margin: 0; -} - -header .cart-info { - font-size: 18px; -} - -footer { - background-color: #007bff; - color: white; - padding: 10px; - text-align: center; -} - -footer .checkout { - background-color: #28a745; - color: white; - padding: 10px 20px; - cursor: pointer; - border-radius: 5px; - margin-top: 10px; -} - -footer .checkout:hover { - background-color: #218838; -} - -/* Cart Styles */ -.cart-items { - display: flex; - flex-direction: column; - align-items: center; - margin: 20px; -} - -.cart-item { - background-color: white; - border-radius: 8px; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); - display: flex; - justify-content: space-between; - padding: 20px; - margin: 10px 0; - width: 80%; - max-width: 800px; - transition: transform 0.3s ease; -} - -.cart-item:hover { - transform: translateY(-5px); -} - -.cart-item img { - max-width: 100px; - border-radius: 8px; -} - -.cart-item div { - flex-grow: 1; - margin-left: 20px; -} - -.cart-item h3 { - font-size: 18px; - color: #007bff; - margin-bottom: 10px; -} - -.cart-item p { - font-size: 14px; - color: #555; - margin-bottom: 5px; -} - -.cart-item input[type="number"] { - width: 50px; - padding: 5px; - margin-right: 10px; - border: 1px solid #ddd; - border-radius: 5px; -} - -.cart-item button { - background-color: #dc3545; - color: white; - padding: 8px 12px; - border: none; - border-radius: 5px; - cursor: pointer; - transition: background-color 0.3s ease; -} - -.cart-item button:hover { - background-color: #c82333; -} - -/* Empty Cart Message */ -.cart-items p { - font-size: 18px; - color: #777; - text-align: center; -} - -/* Responsive Design */ -@media (max-width: 768px) { - .cart-item { - flex-direction: column; - align-items: center; - text-align: center; - } - - .cart-item img { - max-width: 80px; - } - - .cart-item div { - margin-left: 0; - } - - header { - flex-direction: column; - text-align: center; - } - - header .cart-info { - margin-top: 10px; - } -} -- GitLab