From 72d563416b097e5af9239294cdadf3aa6a3d5956 Mon Sep 17 00:00:00 2001 From: Whykioh Date: Sat, 11 Jul 2026 14:08:44 +0200 Subject: [PATCH] Add Remove & Mark watched movie --- index.php | 14 ++++++++++++++ models/Movie.php | 25 +++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 3577d29..dfaafaf 100644 --- a/index.php +++ b/index.php @@ -119,6 +119,20 @@ switch ($route) { } else { http_response_code(405); } break; + case 'remove-movie': + if ($method === 'POST') { + $data['user_id'] = getAuthenticatedUserId($jwt_secret); + $movieController->remove($data); + } else { http_response_code(405); } + break; + + case 'mark-watched': + if ($method === 'POST') { + $data['user_id'] = getAuthenticatedUserId($jwt_secret); + $movieController->markWatched($data); + } else { http_response_code(405); } + break; + default: http_response_code(404); echo json_encode(["error" => "Route /" . $route . " non trouvée"]); diff --git a/models/Movie.php b/models/Movie.php index b25f5ee..6eedf26 100644 --- a/models/Movie.php +++ b/models/Movie.php @@ -33,7 +33,7 @@ class Movie { } return true; -} + } public function share($movieId, $userId) { $stmt = $this->db->prepare("UPDATE movies SET is_common = 1 WHERE id = ? AND user_id = ?"); @@ -56,10 +56,27 @@ class Movie { } // 3. Commune - $stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1 ORDER BY added_at DESC"); - $stmt->execute(); - $common = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt = $this->db->prepare(" + SELECT * + FROM movies + WHERE is_common = 1 + GROUP BY tmdb_id + ORDER BY added_at DESC + "); + $stmt->execute(); + $common = $stmt->fetchAll(PDO::FETCH_ASSOC); return ["perso" => $perso, "partner" => $partner, "common" => $common]; } + + public function remove($movieId, $userId) { + $stmt = $this->db->prepare("DELETE FROM movies WHERE id = ? AND user_id = ?"); + return $stmt->execute([$movieId, $userId]); + } + + public function markWatched($movieId, $userId) { + // Si tu n'as pas de colonne 'watched', ajoute-la en BDD : ALTER TABLE movies ADD COLUMN watched BOOLEAN DEFAULT 0; + $stmt = $this->db->prepare("UPDATE movies SET watched = 1 WHERE id = ? AND user_id = ?"); + return $stmt->execute([$movieId, $userId]); + } } \ No newline at end of file