Skip to content

Commit

Permalink
last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ange230700 committed Feb 7, 2024
1 parent a5a5d24 commit 387e563
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 102 deletions.
6 changes: 0 additions & 6 deletions backend/src/controllers/filmControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ const edit = async (req, res, next) => {
const { id } = req.params;
req.body.id = id;

console.warn("req.body.cover in edit", req.body.cover);

if (req.files.cover && req.files.cover[0]) {
req.body.cover_filename = req.files.cover[0].filename;
}

console.warn("req.body.miniature in edit", req.body.miniature);

if (req.files.miniature && req.files.miniature[0]) {
req.body.miniature_filename = req.files.miniature[0].filename;
}
Expand All @@ -58,8 +54,6 @@ const edit = async (req, res, next) => {
};

const add = async (req, res, next) => {
console.warn("req.body.images in add", req.body.images);

if (req.files.cover && req.files.cover[0]) {
req.body.cover_filename = req.files.cover[0].filename;
}
Expand Down
2 changes: 0 additions & 2 deletions backend/src/models/CategorieParFilmManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class CategorieParFilmManager extends AbstractManager {

arrDep.push(filmId, catId, unique_key);
});
// console.log("querySQL =>", querySQL);
// console.log("arrDep =>", arrDep);

// Execute the SQL INSERT query to add a new categorieParFilm to the "categorieParFilm" table
const result = await this.database.query(`${querySQL};`, arrDep);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/FilmManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FilmManager extends AbstractManager {
IsAvailable,
}) {
const [result] = await this.database.query(
`update ${this.table} SET miniature_filename=?, cover_filename=?, title=?, videoUrl=?, videoFilename=?, duration=?, year=?, description=?, IsAvailable=? where id=?`,
`update ${this.table} SET miniature_filename = COALESCE(?, miniature_filename), cover_filename = COALESCE(?, cover_filename), title = COALESCE(?, title), videoUrl = COALESCE(?, videoUrl), videoFilename = COALESCE(?, videoFilename), duration = COALESCE(?, duration), year = COALESCE(?, year), description = COALESCE(?, description), IsAvailable = COALESCE(?, IsAvailable) where id=?`,
[
miniature_filename,
cover_filename,
Expand Down
5 changes: 0 additions & 5 deletions backend/src/services/multer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const imagesStorage = multer.diskStorage({
if (req.body.miniature) {
req.body.miniature = name;
}

console.warn("req.body.images in imagesStorage", req.body.images);
cb(null, name);
},
});
Expand All @@ -44,9 +42,6 @@ const imagesStorage2 = multer.diskStorage({
if (req.body.miniature) {
req.body.miniature = name;
}

console.warn("req.body.cover in imagesStorage", req.body.cover);
console.warn("req.body.miniature in imagesStorage", req.body.miniature);
cb(null, name);
},
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/CategoryDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function CategoryDisplay({ categorie, getCategories }) {
toast.success("Category deleted");
getCategories();
} else {
toast.error("An error occurred");
toast.error("Error deleting category");
}
} catch (error) {
console.error(error);
toast.error("An error occurred");
toast.error("Error deleting category");
} finally {
setIsDeleting(false);
}
Expand Down
66 changes: 38 additions & 28 deletions frontend/src/pages/AddVideos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function AddVideos() {
const [file, setFile] = useState(undefined);
const [previewFile, setPreviewFile] = useState();
const [previewCover, setPreviewCover] = useState();
const [previewVideo, setPreviewVideo] = useState();
const [cover, setCover] = useState(undefined);
const [description, setDescription] = useState("");
const [title, setTitle] = useState("");
Expand Down Expand Up @@ -69,7 +68,7 @@ function AddVideos() {
duration ||
isAvailable) === (undefined || "" || false)
) {
toast.error("champ manquant");
toast.error("Missing fields");
} else if (isAvailable === "utilisateur") {
setIsAvailable(true);
} else if (isAvailable === "visiteur") {
Expand Down Expand Up @@ -133,10 +132,6 @@ function AddVideos() {
const objectUrlCover = URL.createObjectURL(cover);
setPreviewCover(objectUrlCover);
}
if (videoFilename) {
const objectUrlVideo = URL.createObjectURL(videoFilename);
setPreviewVideo(objectUrlVideo);
}
}, [file, cover]);

return (
Expand All @@ -156,14 +151,43 @@ function AddVideos() {
</div>
<div className="Emptyfieldscontainer">
<div className="Imageuploadercontainer">
<div className="inputContainer">
<input
type="text"
name="name"
className="input"
onChange={(e) => setVideoUrl(e.target.value)}
placeholder="lien de la video"
/>
<div
style={{
display: "flex",
gap: "20px",
alignItems: "center",
}}
className="someContainer"
>
<div className="inputContainer">
<input
type="text"
name="name"
className="input"
onChange={(e) => setVideoUrl(e.target.value)}
placeholder="video url"
/>
</div>
<p
style={{
fontSize: "1.5rem",
fontWeight: "bold",
color: "white",
}}
>
Or
</p>
<div className="Outlineimageuploader">
<div className="Frame4">
<h4 className="AjouterUneMiniature">Add a video file</h4>
</div>
<input
className="input"
onChange={(e) => setVideoFilename(e.target.files[0])}
type="file"
accept="video/*"
/>
</div>
</div>
<div className="Outlineimageuploader">
<div className="Frame4">
Expand Down Expand Up @@ -193,20 +217,6 @@ function AddVideos() {
accept="image/*"
/>
</div>
<div className="Outlineimageuploader">
<div className="Frame4">
<h4 className="AjouterUneMiniature">Add a video file</h4>
<div className="imageContainer2">
{previewVideo && <img src={previewVideo} alt="videoFile" />}
</div>
</div>
<input
className="input"
onChange={(e) => setVideoFilename(e.target.files[0])}
type="file"
accept="video/*"
/>
</div>
</div>
<div className="inputContainer">
<input
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/EditSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function EditSection() {
})
.catch((error) => {
console.error(error);
toast.error("An error occurred");
toast.error("Error updating category name");
});
}

Expand Down Expand Up @@ -127,7 +127,7 @@ function EditSection() {
}
} catch (error) {
console.error(error);
toast.error("An error occurred");
toast.error("Error saving changes");
} finally {
setIsSaving(false);
}
Expand Down
88 changes: 44 additions & 44 deletions frontend/src/pages/EditVideo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import toast from "react-hot-toast";
import axios from "axios";
import { useMovies } from "../contexts/MovieContext";

// § The user should be able to decide if he wanna upload a video or use a youtube link to edit a video.
// § When uploading a video, I would like to see a preview of the video being a snapshot of the video. How can I do that?

function EditVideo() {
const { movieId } = useParams();
Expand Down Expand Up @@ -36,15 +36,15 @@ function EditVideo() {
`${import.meta.env.VITE_BACKEND_URL}/api/categoriesParFilm/${uniqueKey}`
);
if (response.status === 200) {
toast.success("Success");
toast.success("Success deleting category");
setCategorieVideo((prevCategorieVideo) =>
prevCategorieVideo.filter(
(categorie) => categorie.unique_key !== uniqueKey
)
);
}
} catch (e) {
console.error("Error deleting", e);
console.error("Error deleting category", e);
}
};

