Browse Source

Merge pull request #7 from Astri4-4/profile-page

FINISH profile page
features/create-channel
Sacha GUERIN 5 months ago
committed by GitHub
parent
commit
53da558020
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      backend/app/controllers/user.controller.js
  2. 70
      backend/logs/access.log
  3. 10
      frontend/src/pages/Account.jsx

9
backend/app/controllers/user.controller.js

@ -189,19 +189,22 @@ export async function update(req, res) {
console.log(__dirname); console.log(__dirname);
let profilePicture = userInBase.picture.split("/").pop(); let profilePicture = userInBase.picture.split("/").pop();
fs.rename(__dirname + "../uploads/profiles/" + profilePicture, __dirname + "../uploads/profiles/" + user.username + "." + profilePicture.split(".").pop(), (err) => { fs.rename(
path.join(__dirname, "..", "uploads", "profiles", profilePicture),
path.join(__dirname, "..", "uploads", "profiles", user.username + "." + profilePicture.split(".").pop()),
(err) => {
if (err) { if (err) {
logger.write("failed to update profile picture", 500); logger.write("failed to update profile picture", 500);
console.error("Error renaming file:", err); console.error("Error renaming file:", err);
throw err; throw err;
} }
}); });
profilePicture = user.username + "." + profilePicture.split(".").pop(); profilePicture = "/api/media/profile/" + user.username + "." + profilePicture.split(".").pop();
const updateQuery = `UPDATE users SET email = $1, username = $2, password = $3, picture = $4 WHERE id = $5 RETURNING id, email, username, picture`; const updateQuery = `UPDATE users SET email = $1, username = $2, password = $3, picture = $4 WHERE id = $5 RETURNING id, email, username, picture`;
const result = await client.query(updateQuery, [user.email, user.username, user.password, profilePicture, id]); const result = await client.query(updateQuery, [user.email, user.username, user.password, profilePicture, id]);
logger.write("successfully updated user " + id, 200); logger.write("successfully updated user " + id, 200);
res.status(200).send({user: result.rows[0]}); res.status(200).json(result.rows[0]);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
res.status(500).json({error: err}); res.status(500).json({error: err});

70
backend/logs/access.log

@ -1393,3 +1393,73 @@
[2025-07-21 15:23:44.537] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 [2025-07-21 15:23:44.537] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200
[2025-07-21 15:23:49.626] [undefined] PUT(/:id): try to update user 6 [2025-07-21 15:23:49.626] [undefined] PUT(/:id): try to update user 6
[2025-07-21 15:23:49.633] [undefined] PUT(/:id): failed to update profile picture with status 500 [2025-07-21 15:23:49.633] [undefined] PUT(/:id): failed to update profile picture with status 500
[2025-07-21 18:55:14.850] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 18:55:14.865] [undefined] POST(/login): failed to login with status 401
[2025-07-21 18:55:26.093] [undefined] POST(/login): try to login with username 'sacha'
[2025-07-21 18:55:26.145] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 18:56:09.969] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 18:56:09.970] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 18:56:09.971] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 18:56:09.973] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 18:56:09.983] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 18:56:30.328] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 18:56:30.331] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 18:56:30.332] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 18:56:30.335] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 18:56:30.340] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 18:56:37.069] [undefined] POST(/login): try to login with username 'sacha'
[2025-07-21 18:56:37.118] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 18:56:51.114] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 18:56:51.115] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 18:56:51.116] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 18:56:51.118] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 18:56:51.126] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 18:57:46.290] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 18:57:46.293] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 18:57:46.295] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 18:57:46.299] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 18:57:46.303] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 18:57:52.156] [undefined] PUT(/:id): try to update user 1
[2025-07-21 18:57:52.158] [undefined] PUT(/:id): successfully updated user 1 with status 200
[2025-07-21 18:58:05.603] [undefined] GET(/:id/channel): failed due to invalid values with status 400
[2025-07-21 18:58:05.608] [undefined] GET(/:id/history): failed due to invalid values with status 400
[2025-07-21 18:58:05.610] [undefined] GET(/user/:id): failed due to invalid values with status 400
[2025-07-21 18:58:52.332] [undefined] GET(/:id/channel): failed due to invalid values with status 400
[2025-07-21 18:58:52.339] [undefined] GET(/:id/history): failed due to invalid values with status 400
[2025-07-21 18:58:52.341] [undefined] GET(/user/:id): failed due to invalid values with status 400
[2025-07-21 18:58:57.222] [undefined] GET(/:id/channel): failed due to invalid values with status 400
[2025-07-21 18:58:57.225] [undefined] GET(/:id/history): failed due to invalid values with status 400
[2025-07-21 18:58:57.228] [undefined] GET(/user/:id): failed due to invalid values with status 400
[2025-07-21 19:00:00.868] [undefined] GET(/:id/channel): failed due to invalid values with status 400
[2025-07-21 19:00:00.875] [undefined] GET(/:id/history): failed due to invalid values with status 400
[2025-07-21 19:00:00.878] [undefined] GET(/user/:id): failed due to invalid values with status 400
[2025-07-21 19:00:07.728] [undefined] PUT(/:id): failed due to invalid values with status 400
[2025-07-21 19:00:22.072] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 19:00:22.123] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 19:00:31.149] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 19:00:31.150] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 19:00:31.151] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 19:00:31.154] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 19:00:31.161] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 19:00:37.082] [undefined] PUT(/:id): try to update user 1
[2025-07-21 19:00:37.085] [undefined] PUT(/:id): successfully updated user 1 with status 200
[2025-07-21 19:00:41.130] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 19:00:41.131] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 19:00:41.132] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 19:00:41.134] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 19:00:41.142] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 19:01:27.664] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 19:01:27.665] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 19:01:27.672] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 19:01:27.674] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 19:01:27.682] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 19:03:09.269] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 19:03:09.269] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 19:03:09.271] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 19:03:09.274] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 19:03:09.282] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 19:03:11.312] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 19:03:11.314] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200
[2025-07-21 19:03:11.316] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 19:03:11.318] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200
[2025-07-21 19:03:11.323] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200

