diff --git a/backend/logs/access.log b/backend/logs/access.log index efaee8d..a1f3f79 100644 --- a/backend/logs/access.log +++ b/backend/logs/access.log @@ -5536,3 +5536,121 @@ [2025-08-14 20:16:05.601] [undefined] GET(/:id/stats): Successfully get stats with status 200 [2025-08-14 20:16:09.229] [undefined] PUT(/:id): try to update channel with id 4 [2025-08-14 20:16:09.234] [undefined] PUT(/:id): Successfully updated channel with status 200 +[2025-08-14 20:19:48.593] [undefined] POST(/login): try to login with username 'sacha2' +[2025-08-14 20:19:48.645] [undefined] POST(/login): Successfully logged in with status 200 +[2025-08-14 20:19:50.397] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:19:50.401] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:19:50.404] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:19:50.409] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:19:50.416] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:19:52.573] [undefined] GET(/:id): try to get channel with id 1 +[2025-08-14 20:19:52.582] [undefined] GET(/:id/stats): try to get stats +[2025-08-14 20:19:52.586] [undefined] GET(/:id): Successfully get channel with id 1 with status 200 +[2025-08-14 20:19:52.596] [undefined] GET(/:id/stats): Successfully get stats with status 200 +[2025-08-14 20:19:57.515] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:19:57.518] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:19:59.762] [undefined] GET(/:id): try to get channel with id 1 +[2025-08-14 20:19:59.773] [undefined] GET(/:id/stats): try to get stats +[2025-08-14 20:19:59.777] [undefined] GET(/:id): Successfully get channel with id 1 with status 200 +[2025-08-14 20:19:59.785] [undefined] GET(/:id/stats): Successfully get stats with status 200 +[2025-08-14 20:20:00.371] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:20:00.375] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:20:00.377] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:20:00.382] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:20:00.389] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:23:01.532] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:23:01.536] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:23:01.538] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:23:01.544] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:23:01.551] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:31:39.192] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:31:39.195] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:31:39.198] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:31:39.204] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:31:39.211] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:31:53.915] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:31:53.918] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:31:53.942] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:31:53.947] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:31:53.956] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:31:56.423] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:31:56.426] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:31:56.428] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:31:56.434] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:31:56.442] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:32:02.387] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:32:02.390] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:32:02.393] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:32:02.399] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:32:02.406] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:32:11.988] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:32:11.992] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:32:11.994] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:32:11.999] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:32:12.007] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:32:12.840] [undefined] GET(/:id): try to get channel with id 1 +[2025-08-14 20:32:12.850] [undefined] GET(/:id/stats): try to get stats +[2025-08-14 20:32:12.854] [undefined] GET(/:id): Successfully get channel with id 1 with status 200 +[2025-08-14 20:32:12.862] [undefined] GET(/:id/stats): Successfully get stats with status 200 +[2025-08-14 20:32:13.944] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-08-14 20:32:13.947] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-08-14 20:32:13.950] [undefined] GET(/:id/channel): successfully retrieved channel of user 2 with status 200 +[2025-08-14 20:32:13.953] [undefined] GET(/:id/history): successfully retrieved history of user 2 with status 200 +[2025-08-14 20:32:13.961] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-08-14 20:32:50.173] [undefined] POST(/): try to register a user with username: test4 and email: test4@gmail.com +[2025-08-14 20:32:50.223] [undefined] POST(/): successfully registered with status 200 +[2025-08-14 20:32:50.230] [undefined] POST(/login): try to login with username 'test4' +[2025-08-14 20:32:50.281] [undefined] POST(/login): Successfully logged in with status 200 +[2025-08-14 20:32:51.673] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:32:51.677] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:32:51.679] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:32:51.682] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:32:51.691] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:33:07.906] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:33:07.909] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:33:07.911] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:33:07.914] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:33:07.924] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:33:16.345] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:33:16.348] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:33:16.351] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:33:16.354] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:33:16.363] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:34:21.620] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:34:21.624] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:21.627] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:34:21.631] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:21.639] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:34:36.364] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:34:36.367] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:34:36.369] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:36.372] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:36.381] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:34:55.418] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:34:55.422] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:55.425] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:34:55.428] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:34:55.436] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:35:04.997] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:35:05.000] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:35:05.004] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:35:05.008] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:35:05.015] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:36:01.767] [undefined] PUT(/:id): try to update user 6 +[2025-08-14 20:36:01.772] [undefined] PUT(/:id): successfully updated user 6 with status 200 +[2025-08-14 20:36:03.230] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:36:03.233] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:36:03.236] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:36:03.239] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:36:03.248] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:41:31.791] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:41:31.794] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:41:31.797] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:41:31.800] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:41:31.808] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:41:50.529] [undefined] GET(/:id/channel): try to retrieve channel of user 6 +[2025-08-14 20:41:50.532] [undefined] GET(/:id/history): try to retrieve history of user 6 +[2025-08-14 20:41:50.535] [undefined] GET(/:id/channel): failed to retrieve channel of user 6 because it doesn't exist with status 404 +[2025-08-14 20:41:50.539] [undefined] GET(/:id/history): failed to retrieve history of user 6 because it doesn't exist with status 404 +[2025-08-14 20:41:50.550] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 +[2025-08-14 20:41:53.692] [undefined] POST(/): Playlist created with id 7 with status 200 diff --git a/frontend/src/modals/CreatePlaylistModal.jsx b/frontend/src/modals/CreatePlaylistModal.jsx new file mode 100644 index 0000000..4215e71 --- /dev/null +++ b/frontend/src/modals/CreatePlaylistModal.jsx @@ -0,0 +1,46 @@ +import { useState } from "react"; +import { createPlaylist } from "../services/playlist.service.js"; + +export default function CreatePlaylistModal({ isOpen, onClose, addAlert }) { + + const [name, setName] = useState(''); + + const onSubmit = async (e) => { + e.preventDefault(); + const token = localStorage.getItem("token"); + const body = { name }; + await createPlaylist(body, token, addAlert); + onClose(); + }; + + return isOpen && ( + +
+
+

Créer une playlist

+ + setName(e.target.value)} + value={name} + /> + + +
+
+ ) +} \ No newline at end of file diff --git a/frontend/src/pages/Account.jsx b/frontend/src/pages/Account.jsx index d8e5e9a..9586aa5 100644 --- a/frontend/src/pages/Account.jsx +++ b/frontend/src/pages/Account.jsx @@ -1,9 +1,10 @@ import Navbar from "../components/Navbar.jsx"; -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; import PlaylistCard from "../components/PlaylistCard.jsx"; import VideoCard from "../components/VideoCard.jsx"; -import {useNavigate} from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import CreateChannelModal from "../modals/CreateChannelModal.jsx"; +import CreatePlaylistModal from "../modals/CreatePlaylistModal.jsx"; import { getChannel, getUserHistory, getPlaylists, updateUser } from "../services/user.service.js"; @@ -21,6 +22,7 @@ export default function Account() { const [userPlaylists, setUserPlaylists] = useState([]); const [userChannel, setUserChannel] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); + const [isCreatePlaylistModalOpen, setIsCreatePlaylistModalOpen] = useState(false); const [alerts, setAlerts] = useState([]); const navigation = useNavigate(); @@ -92,160 +94,166 @@ export default function Account() {
{/* Left side */} - {/* Profile / Edit profile */} -
-
setIsPictureEditActive(true)} onMouseLeave={() => setIsPictureEditActive(false)} > - - -
- - setUsername(e.target.value)} - placeholder="Nom d'utilisateur" - disabled={!editMode} - /> - -
closeModal()} addAlert={addAlert} /> + setIsCreatePlaylistModalOpen(false)} addAlert={addAlert} /> ) diff --git a/frontend/src/services/playlist.service.js b/frontend/src/services/playlist.service.js new file mode 100644 index 0000000..e520f92 --- /dev/null +++ b/frontend/src/services/playlist.service.js @@ -0,0 +1,23 @@ + +export async function createPlaylist(body, token, addAlert) { + try { + const response = await fetch(`https://localhost/api/playlists`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify(body) + }); + + if (!response.ok) { + throw new Error('Failed to create playlist'); + } + + const data = await response.json(); + addAlert('success', 'Playlist created successfully'); + return data; + } catch (error) { + addAlert('error', error.message); + } +} \ No newline at end of file