Expand Down Expand Up @@ -147,7 +147,7 @@ function EditVideo() {
}
);
if (response.status === 201) {
toast.success("Success");
toast.success("Success adding category");
fetchCategorieVideo();
}
} catch (e) {
Expand Down Expand Up @@ -178,7 +178,7 @@ function EditVideo() {
}
);
if (response.status === 204) {
toast.success("Success");
toast.success("Success editing video");
if (selectedFile) URL.revokeObjectURL(selectedFile);
if (selectedFile2) URL.revokeObjectURL(selectedFile2);
if (selectedFile3) URL.revokeObjectURL(selectedFile3);
Expand All @@ -195,7 +195,7 @@ function EditVideo() {
`${import.meta.env.VITE_BACKEND_URL}/api/films/${movieId}`
);
if (response.status === 200) {
toast.success("Success");
toast.success("Success deleting video");
navigate("/");
}
} catch (e) {
Expand Down Expand Up @@ -233,21 +233,6 @@ function EditVideo() {
return video?.miniature_url;
};

const imageSrc3 = () => {
if (selectedFile3) {
return URL.createObjectURL(selectedFile3);
}
if (video.videoFilename) {
return (
video.videoFilename &&
`${import.meta.env.VITE_BACKEND_URL}/assets/images/${
video?.videoFilename
}`
);
}
return video?.videoUrl;
};

useEffect(() => {
return () => {
if (selectedFile) {
Expand Down Expand Up @@ -298,57 +283,72 @@ function EditVideo() {
accept="image/*"
/>
</div>
<div className="containerFormMiniature">
<img className="miniature" src={imageSrc3()} alt="videoFilename" />
<input
type="file"
className="min"
onChange={handleFileChange3 || ""}
accept="video/*"
/>
</div>
<div className="containerFormEdit">
<input
className="edit"
name="title"
type="text"
value={video?.title}
onChange={handleInputChange || ""}
placeholder="Title"
/>
<input
className="edit"
type="text"
name="cover"
value={video?.cover}
onChange={handleInputChange || ""}
/>
<input
className="edit"
type="text"
name="videoUrl"
value={video?.videoUrl}
onChange={handleInputChange || ""}
/>
<div
style={{
display: "flex",
alignItems: "center",
width: "100%",
justifyContent: "center",
gap: "3rem",
}}
className="someContainer"
>
<input
className="edit"
type="text"
name="videoUrl"
value={video?.videoUrl}
onChange={handleInputChange || ""}
placeholder="Youtube URL"
/>
<p
style={{
fontSize: "1.5rem",
fontWeight: "bold",
color: "white",
}}
>
Or
</p>
<input
type="file"
className="min"
onChange={handleFileChange3 || ""}
accept="video/*"
/>
</div>
<input
className="edit"
type="text"
name="duration"
value={video?.duration}
onChange={handleInputChange || ""}
placeholder="Duration"
/>
<input
className="edit"
type="text"
name="year"
value={video?.year}
onChange={handleInputChange || ""}
placeholder="Year"
/>
<textarea
className="edit"
type="text"
name="description"
value={video?.description}
onChange={handleInputChange || ""}
placeholder="Description"
/>
<div className="categories">
{categorieVideo.map((categorie) => (
Expand Down
Loading

0 comments on commit 387e563

Please sign in to comment.