Skip to content

Commit

Permalink
routes users OK
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelemeriau committed Dec 13, 2023
2 parents 3b2355d + a118ed3 commit 7a213b8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 22 deletions.
23 changes: 22 additions & 1 deletion backend/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CREATE TABLE
`id` int primary key auto_increment not null,
`name` varchar(50) not null,
`email` varchar(50) not null,
`naissance` DATETIME NOT NULL,
`naissance` DATE NOT NULL,
`civility` BOOLEAN NOT NULL,
`password` varchar(50) not null,
`IsAdmin` bool not null
Expand Down Expand Up @@ -197,3 +197,24 @@ VALUES
('Sport', 18),
('War', 19),
('Western', 20);

INSERT INTO
`User` (`name`, `email`,`naissance`, `civility`, `password`, `IsAdmin`)
VALUES
(
'Aurel',
'[email protected]',
'1983/06/10',
'0',
'ggfd4554',
'0'
),
(
'Alex',
'[email protected]',
'1998/03/19',
'0',
'ggfd455',
'0'
);

2 changes: 1 addition & 1 deletion backend/src/controllers/filmControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const add = async (req, res, next) => {
};

const destroy = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
try {
const result = await tables.film.delete(id);
if (result.affectedRows) {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/controllers/userControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ const read = async (req, res, next) => {

// eslint-disable-next-line consistent-return
const edit = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
req.body.id = id;
try {
const result = await tables.user.update(req.body);
if (result.affectedRows > 0) {
if (result) {
res.json(result);
res.status(204);
} else {
return res.status(404).send("Not found");
return res.sendStatus(404);
}
} catch (err) {
next(err);
Expand All @@ -61,7 +61,7 @@ const add = async (req, res, next) => {

try {
// Insert the item into the database
const insertId = await tables.item.create(user);
const insertId = await tables.user.create(user);

// Respond with HTTP 201 (Created) and the ID of the newly inserted item
res.status(201).json({ insertId });
Expand All @@ -74,7 +74,7 @@ const add = async (req, res, next) => {
// The D of BREAD - Destroy (Delete) operation
// This operation is not yet implemented
const destroy = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
try {
const result = await tables.user.delete(id);
if (result.affectedRows) {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/models/FilmManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FilmManager extends AbstractManager {
isAvailable,
}) {
const [result] = await this.database.query(
`insert into ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable) values (?,?,?,?,?,?)`,
`insert into ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable) values (?,?,?,?,?,?,?)`,
[miniature, title, videoUrl, duration, year, description, isAvailable]
);
return result.insertId;
Expand Down Expand Up @@ -52,8 +52,8 @@ class FilmManager extends AbstractManager {
}

async delete(id) {
const [result] = await this.database.query(
`delete * from ${this.table} where id = ?`,
const result = await this.database.query(
`delete from ${this.table} where id = ?`,
[id]
);
return result;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/models/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UserManager extends AbstractManager {
async update({ name, email, naissance, civility, password, IsAdmin, id }) {
// Execute the SQL UPDATE query to update a item to the "user" table
const [result] = await this.database.query(
`UPDATE ${this.table} SET name=?, email=?, naissance=?, civilty=?, password=?, IsAdmin=? WHERE id=?`,
`UPDATE ${this.table} SET name=?, email=?, naissance=?, civility=?, password=?, IsAdmin=? WHERE id=?`,
[name, email, naissance, civility, password, IsAdmin, id]
);

Expand All @@ -58,7 +58,7 @@ class UserManager extends AbstractManager {

async delete(id) {
const [rows] = await this.database.query(
`DELETE FROM * from ${this.table} where id = ?`,
`DELETE from ${this.table} where id = ?`,
[id]
);

Expand Down
16 changes: 7 additions & 9 deletions backend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,30 @@ const serieControllers = require("./controllers/serieControllers");
// Route to get a list of items
router.get("/categories", categorieControllers.browse);
router.get("/films", filmControllers.browse);
router.get("/series", serieControllers.browse);
router.get("/users", userControllers.browse);
router.get("/serie", serieControllers.browse);

// Route to get a specific item by ID
router.get("/categories/:id", categorieControllers.read);
router.get("/films/:id", filmControllers.read);
router.get("/series/:id", serieControllers.read);
router.get("/users/:id", userControllers.read);
router.get("/serie/:id", serieControllers.read);

// Route to edit a specific item by ID
router.put("/films/:id", filmControllers.edit);
router.put("/serie/:id", serieControllers.edit);
router.put("/series/:id", serieControllers.edit);
router.put("/users/:id", userControllers.edit);

// Route to add a new item
router.post("/categories", categorieControllers.add);
router.post("/films", filmControllers.add);
router.post("/series", serieControllers.add);
router.post("/users", userControllers.add);
router.post("/serie", serieControllers.add);

// Route to Update a new item

// Route to Delete a new item

// Route to detele a specific item by ID
router.delete("/films/:id", filmControllers.destroy);
router.delete("/serie/:id", serieControllers.destroy);
router.delete("/series/:id", serieControllers.destroy);
router.delete("/users/:id", userControllers.destroy);
/* ************************************************************************* */

module.exports = router;
2 changes: 1 addition & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function App() {
</div>
</div>
{movies.map((movie) => {
if (movie.is_available) {
if (!movie.is_available) {
return (
<img
key={movie.id}
Expand Down

0 comments on commit 7a213b8

Please sign in to comment.