diff --git a/.eslintrc.json b/.eslintrc.json index 4bc70daad..7ea77ddbd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,7 @@ "browser": true, "es2021": true }, - "extends": ["plugin:react/recommended", "prettier"], + "extends": ["plugin:react/recommended"], "parserOptions": { "ecmaFeatures": { "jsx": true @@ -11,14 +11,9 @@ "ecmaVersion": 12, "sourceType": "module" }, - "plugins": ["react", "prettier"], + "plugins": ["react"], "rules": { - "prettier/prettier": [ - "error", - { - "endOfLine": "auto" - } - ], + "react/display-name": "off", "default-param-last": "off", "react/react-in-jsx-scope": "off", diff --git a/README.md b/README.md index 863724f8f..a126a9c85 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This free MUI & React Dashboard is coming with prebuilt design blocks, so the de switching from our pages to the real website is very easy to be done. Special thanks go to: + - [Nepcha Analytics](https://nepcha.com?ref=readme) for the analytics tool. Nepcha is already integrated with Material Dashboard React. You can use it to gain insights into your sources of traffic. **Documentation built by Developers** diff --git a/package.json b/package.json index 01521c624..7ed533e6c 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,10 @@ "@emotion/styled": "11.10.8", "@mui/icons-material": "5.11.16", "@mui/material": "5.12.3", + "axios": "^1.6.0", "chart.js": "4.3.0", "chroma-js": "2.4.2", + "cross-env": "^7.0.3", "prop-types": "15.8.1", "react": "18.2.0", "react-chartjs-2": "5.2.0", @@ -33,8 +35,10 @@ "yup": "1.1.1" }, "scripts": { - "start": "GENERATE_SOURCEMAP=false react-scripts start", - "build": "GENERATE_SOURCEMAP=false react-scripts build", + + "start": "cross-env GENERATE_SOURCEMAP=false react-scripts start", + "build": "cross-env GENERATE_SOURCEMAP=false react-scripts build", + "test": "react-scripts test", "eject": "react-scripts eject", "install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start" diff --git a/src/App.js b/src/App.js index 5ba40edb9..45fcd6d01 100644 --- a/src/App.js +++ b/src/App.js @@ -155,7 +155,7 @@ export default function App() { } {getRoutes(routes)} - } /> + } /> @@ -179,7 +179,7 @@ export default function App() { } {getRoutes(routes)} - } /> + } /> ); diff --git a/src/assets/images/dd.png b/src/assets/images/dd.png new file mode 100644 index 000000000..7e7c2739b Binary files /dev/null and b/src/assets/images/dd.png differ diff --git a/src/examples/Footer/index.js b/src/examples/Footer/index.js index 7acc80d1a..d15628f97 100644 --- a/src/examples/Footer/index.js +++ b/src/examples/Footer/index.js @@ -63,13 +63,14 @@ function Footer({ company, links }) { © {new Date().getFullYear()}, made with - favorite + Co-lance by - {name} + {" "} + 4Twin 2 Co-lance Team{" "} for a better web. @@ -90,9 +91,7 @@ function Footer({ company, links }) { mt: 0, }, })} - > - {renderLinks()} - + > ); } diff --git a/src/examples/Sidenav/index.js b/src/examples/Sidenav/index.js index 5efd2d2c7..ae2193d6e 100644 --- a/src/examples/Sidenav/index.js +++ b/src/examples/Sidenav/index.js @@ -179,19 +179,6 @@ function Sidenav({ color, brand, brandName, routes, ...rest }) { } /> {renderRoutes} - - - upgrade to pro - - ); } diff --git a/src/layouts/products/data/productsTableData.js b/src/layouts/products/data/productsTableData.js new file mode 100644 index 000000000..e945e1aea --- /dev/null +++ b/src/layouts/products/data/productsTableData.js @@ -0,0 +1,56 @@ +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDBadge from "components/MDBadge"; +import PropTypes from 'prop-types'; + +export default function productsTableData(products) { + const ProductInfo = ({ name, category, description, user }) => ( + + + {name} + + {category} + {description} + {user} + + ); + ProductInfo.propTypes = { + name: PropTypes.string.isRequired, + category: PropTypes.string.isRequired, + description: PropTypes.string.isRequired, + user: PropTypes.string.isRequired, + }; + + const randomStatus = () => { + const statuses = ["Available", "Pending", "Sold"]; + return statuses[Math.floor(Math.random() * statuses.length)]; + }; + + const formatRows = products.map(product => ({ + productInfo: , + status: ( + + + + ), + action: ( + + Edit + + ), + })); + + return { + columns: [ + { Header: "product", accessor: "productInfo", width: "45%", align: "left" }, + { Header: "status", accessor: "status", align: "center" }, + { Header: "action", accessor: "action", align: "center" }, + ], + rows: formatRows, + }; +} \ No newline at end of file diff --git a/src/layouts/products/data/productsTableDataRelations.js b/src/layouts/products/data/productsTableDataRelations.js new file mode 100644 index 000000000..d0d1dfeea --- /dev/null +++ b/src/layouts/products/data/productsTableDataRelations.js @@ -0,0 +1,71 @@ +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDBadge from "components/MDBadge"; +import PropTypes from 'prop-types'; + +export default function productsTableDataRelations(products) { + const ProductInfo = ({ name, category, description }) => ( + + + {name} + + {category} + {description} + + ); + ProductInfo.propTypes = { + name: PropTypes.string.isRequired, + category: PropTypes.string.isRequired, + description: PropTypes.string.isRequired, + }; + + const OwnerInfo = ({ userName, userEmail }) => ( + + + {userName} + + {userEmail} + + ); + OwnerInfo.propTypes = { + userName: PropTypes.string.isRequired, + userEmail: PropTypes.string.isRequired, + }; + + const randomStatus = () => { + const statuses = ["Available", "Pending", "Sold"]; + return statuses[Math.floor(Math.random() * statuses.length)]; + }; + + const formatRows = products.map(product => ({ + productInfo: , + owner: , + status: ( + + + + ), + action: ( + + Edit + + ), + })); + + return { + columns: [ + { Header: "product", accessor: "productInfo", width: "30%", align: "left" }, + { Header: "owner", accessor: "owner", width: "30%", align: "left" }, + { Header: "status", accessor: "status", align: "center" }, + { Header: "action", accessor: "action", align: "center" }, + ], + rows: formatRows, + }; +} diff --git a/src/layouts/products/index.js b/src/layouts/products/index.js new file mode 100644 index 000000000..ed3f749d2 --- /dev/null +++ b/src/layouts/products/index.js @@ -0,0 +1,147 @@ +import Grid from "@mui/material/Grid"; +import Card from "@mui/material/Card"; +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import DashboardLayout from "examples/LayoutContainers/DashboardLayout"; +import DashboardNavbar from "examples/Navbars/DashboardNavbar"; +import Footer from "examples/Footer"; +import DataTable from "examples/Tables/DataTable"; +import { useEffect, useState } from "react"; +import productsTableData from "./data/productsTableData"; +import productsTableDataRelations from "./data/productsTableDataRelations"; +import { getProducts, getTypeProducts, getCategoryProducts, getProductsRelations } from "../../services/productService"; +import { Select, MenuItem, FormControl, InputLabel, TextField } from "@mui/material"; +function Products() { + const [tableData, setTableData] = useState({ columns: [], rows: [] }); + const [tableDataRelations, setTableDataRelations] = useState({ columns: [], rows: [] }); + const [productType, setProductType] = useState(""); + const [searchQuery, setSearchQuery] = useState(''); + + async function fetchDataCategory(value) { + try { + + const categoryProducts = await getCategoryProducts(value); + setTableData(productsTableData(categoryProducts)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + + const handleSearchChange = (event) => { + setSearchQuery(event.target.value); + fetchDataCategory(event.target.value) + }; + + + async function fetchDataTypes(value) { + try { + setProductType(value); + const TypeProducts = await getTypeProducts(value); + setTableData(productsTableData(TypeProducts)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + + const handleProductTypeChange = (event) => { + setProductType(event.target.value); + fetchDataTypes(event.target.value); + }; + useEffect(() => { + async function fetchData() { + try { + const Products = await getProducts(); + const ProductsRelations = await getProductsRelations(); + console.log(ProductsRelations); + setTableData(productsTableData(Products)); + setTableDataRelations(productsTableDataRelations(ProductsRelations)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + + fetchData(); + }, []); + + return ( + + + + + + + + + + Products Table + + + + + Type + + Electronics + Non Electronics + + + + + + + + + + + + Products Relation Table + + + + + + + + + + + + ); +} + +export default Products; diff --git a/src/layouts/reclamation/data/reclamationTableData.js b/src/layouts/reclamation/data/reclamationTableData.js new file mode 100644 index 000000000..5d39c1060 --- /dev/null +++ b/src/layouts/reclamation/data/reclamationTableData.js @@ -0,0 +1,100 @@ +/* eslint-disable react/prop-types */ +/* eslint-disable react/function-component-definition */ +/** +========================================================= +* Material Dashboard 2 React - v2.2.0 +========================================================= + +* Product Page: https://www.creative-tim.com/product/material-dashboard-react +* Copyright 2023 Creative Tim (https://www.creative-tim.com) + +Coded by www.creative-tim.com + + ========================================================= + +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +*/ + +// Material Dashboard 2 React components +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDAvatar from "components/MDAvatar"; +import MDBadge from "components/MDBadge"; +import React, { useEffect, useState } from "react"; +import axios from "axios"; +// Images +import dd from "assets/images/dd.png"; +import team3 from "assets/images/team-3.jpg"; +import team4 from "assets/images/team-4.jpg"; +import Reclamation from ".."; + +export default function data() { + const [reclamations, setReclamations] = useState([]); + + useEffect(() => { + // Utilisez useEffect pour effectuer la requête lorsque le composant est monté + axios + .get("http://localhost:8005/api/reclamation/all") + .then((response) => { + // Mettez à jour l'état avec les données de la réponse de l'API + setReclamations(response.data); + }) + .catch((error) => { + // Gérez les erreurs ici, par exemple, en les affichant à l'utilisateur + console.error("Erreur lors de la récupération des données de l'API", error); + }); + }, []); + const ReclamationContent = ({ image, name, email }) => ( + + + + + {name} + + {email} + + + ); + const formatRows = reclamations.map((reclamation) => ({ + reclamationInfo: ( + + ), + description: ( + + {reclamation.description.value} + + ), + status: + reclamation.type.value === "URGENT" ? ( + + done + + ) : ( + + not urgent + + ), + action: ( + + Edit + + ), + })); + + console.log(reclamations); + + return { + columns: [ + { Header: "reclamationInfo", accessor: "reclamationInfo", width: "45%", align: "left" }, + { Header: "Description", accessor: "description", align: "left" }, + { Header: "status", accessor: "status", align: "center" }, + { Header: "action", accessor: "action", align: "center" }, + ], + + rows: formatRows, + }; +} diff --git a/src/layouts/reclamation/index.js b/src/layouts/reclamation/index.js new file mode 100644 index 000000000..4eb8ce957 --- /dev/null +++ b/src/layouts/reclamation/index.js @@ -0,0 +1,75 @@ +/** +========================================================= +* Material Dashboard 2 React - v2.2.0 +========================================================= + +* Product Page: https://www.creative-tim.com/product/material-dashboard-react +* Copyright 2023 Creative Tim (https://www.creative-tim.com) + +Coded by www.creative-tim.com + + ========================================================= + +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +*/ + +// @mui material components +import Grid from "@mui/material/Grid"; +import Card from "@mui/material/Card"; + +// Material Dashboard 2 React components +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; + +// Material Dashboard 2 React example components +import DashboardLayout from "examples/LayoutContainers/DashboardLayout"; +import DashboardNavbar from "examples/Navbars/DashboardNavbar"; +import Footer from "examples/Footer"; +import DataTable from "examples/Tables/DataTable"; + +// Data +import authorsTableData from "./data/reclamationTableData"; + +function Reclamation() { + const { columns, rows } = authorsTableData(); + + return ( + + + + + + + + + Reclamation Table + + + + + + + + + + + + ); +} + +export default Reclamation; diff --git a/src/layouts/reviews/data/reviewsTableData.js b/src/layouts/reviews/data/reviewsTableData.js new file mode 100644 index 000000000..d9aee4dcd --- /dev/null +++ b/src/layouts/reviews/data/reviewsTableData.js @@ -0,0 +1,65 @@ +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDBadge from "components/MDBadge"; +import PropTypes from 'prop-types'; + +export default function ReviewsTableData(reviews) { + const ReviewInfo = ({ feedback, rating, user }) => ( + + + {feedback} + + + User: {user} + + ); + const RatingInfo = ({ rating }) => ( + + + Rating: {rating} + + ); + + RatingInfo.propTypes = { + + rating: PropTypes.string.isRequired, + + }; + ReviewInfo.propTypes = { + feedback: PropTypes.string.isRequired, + rating: PropTypes.string.isRequired, + user: PropTypes.string.isRequired, + }; + + const formatRows = reviews.map(review => ({ + reviewInfo: , + rating: , + status: ( + + + + ), + action: ( + + Edit + + ), + })); + + return { + columns: [ + { Header: "Review", accessor: "reviewInfo", width: "45%", align: "left" }, + { Header: "Rating", accessor: "rating", align: "center" }, + { Header: "Action", accessor: "action", align: "center" }, + ], + rows: formatRows, + }; +} diff --git a/src/layouts/reviews/data/reviewsTableDataRelations.js b/src/layouts/reviews/data/reviewsTableDataRelations.js new file mode 100644 index 000000000..eeeabc8fc --- /dev/null +++ b/src/layouts/reviews/data/reviewsTableDataRelations.js @@ -0,0 +1,57 @@ +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDBadge from "components/MDBadge"; +import PropTypes from 'prop-types'; + +export default function reviewsTableDataRelations(reviews) { + const ReviewInfo = ({ feedback, rating }) => ( + + + {feedback} + + Rating: {rating} + + ); + ReviewInfo.propTypes = { + feedback: PropTypes.string.isRequired, + rating: PropTypes.string.isRequired, + }; + + const UserInfo = ({ userName, userEmail }) => ( + + + {userName} + + {userEmail} + + ); + UserInfo.propTypes = { + userName: PropTypes.string.isRequired, + userEmail: PropTypes.string.isRequired, + }; + + const formatRows = reviews.map(review => ({ + reviewInfo: , + user: , + action: ( + + Edit + + ), + })); + + return { + columns: [ + { Header: "Review", accessor: "reviewInfo", width: "40%", align: "left" }, + { Header: "User", accessor: "user", width: "30%", align: "left" }, + { Header: "Action", accessor: "action", align: "center" }, + ], + rows: formatRows, + }; +} diff --git a/src/layouts/reviews/index.js b/src/layouts/reviews/index.js new file mode 100644 index 000000000..ad6d7ac86 --- /dev/null +++ b/src/layouts/reviews/index.js @@ -0,0 +1,146 @@ +import Grid from "@mui/material/Grid"; +import Card from "@mui/material/Card"; +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import DashboardLayout from "examples/LayoutContainers/DashboardLayout"; +import DashboardNavbar from "examples/Navbars/DashboardNavbar"; +import Footer from "examples/Footer"; +import DataTable from "examples/Tables/DataTable"; +import { useEffect, useState } from "react"; +import reviewsTableData from "./data/reviewsTableData"; +import reviewsTableDataRelations from "./data/reviewsTableDataRelations"; +import { getReviews, getTypeReviews, getRatingReviews, getReviewsRelations } from "../../services/reviewsService"; +import { Select, MenuItem, FormControl, InputLabel, TextField } from "@mui/material"; + +function Reviews() { + const [tableData, setTableData] = useState({ columns: [], rows: [] }); + const [tableDataRelations, setTableDataRelations] = useState({ columns: [], rows: [] }); + const [reviewType, setReviewType] = useState(""); + const [searchQuery, setSearchQuery] = useState(''); + + async function fetchDataRating(value) { + try { + const ratingReviews = await getRatingReviews(value); + setTableData(reviewsTableData(ratingReviews)); + } catch (error) { + console.error("Error fetching reviews data:", error); + } + } + + const handleSearchChange = (event) => { + setSearchQuery(event.target.value); + fetchDataRating(event.target.value) + }; + + async function fetchDataTypes(value) { + try { + setReviewType(value); + const typeReviews = await getTypeReviews(value); + setTableData(reviewsTableData(typeReviews)); + } catch (error) { + console.error("Error fetching reviews data:", error); + } + } + + const handleReviewTypeChange = (event) => { + setReviewType(event.target.value); + fetchDataTypes(event.target.value); + }; + + useEffect(() => { + async function fetchData() { + try { + const reviews = await getReviews(); + const reviewsRelations = await getReviewsRelations(); + console.log(reviewsRelations); + setTableData(reviewsTableData(reviews)); + setTableDataRelations(reviewsTableDataRelations(reviewsRelations)); + } catch (error) { + console.error("Error fetching reviews data:", error); + } + } + + fetchData(); + }, []); + + return ( + + + + + + + + + + Reviews Table + + + + + Type + + Positive + Negative + + + + + + + + + + + + + Reviews Relation Table + + + + + + + + + + + + ); +} + +export default Reviews; diff --git a/src/layouts/user/data/usertable.js b/src/layouts/user/data/usertable.js new file mode 100644 index 000000000..d62165950 --- /dev/null +++ b/src/layouts/user/data/usertable.js @@ -0,0 +1,46 @@ +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import MDBadge from "components/MDBadge"; +import PropTypes from "prop-types"; + +export default function usertable(users) { + const ProductInfo = ({ name }) => ( + + + {name} + + + ); + ProductInfo.propTypes = { + name: PropTypes.string.isRequired, + }; + + const formatRows = users.map((product) => { + const columns = [ + { Header: "Full Name", accessor: "productInfo", width: "45%", align: "left" }, + { Header: "username", accessor: "username", align: "center" }, + { Header: "Email", accessor: "email", align: "center" }, + { Header: "Location", accessor: "location", align: "center" }, + ]; + + // Check if "status" is defined in the user object + if (product.status !== undefined) { + columns.push({ Header: "status", accessor: "status", align: "center" }); + } + + + return { + ...product, + productInfo: , + username: , + email: , + location: , + columns: columns, + }; + }); + + return { + columns: formatRows[0].columns, // Assuming all rows have the same columns + rows: formatRows, + }; +} diff --git a/src/layouts/user/index.js b/src/layouts/user/index.js new file mode 100644 index 000000000..c35ab119a --- /dev/null +++ b/src/layouts/user/index.js @@ -0,0 +1,188 @@ +import Grid from "@mui/material/Grid"; +import Card from "@mui/material/Card"; +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; +import DashboardLayout from "examples/LayoutContainers/DashboardLayout"; +import DashboardNavbar from "examples/Navbars/DashboardNavbar"; +import Footer from "examples/Footer"; +import DataTable from "examples/Tables/DataTable"; +import { useEffect, useState } from "react"; +import usertable from "./data/usertable"; +import { getallusers, gettypeusers, getusers, getusersbylocation } from "./userservice"; +import { FormControl, InputLabel, MenuItem, Select, TextField } from "@mui/material"; + +function Products() { + const [productType, setProductType] = useState(""); + const [tableData, setTableData] = useState({ columns: [], rows: [] }); + const [allusers, setallusers] = useState({ columns: [], rows: [] }); + const [searchQuery, setSearchQuery] = useState(""); + + async function fetchDataCategory(value) { + try { + const categoryProducts = await getusersbylocation(value); + var cleanedusers = cleanProductData(categoryProducts); + setTableData(usertable(cleanedusers)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + + const handleSearchChange = (event) => { + setSearchQuery(event.target.value); + fetchDataCategory(event.target.value); + }; + async function fetchDataTypes(value) { + try { + setProductType(value); + const TypeProducts = await gettypeusers(value); + var cleanedusers = cleanProductData(TypeProducts); + setTableData(usertable(cleanedusers)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + const handleProductTypeChange = (event) => { + setProductType(event.target.value); + fetchDataTypes(event.target.value); + }; + + function cleanProductData(rawData) { + return rawData.map((user) => { + return { + name: user.name.value, + username: user.username.value, + email: user.email.value, + userID: user.userID?.value, + location: user.location.value, + status: user.status?.value, + }; + }); + } + useEffect(() => { + async function fetchData() { + try { + const rawProducts = await getusers(); + const rawallusers = await getallusers(); + const cleanedrawsers = cleanProductData(rawallusers); + const cleanedProducts = cleanProductData(rawProducts); + setTableData(usertable(cleanedProducts)); + setallusers(usertable(cleanedrawsers)); + } catch (error) { + console.error("Error fetching products data:", error); + } + } + + fetchData(); + }, []); + + return ( + + + + + + + + + Users Table + + + + + Type + + + Admin + Guest + IndividualUser + BusinessUser + + + + + + + + + + + + + + + + + + + users Table + + + + + + + + + + + + + ); +} + +export default Products; diff --git a/src/layouts/user/userservice.js b/src/layouts/user/userservice.js new file mode 100644 index 000000000..3dd3dc80b --- /dev/null +++ b/src/layouts/user/userservice.js @@ -0,0 +1,46 @@ +// services/productService.js +import axios from "axios"; + +const BASE_URL = "http://localhost:8005/api/user"; + +const getusers = async () => { + try { + const response = await axios.get(`${BASE_URL}/req`); + return response.data; + } catch (error) { + console.error("Error fetching products", error); + return []; + } +}; +const getallusers = async () => { + try { + const response = await axios.get(`${BASE_URL}/getallusers`); + return response.data; + } catch (error) { + console.error("Error fetching products", error); + return []; + } + }; + +const gettypeusers = async (type) => { + try { + const response = await axios.get(`${BASE_URL}/user/` + type); + return response.data; + console.log(response.data) + } catch (error) { + console.error(`Error fetching products of type ${type}`, error); + return []; + } +}; + +const getusersbylocation = async (location) => { + try { + const response = await axios.get(`${BASE_URL}/filteruser/`+ location) + return response.data; + } catch (error) { + console.error(`Error fetching products of category ${category}`, error); + return []; + } +}; + +export { getusers, gettypeusers, getusersbylocation,getallusers }; diff --git a/src/routes.js b/src/routes.js index a17b439ad..e0e512768 100644 --- a/src/routes.js +++ b/src/routes.js @@ -47,17 +47,53 @@ import SignUp from "layouts/authentication/sign-up"; // @mui icons import Icon from "@mui/material/Icon"; +import Reclamation from "layouts/reclamation"; + +import User from "layouts/user"; + +import Products from "layouts/products"; +import Reviews from "layouts/reviews"; + const routes = [ { type: "collapse", - name: "Dashboard", + name: "Reclamation", key: "dashboard", - icon: dashboard, - route: "/dashboard", - component: , + icon: Reclamation, + route: "/reclamation", + component: , + }, + { + type: "collapse", + + name: "User", + key: "user", + icon: User, + route: "/user", + component: < User/>, + }, + { + + name: "Products", + key: "dashboard1", + icon: Products, + route: "/products", + component: , }, { + type: "collapse", + name: "Reviews", + key: "Reviews", + icon: Reviews, + route: "/reviews", + component: , + }, + +]; + +export default routes; +/**{ type: "collapse", name: "Tables", key: "tables", @@ -112,7 +148,4 @@ const routes = [ icon: assignment, route: "/authentication/sign-up", component: , - }, -]; - -export default routes; + }, */ diff --git a/src/services/productService.js b/src/services/productService.js new file mode 100644 index 000000000..bd10d5e48 --- /dev/null +++ b/src/services/productService.js @@ -0,0 +1,65 @@ +import axios from "axios"; + +const BASE_URL = "http://localhost:8005/api/products"; + +const cleanseData = (rawData, fields) => { + return rawData.map(item => { + const cleansedItem = {}; + fields.forEach(field => { + if (item[field]) { + cleansedItem[field] = item[field].value; + } + }); + return cleansedItem; + }); +}; + +const getProducts = async () => { + try { + const response = await axios.get(`${BASE_URL}/list`); + const fields = ['name', 'productID', 'category', 'user', 'description']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error("Error fetching products", error); + return []; + } +}; + +const getTypeProducts = async (type) => { + try { + const response = await axios.get(`${BASE_URL}/getByType`, { params: { type } }); + const fields = ['name', 'productID', 'category', 'user', 'description']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error(`Error fetching products of type ${type}`, error); + return []; + } +}; + +const getCategoryProducts = async (category) => { + try { + const response = await axios.get(`${BASE_URL}/getByCategory`, { params: { category } }); + const fields = ['name', 'productID', 'category', 'user', 'description']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error(`Error fetching products of category ${category}`, error); + return []; + } +}; +const getProductsRelations = async () => { + try { + const response = await axios.get(`${BASE_URL}/getProductsRelations`); + const fields = ['name', 'productID', 'category', 'description', 'userName', 'userEmail']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error("Error fetching product relations", error); + return []; + } +}; + + +export { getProducts, getTypeProducts, getCategoryProducts, getProductsRelations }; \ No newline at end of file diff --git a/src/services/reviewsService.js b/src/services/reviewsService.js new file mode 100644 index 000000000..7773e46fd --- /dev/null +++ b/src/services/reviewsService.js @@ -0,0 +1,65 @@ +import axios from "axios"; + +const REVIEWS_BASE_URL = "http://localhost:8005/api/reviews"; + +const cleanseData = (rawData, fields) => { + return rawData.map(item => { + const cleansedItem = {}; + fields.forEach(field => { + if (item[field]) { + cleansedItem[field] = item[field].value; + } + }); + return cleansedItem; + }); +}; + +const getReviews = async () => { + try { + const response = await axios.get(`${REVIEWS_BASE_URL}/list`); + const fields = ['reviewID', 'rating', 'feedback', 'user']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error("Error fetching reviews", error); + return []; + } +}; + +const getTypeReviews = async (type) => { + try { + const response = await axios.get(`${REVIEWS_BASE_URL}/getByType`, { params: { type } }); + const fields = ['reviewID', 'rating', 'feedback', 'user']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error(`Error fetching reviews of type ${type}`, error); + return []; + } +}; + +const getRatingReviews = async (rating) => { + try { + const response = await axios.get(`${REVIEWS_BASE_URL}/getByRating`, { params: { rating } }); + const fields = ['reviewID', 'rating', 'feedback', 'user']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error(`Error fetching reviews with rating ${rating}`, error); + return []; + } +}; + +const getReviewsRelations = async () => { + try { + const response = await axios.get(`${REVIEWS_BASE_URL}/getReviewsRelations`); + const fields = ['reviewID', 'rating', 'feedback', 'userName', 'userEmail']; + const cleansedData = cleanseData(response.data, fields); + return cleansedData; + } catch (error) { + console.error("Error fetching review relations", error); + return []; + } +}; + +export { getReviews, getTypeReviews, getRatingReviews, getReviewsRelations };