Skip to content

Commit

Permalink
fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ange230700 committed Dec 13, 2023
2 parents 6623fb1 + ea06622 commit f61f432
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 29 deletions.
84 changes: 82 additions & 2 deletions 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 @@ -159,4 +159,84 @@ CREATE TABLE
CONSTRAINT FK_Categorie_Par_Film_film_id FOREIGN KEY (`filmId`) REFERENCES `Film`(`id`),
CONSTRAINT FK_Categorie_Par_Film_categorie_id FOREIGN KEY (`categorieId`) REFERENCES `Categorie`(`id`),
PRIMARY KEY (`filmId`, `categorieId`)
);
);

INSERT INTO
`Film` (`miniature`, `title`, `duration`, `year`, `description`, `isAvailable`)
VALUES
(
'https://m.media-amazon.com/images/M/MV5BMTc5MDE2ODcwNV5BMl5BanBnXkFtZTgwMzI2NzQ2NzM@._V1_.jpg',
'Avengers: Endgame',
181,
'2019',
'After the devastating events of Avengers: Infinity War (2018), the universe is in ruins. With the help of remaining allies, the Avengers assemble once more in order to reverse Thanos actions and restore balance to the universe.',
1
),
(
'https://m.media-amazon.com/images/M/MV5BMjMxNjY2MDU1OV5BMl5BanBnXkFtZTgwNzY1MTUwNTM@._V1_.jpg',
'Avengers: Infinity War',
149,
'2018',
'The Avengers and their allies must be willing to sacrifice all in an attempt to defeat the powerful Thanos before his blitz of devastation and ruin puts an end to the universe.',
0
),
(
'https://m.media-amazon.com/images/M/MV5BNDYxNjQyMjAtNTdiOS00NGYwLWFmNTAtNThmYjU5ZGI2YTI1XkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_.jpg',
'The Avengers',
143,
'2012',
'Earth mightiest heroes must come together and learn to fight as a team if they are going to stop the mischievous Loki and his alien army from enslaving humanity.',
1
),
(
'https://static.wikia.nocookie.net/ironman/images/d/da/P170620_v_v8_ba.jpg/revision/latest?cb=20191202183622',
'Iron man',
126,
'2008',
'After being held captive in an Afghan cave, billionaire engineer Tony Stark creates a unique weaponized suit of armor to fight evil.',
0
);

INSERT INTO
`Categorie` (`name`, `position`)
VALUES
('Action', 1),
('Adventure', 2),
('Sci-Fi', 3),
('Drama', 4),
('Thriller', 5),
('Comedy', 6),
('Crime', 7),
('Fantasy', 8),
('Mystery', 9),
('Animation', 10),
('Family', 11),
('Biography', 12),
('History', 13),
('Horror', 14),
('Music', 15),
('Musical', 16),
('Romance', 17),
('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'
);
6 changes: 3 additions & 3 deletions backend/src/controllers/serieControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const read = async (req, res, next) => {
};

