diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/favicon.ico differ diff --git a/logo192.png b/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/logo192.png differ diff --git a/logo512.png b/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/logo512.png differ diff --git a/server/.htaccess b/server/.htaccess index 6b43e8b..eb8d1ca 100644 --- a/server/.htaccess +++ b/server/.htaccess @@ -2,4 +2,7 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] -SetEnvIfNoCase Request_URI ^ / index.php no-gzip -vary \ No newline at end of file +SetEnvIfNoCase Request_URI ^ / index.php no-gzip -vary +# HTID:21006778: DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES BELOW +allow from 0.0.0.0 +# DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES ABOVE HTID:21006778: diff --git a/server/DbConnect.php b/server/DbConnect.php index 0afbd96..479419e 100644 --- a/server/DbConnect.php +++ b/server/DbConnect.php @@ -4,14 +4,20 @@ */ class DbConnect { - // private $server = 'https://databases.000webhost.com'; - // private $dbname = 'id20087235_scandiweb_task'; - // private $user = 'id20087235_root'; - // private $pass = 'WpG)fM7WHlk%oEOX'; private $server = 'localhost'; - private $dbname = 'scandiweb_task'; - private $user = 'root'; - private $pass = ''; + private $dbname = 'id20087235_scandiweb_task'; + private $user = 'id20087235_root'; + private $pass = 'WpG)fM7WHlk%oEOX'; + +// private $server = 'sql7.freemysqlhosting.net'; +// private $dbname = 'sql7587618'; +// private $user = 'sql7587618'; +// private $pass = '2BbPJcDg3X'; + +// private $server = 'localhost'; +// private $dbname = 'scandiweb_task'; +// private $user = 'root'; +// private $pass = ''; diff --git a/server/index.php b/server/index.php index 74522dd..bdfc56e 100644 --- a/server/index.php +++ b/server/index.php @@ -3,7 +3,7 @@ ini_set('display_errors', 1); header("Access-Control-Allow-Origin: *"); header('Access-Control-Allow-Credentials: true'); -header('Access-Control-Max-Age: 86400'); +// header('Access-Control-Max-Age: 86400'); header("Access-Control-Allow-Headers: *"); header("Access-Control-Allow-Methods: *"); @@ -21,14 +21,21 @@ $products_list->getProducts($conn); break; case "POST": - $product = json_decode(file_get_contents('php://input')); - $type = $product->type; - $class = $type; - $product_object = new $class($product, true); - $product_object->addProduct($conn, $type); - break; - case "DELETE": - $products_list = new ProductList(); - $products_list->deleteProduct($conn); + $path = explode('/', $_SERVER['REQUEST_URI']); + if ($path[1] == "addproduct") { + $product = json_decode(file_get_contents('php://input')); + $type = $product->type; + $class = $type; + // echo json_encode($path); + $product_object = new $class($product, true); + $product_object->addProduct($conn, $type); + } else { + $products_list = new ProductList(); + $products_list->deleteProduct($conn, $path[2]); + } break; + // case "DELETE": + // $products_list = new ProductList(); + // $products_list->deleteProduct($conn); + // break; } \ No newline at end of file diff --git a/server/product.php b/server/product.php index 3749128..4bed1fe 100644 --- a/server/product.php +++ b/server/product.php @@ -53,7 +53,7 @@ public function addProduct($conn, $type) if ($valid) { try { $sql = - "INSERT INTO products(SKU, name, price, type) VALUES(:SKU, :name, :price, :type)" . + "INSERT INTO products(SKU, name, price, type) VALUES(:SKU, :name, :price, :type);" . "INSERT INTO dvds(SKU, size) VALUES(:SKU, :size)"; $stmt = $conn->prepare($sql); $stmt->bindParam(':SKU', $this->SKU); @@ -188,7 +188,7 @@ public function addProduct($conn, $type) if ($valid) { try { $sql = - "INSERT INTO products(SKU, name, price, type) VALUES(:SKU, :name, :price, :type)" . + "INSERT INTO products(SKU, name, price, type) VALUES(:SKU, :name, :price, :type);" . "INSERT INTO furniture(SKU, length, width, height) VALUES(:SKU, :length, :width, :height)"; $stmt = $conn->prepare($sql); $stmt->bindParam(':SKU', $this->SKU); @@ -241,13 +241,12 @@ public function getProducts($conn) } } - public function deleteProduct($conn) + public function deleteProduct($conn, $SKU) { try { $sql = "DELETE FROM products WHERE SKU = :id"; - $path = explode('/', $_SERVER['REQUEST_URI']); $stmt = $conn->prepare($sql); - $stmt->bindParam(':id', $path[4]); + $stmt->bindParam(':id', $SKU); $stmt->execute(); $response = ['status' => '200', 'message' => 'Record deleted successfully.']; } catch (\Throwable $error) { diff --git a/server/test.php b/server/test.php deleted file mode 100644 index 6c929e4..0000000 --- a/server/test.php +++ /dev/null @@ -1,11 +0,0 @@ - - - - -

