fix purposes

This commit is contained in:
2026-07-12 16:50:35 +02:00
parent 7207e8afb7
commit 34ef199fb6
7 changed files with 126 additions and 7 deletions
+22 -2
View File
@@ -42,9 +42,29 @@ class MovieController {
// 3. On renvoie le JSON
echo json_encode([
"success" => true,
"partner_id" => $realPartnerId,
"success" => true,
"partner_id" => $realPartnerId,
"lists" => $lists
]);
}
public function remove($data) {
if (!isset($data['movie_id'])) {
http_response_code(400);
echo json_encode(["error" => "ID du film manquant"]);
return;
}
$res = $this->movieModel->remove($data['movie_id'], $data['user_id']);
echo json_encode(["success" => $res]);
}
public function markWatched($data) {
if (!isset($data['movie_id'])) {
http_response_code(400);
echo json_encode(["error" => "ID du film manquant"]);
return;
}
$res = $this->movieModel->markWatched($data['movie_id'], $data['user_id']);
echo json_encode(["success" => $res]);
}
}
+61
View File
@@ -0,0 +1,61 @@
<?php
// controllers/TmdbController.php
// Proxy serveur vers TMDB : la clé API ne quitte jamais le backend.
class TmdbController {
private $apiKey;
private $baseUrl = 'https://api.themoviedb.org/3';
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
private function fetch($endpoint, $params = []) {
$params['api_key'] = $this->apiKey;
$url = $this->baseUrl . $endpoint . '?' . http_build_query($params);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE) ?: 502;
curl_close($ch);
return ['code' => $httpCode, 'body' => $response ?: json_encode(["error" => "TMDB injoignable"])];
}
public function search($data) {
$query = trim($data['query'] ?? '');
if ($query === '') {
http_response_code(400);
echo json_encode(["error" => "Paramètre 'query' manquant"]);
return;
}
$result = $this->fetch('/search/movie', [
'query' => $query,
'language' => 'fr-FR',
'page' => 1
]);
http_response_code($result['code']);
echo $result['body'];
}
public function details($data) {
$id = $data['id'] ?? null;
if (!$id || !ctype_digit((string)$id)) {
http_response_code(400);
echo json_encode(["error" => "ID de film invalide"]);
return;
}
$result = $this->fetch("/movie/{$id}", [
'language' => 'fr-FR',
'append_to_response' => 'credits'
]);
http_response_code($result['code']);
echo $result['body'];
}
}