diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..941d53615e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +node_modules +package-lock.json \ No newline at end of file diff --git a/apparence.png b/apparence.png new file mode 100644 index 0000000000..c4851fb197 Binary files /dev/null and b/apparence.png differ diff --git a/architecture react.png b/architecture react.png new file mode 100644 index 0000000000..ab9fe49a3c Binary files /dev/null and b/architecture react.png differ diff --git a/backend/helpers/cleardatabase.sql b/backend/helpers/cleardatabase.sql new file mode 100644 index 0000000000..17bec8683d --- /dev/null +++ b/backend/helpers/cleardatabase.sql @@ -0,0 +1,15 @@ +DELETE FROM Users; +DELETE FROM Products; +DELETE FROM Orders; +DELETE FROM Subscriptions; +DELETE FROM Baskets; +DELETE FROM Addresses; +DELETE FROM AdminUsers; + +DROP TABLE Users; +DROP TABLE Products; +DROP TABLE Orders; +DROP TABLE Subscriptions; +DROP TABLE Baskets; +DROP TABLE Addresses; +DROP TABLE AdminUsers; \ No newline at end of file diff --git a/backend/helpers/database.js b/backend/helpers/database.js new file mode 100644 index 0000000000..0b935041d7 --- /dev/null +++ b/backend/helpers/database.js @@ -0,0 +1,30 @@ +const mariadb = require('mariadb'); +const pool = mariadb.createPool({ + host: process.env.HOST, + user: process.env.USER, + password: process.env.PASSWORDDB, + database: process.env.DATABASE, + port: process.env.PORTDB, + connectionLimit: 5, + supportBigNumbers: true, + bigNumberStrings: true, +}); + +// connect and check for errors +pool.getConnection((err, connection) => { + if (err) { + if (err.code === 'PROTOCOL_CONNECTION_LOST') { + console.error('Database connection lost'); + } + if (err.code === 'ER_CON_COUNT_ERROR') { + console.error('Database has too many connections'); + } + if (err.code === 'ECONNREFUSED') { + console.error('Database connection was refused'); + } + } + if (connection) connection.release(); + return; +}); + +module.exports = pool; \ No newline at end of file diff --git a/backend/helpers/database.sql b/backend/helpers/database.sql new file mode 100644 index 0000000000..ec865f6da3 --- /dev/null +++ b/backend/helpers/database.sql @@ -0,0 +1,78 @@ +CREATE TABLE Users ( + UserID INT NOT NULL AUTO_INCREMENT, + UserName VARCHAR(60), + UserEmail VARCHAR(60), + UserPassword VARCHAR(60), + CreationDate DATE, + DeletionDate DATE, + PRIMARY KEY (UserID) +); + +CREATE TABLE Products ( + ProductID INT NOT NULL AUTO_INCREMENT, + ProductName VARCHAR(60), + ProductStock INT, + ProductDesc TEXT, + ProductPrice DECIMAL(6,2), + ProductOnSale BOOLEAN, + PRIMARY KEY (ProductID) +); + +CREATE TABLE Addresses ( + AddressID INT NOT NULL AUTO_INCREMENT, + UserID INT, + Street VARCHAR(100), + Postcode INT, + Country VARCHAR(30), + PRIMARY KEY (AddressID), + FOREIGN KEY (UserID) REFERENCES Users(UserID) +); + +CREATE TABLE Orders ( + OrderID INT NOT NULL AUTO_INCREMENT, + UserID INT, + ProductID INT, + OrderSubtotal INT, + OrderDate DATE, + SubscriptionID INT, + PaidDate DATE, + DeliveryDate DATE, + WasPaid BOOLEAN DEFAULT false, + WasDelivered BOOLEAN DEFAULT false, + NumItems INT NOT NULL DEFAULT 1, + PRIMARY KEY (OrderID), + FOREIGN KEY (UserID) REFERENCES Users(UserID), + FOREIGN KEY (ProductID) REFERENCES Products(ProductID), + FOREIGN KEY (SubscriptionID) REFERENCES Subscriptions(SubscriptionID) +); + +CREATE TABLE Baskets ( + UserID INT, + ItemIndex INT NOT NULL AUTO_INCREMENT, + ItemQuantity INT NOT NULL DEFAULT 1, + ProductID INT, + PRIMARY KEY (ItemIndex), + FOREIGN KEY (UserID) REFERENCES Users(UserID), + FOREIGN KEY (ProductID) REFERENCES Products(ProductID) +); + +CREATE TABLE Subscriptions ( + SubscriptionID INT NOT NULL AUTO_INCREMENT, + UserID INT, + ProductID INT, + SubscriptionStart DATE, + SubscriptionEnd DATE, + SubscriptionLength INT, + PRIMARY KEY (SubscriptionID), + FOREIGN KEY (UserID) REFERENCES Users(UserID), + FOREIGN KEY (ProductID) REFERENCES Products(ProductID) +); + +CREATE TABLE AdminUsers ( + AdminUserID INT NOT NULL AUTO_INCREMENT, + AdminUserName VARCHAR(60), + AdminUserEmail VARCHAR(60), + AdminUserPassword VARCHAR(60), + AdminAccess BOOLEAN, + PRIMARY KEY (AdminUserID) +); \ No newline at end of file diff --git a/backend/helpers/dummydata.sql b/backend/helpers/dummydata.sql new file mode 100644 index 0000000000..4ad7929b81 --- /dev/null +++ b/backend/helpers/dummydata.sql @@ -0,0 +1,16 @@ +INSERT INTO Users(UserName, UserEmail, UserPassword, CreationDate) VALUES +('Toto', 'toto@gmail.com', 'totoiscool', NOW()), +('Tata', 'tata@gmail.com', 'tataiscool', NOW()); + +INSERT INTO Products(ProductName, ProductStock, ProductDesc, ProductPrice, ProductOnSale) VALUES +('Test Product 1', 50, 'This is the first test product.', 10.00, TRUE), +('Test Product 2', 20, 'This is the second test product.', 20.00, TRUE), +('Test Product 3', 10, 'This is the third test product.', 50.00, TRUE); + +INSERT INTO Baskets(UserID, ItemQuantity, ProductID) VALUES +(1, 2, 1), +(2, 1, 3); + +INSERT INTO Orders(UserID, ProductID, OrderSubtotal, OrderDate, NumItems) VALUES +(1, 1, 20, NOW(), 2), +(2, 3, 50, NOW(), 1); diff --git a/backend/index.js b/backend/index.js new file mode 100644 index 0000000000..3b2a6bef81 --- /dev/null +++ b/backend/index.js @@ -0,0 +1,32 @@ +const express = require('express'); +const PORT = process.env.PORT || 3001; + +const bodyParser = require('body-parser'); +const cookieParser = require('cookie-parser'); + +const cors = require('cors'); +const corsOptions = { + origin: 'http://localhost:3000', + methods: ['GET', 'POST'] +}; + +/* ROUTE IMPORT */ +const products = require('./routes/product'); + +const app = express(); + +/* MIDDLEWARE */ +app.use(cors(corsOptions)); +app.use(express.json()); +app.use(bodyParser.urlencoded({extended: true})); + +/* API */ +app.get('/', (req, res) => { + res.status(200).send("Le site web pour les abonnements des tuyaux informatiques!"); +}); + +app.use('/products', products); + +app.listen(PORT, () => { + console.log(`Server listening on ${PORT}`); +}); \ No newline at end of file diff --git a/backend/routes/product.js b/backend/routes/product.js new file mode 100644 index 0000000000..5efdfc71e4 --- /dev/null +++ b/backend/routes/product.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); +//const pool = require('../helpers/database'); + +router.get('/', (req, res) => { + res.status(200).send("This is the product route of the API!"); +}) + +module.exports = router; \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000000..4d29575de8 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 0000000000..58beeaccd8 --- /dev/null +++ b/frontend/README.md @@ -0,0 +1,70 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can't go back!** + +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. + +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000000..42405cb9d5 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,50 @@ +{ + "name": "dev-web-2023-frontend", + "version": "1.0.0", + "private": true, + "description": "This is the frontend package for Informateur.", + "main": "index.js", + "repository": { + "type": "git", + "url": "\"git+https://github.com/ematthewephec/Dev-Web-2023.git\"" + }, + "author": "Gabrielle Cruz", + "license": "ISC", + "dependencies": { + "@testing-library/jest-dom": "^5.16.5", + "@testing-library/react": "^13.4.0", + "@testing-library/user-event": "^13.5.0", + "axios": "^1.3.4", + "bootstrap": "^5.2.3", + "react": "^18.2.0", + "react-bootstrap": "^2.7.2", + "react-dom": "^18.2.0", + "react-router-dom": "^6.9.0", + "react-scripts": "5.0.1", + "web-vitals": "^2.1.4" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico new file mode 100644 index 0000000000..a11777cc47 Binary files /dev/null and b/frontend/public/favicon.ico differ diff --git a/frontend/public/index.html b/frontend/public/index.html new file mode 100644 index 0000000000..aa069f27cb --- /dev/null +++ b/frontend/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/frontend/public/logo192.png b/frontend/public/logo192.png new file mode 100644 index 0000000000..fc44b0a379 Binary files /dev/null and b/frontend/public/logo192.png differ diff --git a/frontend/public/logo512.png b/frontend/public/logo512.png new file mode 100644 index 0000000000..a4e47a6545 Binary files /dev/null and b/frontend/public/logo512.png differ diff --git a/frontend/public/manifest.json b/frontend/public/manifest.json new file mode 100644 index 0000000000..080d6c77ac --- /dev/null +++ b/frontend/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/frontend/public/robots.txt b/frontend/public/robots.txt new file mode 100644 index 0000000000..e9e57dc4d4 --- /dev/null +++ b/frontend/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/frontend/src/components/app/App.css b/frontend/src/components/app/App.css new file mode 100644 index 0000000000..74b5e05345 --- /dev/null +++ b/frontend/src/components/app/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/frontend/src/components/app/App.js b/frontend/src/components/app/App.js new file mode 100644 index 0000000000..f053430fc0 --- /dev/null +++ b/frontend/src/components/app/App.js @@ -0,0 +1,20 @@ +import React from 'react'; +import './App.css'; +import { Routes, Route } from 'react-router-dom'; +import 'bootstrap/dist/css/bootstrap.min.css'; +import IndexPage from '../indexpage/IndexPage'; +import BasicNavbar from '../utils/BasicNavbar'; + +function App() { + return ( +
+ + }> + } /> + + +
+ ); +} + +export default App; diff --git a/frontend/src/components/app/App.test.js b/frontend/src/components/app/App.test.js new file mode 100644 index 0000000000..1f03afeece --- /dev/null +++ b/frontend/src/components/app/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/frontend/src/components/common/Navigation.js b/frontend/src/components/common/Navigation.js new file mode 100644 index 0000000000..ef207bbe53 --- /dev/null +++ b/frontend/src/components/common/Navigation.js @@ -0,0 +1,33 @@ +import React from 'react'; + +import Container from 'react-bootstrap/Container'; +import Nav from 'react-bootstrap/Nav'; +import Navbar from 'react-bootstrap/Navbar'; + +import logo from '../../logo.svg'; + + +function Navigation(){ + return( + + + + Informateur + + + + + + + + ) +} + +export default Navigation; \ No newline at end of file diff --git a/frontend/src/components/indexpage/IndexPage.js b/frontend/src/components/indexpage/IndexPage.js new file mode 100644 index 0000000000..da03e8b2be --- /dev/null +++ b/frontend/src/components/indexpage/IndexPage.js @@ -0,0 +1,35 @@ +import React, {useEffect, useState} from 'react'; +import Axios from 'axios'; +import Card from 'react-bootstrap/Card'; +import {AXIOS_CONFIG, INDEX_URL} from '../utils/Constants'; +//import './FrontPage.css'; + +function IndexPage(){ + const [title, setTitle] = useState(""); + + const getIndexHello = async () => { + Axios.get(INDEX_URL) + .then((response) => { + setTitle(response.data) + }); + }; + + useEffect(() => { + getIndexHello(); + }, []); + + return( +
+ + + Bienvenue chez Informateur + + {title} + + + +
+ ) +} + +export default IndexPage; diff --git a/frontend/src/components/utils/BasicNavbar.js b/frontend/src/components/utils/BasicNavbar.js new file mode 100644 index 0000000000..0609a50f93 --- /dev/null +++ b/frontend/src/components/utils/BasicNavbar.js @@ -0,0 +1,14 @@ +import React from 'react'; +import Navigation from '../common/Navigation'; +import { Outlet } from 'react-router-dom'; + +const BasicNavbar = () => { + return( + <> + + + + ) +} + +export default BasicNavbar; \ No newline at end of file diff --git a/frontend/src/components/utils/Constants.js b/frontend/src/components/utils/Constants.js new file mode 100644 index 0000000000..fab49ba918 --- /dev/null +++ b/frontend/src/components/utils/Constants.js @@ -0,0 +1,8 @@ +export const INDEX_URL = `http://localhost:3001/`; + +export const AXIOS_CONFIG = { + headers: { + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json' + } +}; \ No newline at end of file diff --git a/frontend/src/index.css b/frontend/src/index.css new file mode 100644 index 0000000000..ec2585e8c0 --- /dev/null +++ b/frontend/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/frontend/src/index.js b/frontend/src/index.js new file mode 100644 index 0000000000..45560674bb --- /dev/null +++ b/frontend/src/index.js @@ -0,0 +1,20 @@ +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import {BrowserRouter} from 'react-router-dom'; +import App from './components/app/App'; +import './index.css'; +import reportWebVitals from './reportWebVitals'; + +const root = ReactDOM.createRoot(document.getElementById('root')); +root.render( + + + + + +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/frontend/src/logo.svg b/frontend/src/logo.svg new file mode 100644 index 0000000000..9dfc1c058c --- /dev/null +++ b/frontend/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/reportWebVitals.js b/frontend/src/reportWebVitals.js new file mode 100644 index 0000000000..5253d3ad9e --- /dev/null +++ b/frontend/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/frontend/src/setupTests.js b/frontend/src/setupTests.js new file mode 100644 index 0000000000..8f2609b7b3 --- /dev/null +++ b/frontend/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/package.json b/package.json new file mode 100644 index 0000000000..5889bce212 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "dev-web-2023-backend", + "version": "1.0.0", + "description": "This is the repository for Informateur, a DEV 3 2023 project.", + "main": "index.js", + "scripts": { + "server": "nodemon backend/index.js", + "client": "npm start --prefix frontend", + "dev": "concurrently \"npm run server\" \"npm run client\"", + "test": "\"echo \\\"Error: no test specified\\\" && exit 1\"" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ematthewephec/Dev-Web-2023.git" + }, + "author": "Gabrielle Cruz", + "license": "ISC", + "bugs": { + "url": "https://github.com/ematthewephec/Dev-Web-2023/issues" + }, + "homepage": "https://github.com/ematthewephec/Dev-Web-2023#readme", + "dependencies": { + "axios": "^1.3.4", + "axios-hooks": "^4.0.0", + "body-parser": "^1.20.2", + "concurrently": "^7.6.0", + "cookie-parser": "^1.4.6", + "cors": "^2.8.5", + "create-react-app": "^5.0.1", + "express": "^4.18.2", + "express-session": "^1.17.3", + "mariadb": "^3.1.0", + "nodemon": "^2.0.21" + } +} diff --git a/test.txt b/test.txt new file mode 100644 index 0000000000..2b1844d816 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +hello my name is jeff