Hello GFG

- - - - \ No newline at end of file diff --git a/src/components/CreateProduct/CreateProduct.js b/src/components/CreateProduct/CreateProduct.js index 6bcb514..9b55364 100644 --- a/src/components/CreateProduct/CreateProduct.js +++ b/src/components/CreateProduct/CreateProduct.js @@ -1,5 +1,4 @@ import './CreateProduct.css'; -import axios from 'axios'; import { Navbar, Container, Nav, Form, Button, Modal } from 'react-bootstrap'; import BookComponent from './TypeComponents/BookComponent'; import DVDComponent from './TypeComponents/DVDComponent' @@ -61,16 +60,27 @@ function CreateProduct() { return true }); if (valid) { - axios.post('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/', product).then(function (response) { - console.log(response.data); - if (response.data.status === '200') { - navigate('/'); - } - else { - setErrorMessage(response.data.message); - handleShow() - } - }); + try { + // console.log(product) + fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/addproduct', { + method: 'post', + body: JSON.stringify(product) + }).then(function (response) { + return response.json(); + }).then(function (data) { + console.log(data); + if (data.status === '200') { + navigate('/'); + } + else { + setErrorMessage(data.message); + handleShow() + } + }); + } catch (error) { + alert(error) + } + } else { handleShow(); @@ -113,7 +123,7 @@ function CreateProduct() { SKU Name Price ($) Type Swithcer - handleTypeChange(e)}> + handleTypeChange(e)}> diff --git a/src/components/CreateProduct/TypeComponents/BookComponent.js b/src/components/CreateProduct/TypeComponents/BookComponent.js index 38f8910..0dfd8c0 100644 --- a/src/components/CreateProduct/TypeComponents/BookComponent.js +++ b/src/components/CreateProduct/TypeComponents/BookComponent.js @@ -6,7 +6,7 @@ function BookComponent(props) { Weight (KG) Size (MB) Length (CM) Width (CM) Height (CM) handleCheckbox(e)}> diff --git a/src/components/ProductsList/ProductsList.js b/src/components/ProductsList/ProductsList.js index f5e51a7..2828cf5 100644 --- a/src/components/ProductsList/ProductsList.js +++ b/src/components/ProductsList/ProductsList.js @@ -1,9 +1,6 @@ -import axios from 'axios'; import { useEffect, useState } from 'react'; import './ProductsList.css'; import Product from '../Product/Product'; -// import Col from 'react-bootstrap/Col'; -// import Row from 'react-bootstrap/Row'; import { Navbar, Container, Nav, Col, Row, Button } from 'react-bootstrap'; @@ -24,9 +21,18 @@ export default function ProductsList() { function getProducts() { - axios.get('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/').then(function (response) { - setProducts(response.data); - }); + try { + fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/', { + method: 'get', + }).then(function (response) { + return response.json(); + }).then(function (data) { + // console.log(data); + setProducts(data); + }); + } catch (error) { + alert(error); + } } const handleDelete = (event) => { @@ -34,21 +40,30 @@ export default function ProductsList() { selected.forEach(SKU => { deleteHelper(SKU); }); - // handleSelection({}); } const deleteHelper = (SKU) => { let tempSelected = []; Object.assign(tempSelected, selected); - axios.delete('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/' + SKU + '/delete').then(function (response) { - console.log(response.data); - tempSelected = tempSelected.filter(product => { - // eslint-disable-next-line eqeqeq - return product != SKU; + try { + fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/deleteproduct/' + SKU, { + method: 'post', + }).then(function (response) { + return response.json(); + }).then(function (data) { + console.log(data); + if (data.status === '200') { + tempSelected = tempSelected.filter(product => { + // eslint-disable-next-line eqeqeq + return product != SKU; + }) + setSelected(tempSelected); + getProducts(); + } }); - setSelected(tempSelected); - getProducts(); - }); + } catch (error) { + alert(error); + } } @@ -63,10 +78,6 @@ export default function ProductsList() { setSelected(tempSelected); }; - // if (products.length === 0) { - // return ([]); - // } - return ( <>