10
frontend/src/pages/Account.jsx

@ -2,6 +2,7 @@ import Navbar from "../components/Navbar.jsx";
import {useEffect, useState} from "react"; import {useEffect, useState} from "react";
import PlaylistCard from "../components/PlaylistCard.jsx"; import PlaylistCard from "../components/PlaylistCard.jsx";
import VideoCard from "../components/VideoCard.jsx"; import VideoCard from "../components/VideoCard.jsx";
import {useNavigate} from "react-router-dom";
export default function Account() { export default function Account() {
@ -16,9 +17,10 @@ export default function Account() {
const [isPictureEditActive, setIsPictureEditActive] = useState(false); const [isPictureEditActive, setIsPictureEditActive] = useState(false);
const [userHistory, setUserHistory] = useState([]); const [userHistory, setUserHistory] = useState([]);
const [userPlaylists, setUserPlaylists] = useState([]); const [userPlaylists, setUserPlaylists] = useState([]);
const [userChannel, setUserChannel] = useState(null); const [userChannel, setUserChannel] = useState(null);
const navigation = useNavigate();
const fetchUserChannel = async () => { const fetchUserChannel = async () => {
try { try {
const response = await fetch(`/api/users/${user.id}/channel`, { const response = await fetch(`/api/users/${user.id}/channel`, {
@ -93,7 +95,7 @@ export default function Account() {
const editModeClasses = nonEditModeClasses + " glassmorphism"; const editModeClasses = nonEditModeClasses + " glassmorphism";
const handlePlaylistClick = (playlistId) => { const handlePlaylistClick = (playlistId) => {
navigation(`/playlist/${playlistId}`);
} }
const handleUpdateUser = async () => { const handleUpdateUser = async () => {
@ -253,9 +255,9 @@ export default function Account() {
<div className="glassmorphism p-10 w-full flex justify-between"> <div className="glassmorphism p-10 w-full flex justify-between">
<p className="text-3xl text-white mb-2 font-montserrat font-bold">{userChannel.channel.name}</p> <p className="text-3xl text-white mb-2 font-montserrat font-bold">{userChannel.channel.name}</p>
<button> <button>
<a href="" className="bg-primary p-3 rounded-sm text-white font-montserrat text-2xl font-semibold cursor-pointer"> <span onClick={() => navigation("/manage-channel")} className="bg-primary p-3 rounded-sm text-white font-montserrat text-2xl font-semibold cursor-pointer">
Gérer la chaîne Gérer la chaîne
</a> </span>
</button> </button>
</div> </div>
) : ( ) : (

Loading…
Cancel
Save