Skip to content

Commit

Permalink
modifywrite
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitounmax committed Jul 21, 2023
1 parent 9d8a86b commit 636596e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ CREATE TABLE post (

INSERT INTO post (title, description, image) VALUES ('New Title', 'New Description', 'new_image.jpg');
UPDATE post SET title = 'Updated Title', description = 'Updated Description' WHERE id = 1;
DELETE FROM post WHERE id = 3;
8 changes: 7 additions & 1 deletion backend/src/models/PostManager .js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ class PostManager extends AbstractManager {

insert(post) {
return this.database.query(
`insert into ${this.table} (title, description, image) values (?, ?, ?)`,
`INSERT INTO ${this.table} (title, description, image) VALUES (?, ?, ?)`,
[post.title, post.description, post.image]
);
}

delete(post) {
return this.database.query(`DELETE FROM ${this.table} WHERE id = ?`, [
post.id,
]);
}
}

module.exports = PostManager;
Binary file added frontend/src/img/fond.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion frontend/src/pages/Write.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function Write() {
};

const updateProject = () => {
// Envoyer une requête PUT pour mettre à jour le projet
fetch("/posts/1", {
method: "PUT",
headers: {
Expand All @@ -42,12 +41,36 @@ function Write() {
.then((response) => response.json())
.then((data) => {
console.info(data);
alert("Modification réussi");

Check warning on line 44 in frontend/src/pages/Write.jsx

View workflow job for this annotation

GitHub Actions / lint / Run linters

Unexpected alert
})
.catch((error) => {
console.error(error);
});
};

const deleteProject = () => {
fetch("http://localhost:8000/", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
description: value,
image: "https://picsum.photos/200/300",
}),
})
.then((response) => {
if (response.ok) {
alert("Suppresion réussi");

Check warning on line 65 in frontend/src/pages/Write.jsx

View workflow job for this annotation

GitHub Actions / lint / Run linters

Unexpected alert
}
})
.catch((error) => {
console.error(error);
// Traiter l'erreur ici si nécessaire
});
};

return (
<div className="add">
<div className="content">
Expand Down Expand Up @@ -86,6 +109,9 @@ function Write() {
<button type="button" onClick={updateProject}>
Mettre à jour
</button>
<button type="button" onClick={deleteProject}>
Supprimer
</button>
</div>
</div>
<div className="item">
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ $lightGreen: #b9e7e7;
.app {
display: flex;
justify-content: center;

.container {
width: 1024px;

Expand All @@ -22,7 +23,7 @@ $lightGreen: #b9e7e7;

h1 {
font-size: 20px;
color: teal;
color: rgb(255, 255, 255);
margin-bottom: 20px;
}

Expand All @@ -43,7 +44,7 @@ $lightGreen: #b9e7e7;
button {
padding: 10px;
border: none;
background-color: teal;
background-color: rgb(208, 198, 14);
cursor: pointer;
color: white;
}
Expand Down Expand Up @@ -101,17 +102,16 @@ $lightGreen: #b9e7e7;
border: 1px solid white;

&:hover {
color: teal;
color: rgb(196, 142, 15);
background-color: white;
border: 1px solid teal;
border: 1px solid rgb(182, 138, 3);
}
}
}
}
}

//FOOTER

footer {
margin-top: 100px;
padding: 20px;
Expand All @@ -121,6 +121,8 @@ $lightGreen: #b9e7e7;
align-items: center;
justify-content: space-between;
font-size: 12px;
flex-direction: row; /* Ajouter cette ligne pour aligner horizontalement */

img {
height: 50px;
}
Expand Down Expand Up @@ -185,7 +187,7 @@ $lightGreen: #b9e7e7;
border: none;
background-color: rgb(244, 142, 8);
border: 1px solid rgb(128, 43, 0);
color: teal;
color: rgb(255, 255, 255);

&:hover {
border: 1px solid white;
Expand Down

0 comments on commit 636596e

Please sign in to comment.