Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User profile #10

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ab6aa58
Create test.txt
ematthewephec Mar 1, 2023
24b71f9
CREATE index.js
GabrielleCruz99Official Mar 8, 2023
7fe25f7
CREATE database.js
GabrielleCruz99Official Mar 8, 2023
8baff37
ADD backend product route
GabrielleCruz99Official Mar 8, 2023
735df26
ADD package.json
GabrielleCruz99Official Mar 8, 2023
95e7c74
Merge pull request #2 from ematthewephec/1-technical-task-set-up-node…
GabrielleCruz99Official Mar 14, 2023
8b441b2
3 technical task install and set up reactjs environment (#4)
GabrielleCruz99Official Mar 15, 2023
23a98bc
Add files via upload
aurelle-awountsa Mar 15, 2023
d12471d
Add files via upload
aurelle-awountsa Mar 15, 2023
ae60acb
FEAT: US1 création de la partie frontend de la page articles et modif…
quentinrld Mar 21, 2023
352f30d
FEAT: Modification de la navbar pour correspondre au style
quentinrld Mar 22, 2023
5fa9d17
ADD database tables (#7)
GabrielleCruz99Official Apr 26, 2023
cacdebd
feat[US1]: Connexion à la DB et recherche dynamique des information c…
quentinrld Apr 26, 2023
1e59465
5 us03 add overview of client basket (#9)
GabrielleCruz99Official May 2, 2023
f870814
Merge branch 'dev' into US1
quentinrld May 2, 2023
e2b29f3
Merge pull request #8 from ematthewephec/US1
quentinrld May 2, 2023
b565976
12 us04 add item removal from basket (#13)
GabrielleCruz99Official May 3, 2023
51e4741
fit(US2) : en vue de pouvoir rajouter des articles dans notre panier …
quentinrld May 10, 2023
c173bfc
debut footer
quentinrld May 11, 2023
7a3585c
14 us05 clear user basket (#15)
GabrielleCruz99Official May 21, 2023
684b10d
ADD database scripts (#11)
GabrielleCruz99Official May 22, 2023
e46b74d
Update ArticlesCard.test.js
quentinrld May 23, 2023
09f8882
footer
quentinrld May 23, 2023
6b4df1b
update footer
quentinrld May 23, 2023
da111f3
Merge pull request #18 from ematthewephec/US2
quentinrld May 23, 2023
a7d7bd6
16 us06 user registration (#19)
GabrielleCruz99Official May 24, 2023
19b63f7
build
quentinrld Jun 3, 2023
0691225
Facture (#26)
GabrielleCruz99Official Jun 8, 2023
7775a9a
init branch
FrancoisT97 Aug 18, 2023
5e271a2
add profile redirection + resolve bugs
FrancoisT97 Aug 18, 2023
12b5710
récupération info db profile + address
FrancoisT97 Aug 20, 2023
60ae1d9
update db with lastName, add update profile
FrancoisT97 Aug 20, 2023
25fe77f
add toast success + error
FrancoisT97 Aug 20, 2023
98941ae
add verivication id email exists
FrancoisT97 Aug 20, 2023
075eae0
resolve error start server
FrancoisT97 Aug 21, 2023
ad18b50
update connect page display
FrancoisT97 Aug 21, 2023
78ebce4
initialise connection page + error message and backend for connection
FrancoisT97 Aug 21, 2023
0d61f6a
import redux
FrancoisT97 Aug 21, 2023
4aeddf9
verify connection aned add deconnexion
FrancoisT97 Aug 21, 2023
fbffe27
add refresh on deconnection + welcome display
FrancoisT97 Aug 21, 2023
d9a74ad
Merge pull request #29 from ematthewephec/SignIn
FrancoisT97 Aug 22, 2023
57ed7a1
Merge branch 'dev' into userProfile
FrancoisT97 Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
package-lock.json
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/Dev-Web-2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/dictionaries/matthew.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
'@babel/preset-env',
['@babel/preset-react', {runtime: 'automatic'}],
],
};
15 changes: 15 additions & 0 deletions backend/helpers/cleardatabase.sql
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions backend/helpers/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: '127.0.0.1',
user: 'root',
password: 'root',
database: 'informateur',
port: 3307,
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;
80 changes: 80 additions & 0 deletions backend/helpers/database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
CREATE TABLE Users (
UserID INT NOT NULL AUTO_INCREMENT,
UserName VARCHAR(60),
UserFirstname 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,
City VARCHAR(30),
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)
);
16 changes: 16 additions & 0 deletions backend/helpers/dummydata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
INSERT INTO Users(UserName, UserEmail, UserPassword, CreationDate) VALUES
('Toto', '[email protected]', 'totoiscool', NOW()),
('Tata', '[email protected]', '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);
5 changes: 5 additions & 0 deletions backend/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function getCurrentDate(){
return new Date().toISOString().slice(0, 19).replace('T', ' ');
}

module.exports = getCurrentDate;
44 changes: 44 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const express = require('express');
const dotenv = require('dotenv');

dotenv.config({path: '.env'});
const PORT = process.env.PORT || 3001;
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
//const session = require('express-session');
//const config = require('./config/auth.conf');

const cors = require('cors');
const corsOptions = {
origin: 'http://localhost:3000',
methods: ['GET', 'POST', 'DELETE']
};

/* ROUTE IMPORT */
const products = require('./routes/product');
const facture = require('./routes/facture');
const baskets = require('./routes/basket');
const users = require('./routes/user');

const app = express();

/* MIDDLEWARE */
app.use(cors(corsOptions));
app.use(express.json());
app.use(bodyParser.urlencoded({extended: true}));
//app.use(session(config));
//app.use(cookieParser())

/* API */
app.get('/', (req, res) => {
res.status(200).send("Le site web pour les abonnements des tuyaux informatiques!");
});

app.use('/products', products);
app.use('/facture', facture);
app.use('/baskets', baskets);
app.use('/users', users);

app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
});
60 changes: 60 additions & 0 deletions backend/routes/basket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const express = require('express');
const router = express.Router();
const pool = require('../helpers/database');

router.get('/', (req, res) => {
res.status(200).send("This is the basket route of the API!");
});

router.get('/:userId', async(req, res) => {
try {
const userId = req.params.userId;
const basketQuery = 'SELECT ItemIndex, Products.ProductName, \
Products.ProductPrice, ItemQuantity \
FROM Baskets INNER JOIN Users ON Baskets.UserID=Users.UserID INNER JOIN \
Products ON Baskets.ProductID=Products.ProductID WHERE Baskets.UserID=?';
const result = await pool.query(basketQuery, userId);
res.status(200).json(result);
} catch (err) {
res.status(404).send('User not found!');
}
});
router.post('/add/:userId/:productId/:quantity', async(req, res) => {
const {userId, productId, quantity} = req.params;
const basketQuery = 'INSERT INTO Baskets (UserID, ProductID, ItemQuantity) VALUES (?, ?, ?)';
const result = await pool.query(basketQuery, ['1', productId, '1']);
res.status(200).json(result);
});

router.delete('/:userId', async(req, res) => {
try{
const userId = req.params.userId;
const itemIndex = req.body.itemIndex;
const basketQuery = 'DELETE FROM Baskets WHERE UserID=? AND ItemIndex=?';
const result = await pool.query(basketQuery, [userId, itemIndex]);
result.affectedRows === 0 ?
(await pool.query('SELECT * FROM Users WHERE UserID=?', userId)).length === 0 ?
res.status(404).send('User not found!') :
res.status(404).send('Item not found!') :
res.status(200).json(result);
} catch (err) {
res.status(404).send('Not found!');
}
})

router.delete('/:userId/clear', async(req, res) => {
try {
const userId = req.params.userId;
const basketQuery = 'DELETE FROM Baskets WHERE UserID=?';
const result = await pool.query(basketQuery, userId);
result.affectedRows === 0 ?
(await pool.query('SELECT * FROM Users WHERE UserID=?', userId)).length === 0 ?
res.status(404).send('User not found!') :
res.status(404).send('No items found in basket!') :
res.status(200).json(result);
} catch (err) {
res.status(404).send('Not found!');
}
})

module.exports = router;
Loading