fix purposes
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user