Add movies lists

This commit is contained in:
2026-07-11 10:55:59 +02:00
parent 45e5f8d6c6
commit d8aa88a8fb
2 changed files with 115 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
// controllers/MovieController.php
require_once __DIR__ . '/../models/Movie.php';
class MovieController {
private $db;
private $movieModel;
public function __construct($db) {
$this->db = $db;
$this->movieModel = new Movie($this->db);
}
// INTERCEPTE L'AJOUT
public function addMovie($data) {
if (empty($data['user_id']) || empty($data['tmdb_id']) || empty($data['title'])) {
http_response_code(400);
echo json_encode(["success" => false, "message" => "Données incomplètes (user_id, tmdb_id, title requis)."]);
return;
}
$mediaType = $data['media_type'] ?? 'film';
$isCommon = isset($data['is_common']) ? (bool)$data['is_common'] : false;
$posterPath = $data['poster_path'] ?? null;
$result = $this->movieModel->add($data['user_id'], $data['tmdb_id'], $data['title'], $posterPath, $mediaType, $isCommon);
http_response_code($result['success'] ? 201 : 400);
echo json_encode($result);
}
// INTERCEPTE LA RECUPERATION DES LISTES
public function getLists($data) {
if (empty($data['user_id'])) {
http_response_code(400);
echo json_encode(["success" => false, "message" => "ID utilisateur requis."]);
return;
}
// On a besoin du partner_id pour choper sa liste, s'il n'est pas envoyé on le met à null
$partnerId = $data['partner_id'] ?? null;
$result = $this->movieModel->getLists($data['user_id'], $partnerId);
http_response_code(200);
echo json_encode($result);
}
}