const edit = async (req, res, next) => {
const { id } = req.params.id;
const { id } = req.params;
req.body.id = id;
try {
const result = await tables.serie.update(req.body);
if (result.affectedRows) {
if (result) {
res.json(result);
res.sendStatus(204);
} else {
Expand All @@ -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.serie.delete(id);
if (result.affectedRows) {
Expand Down
97 changes: 97 additions & 0 deletions backend/src/controllers/userControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Import access to database tables
const tables = require("../tables");

// The B of BREAD - Browse (Read All) operation
const browse = async (req, res, next) => {
try {
// Fetch all items from the database
const users = await tables.user.readAll();

// Respond with the items in JSON format
res.json(users);
} catch (err) {
// Pass any errors to the error-handling middleware
next(err);
}
};

// The R of BREAD - Read operation
const read = async (req, res, next) => {
try {
// Fetch a specific item from the database based on the provided ID
const user = await tables.user.read(req.params.id);

// If the item is not found, respond with HTTP 404 (Not Found)
// Otherwise, respond with the item in JSON format
if (user == null) {
res.sendStatus(404);
} else {
res.json(user);
}
} catch (err) {
// Pass any errors to the error-handling middleware
next(err);
}
};

// The E of BREAD - Edit (Update) operation
// This operation is not yet implemented

// eslint-disable-next-line consistent-return
const edit = async (req, res, next) => {
const { id } = req.params;
req.body.id = id;
try {
const result = await tables.user.update(req.body);
if (result) {
res.json(result);
res.status(204);
} else {
return res.sendStatus(404);
}
} catch (err) {
next(err);
}
};

// The A of BREAD - Add (Create) operation
const add = async (req, res, next) => {
// Extract the item data from the request body
const user = req.body;

try {
// Insert the item into the database
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 });
} catch (err) {
// Pass any errors to the error-handling middleware
next(err);
}
};

// The D of BREAD - Destroy (Delete) operation
// This operation is not yet implemented
const destroy = async (req, res, next) => {
const { id } = req.params;
try {
const result = await tables.user.delete(id);
if (result.affectedRows) {
res.sendStatus(200);
} else {
res.sendStatus(404);
}
} catch (err) {
next(err);
}
};

// Ready to export the controller functions
module.exports = {
browse,
read,
edit,
add,
destroy,
};
48 changes: 26 additions & 22 deletions backend/src/models/SerieManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const AbstractManager = require("./AbstractManager");

class SerieManager extends AbstractManager {
constructor() {
super({ table: "Serie" });
super({ table: "serie" });
}

async create({
Expand All @@ -19,17 +19,17 @@ class SerieManager extends AbstractManager {
seasonsNumber,
}) {
const [result] = await this.database.query(
`INSERT INTO ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable, episodesNumber, seasonsNumber) values (?, ?, ?, ?, ?, ?, ?, ?)`,
`INSERT INTO ${this.table} (miniature, title, videoUrl, duration, year, description, isAvailable, episodesNumber, seasonsNumber) values (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[
miniature,
title,
videoUrl,
duration,
year,
description,
IsVailable,
EpisodesNumber,
SeasonsNumber,
isAvailable,
episodesNumber,
seasonsNumber,
]
);
return result;
Expand All @@ -42,6 +42,7 @@ class SerieManager extends AbstractManager {
);
return result;
}

async readAll() {
const [result] = await this.database.query(`select * from ${this.table} `);
return result;
Expand All @@ -60,26 +61,29 @@ class SerieManager extends AbstractManager {
seasonsNumber,
}) {
const [result] = await this.database.query(
`UPDATE ${this.table} SET miniature = ?, title = ?, videoUrl = ?, duration = ?, year = ?, description = ?, IsVailable = ?, EpisodesNumber = ?, SeasonsNumber = ?, WHERE id = ?`

`UPDATE ${this.table} SET miniature=?, title=?, videoUrl=?, duration=?, year=?, description=?, isAvailable=?, episodesNumber=?, seasonsNumber=? WHERE id=?`,
[
miniature,
title,
videoUrl,
duration,
year,
description,
isAvailable,
episodesNumber,
seasonsNumber,
id,
]
);
[
id,
miniature,
title,
videoUrl,
duration,
year,
description,
IsVailable,
EpisodesNumber,
SeasonsNumber,
];
return result;
return result.affectedRows;

}
async delete(id) {
const [result] = await this.database.query(
`delete from ${this.table} where id = ?,`
)[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
6 changes: 6 additions & 0 deletions backend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,39 @@ const router = express.Router();
// Import itemControllers module for handling item-related operations
const categorieControllers = require("./controllers/categorieControllers");
const filmControllers = require("./controllers/filmControllers");
const userControllers = require("./controllers/userControllers");
const serieControllers = require("./controllers/serieControllers");
const categorieParFilmControllers = require("./controllers/categorieParFilmControllers");

// 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);

// 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);

// Route to edit a specific item by ID
router.put("/categories/:id", categorieControllers.edit);
router.put("/films/:id", filmControllers.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);

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

// Route to get all categories for a specific film
router.get(
Expand Down
Loading

0 comments on commit f61f432

Please sign in to comment.