initial commit
This commit is contained in:
commit
0c42bef077
109 changed files with 16545 additions and 0 deletions
41
app/Services/OmdbService.php
Normal file
41
app/Services/OmdbService.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Models\Movie;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class OmdbService implements MovieDbInterface
|
||||
{
|
||||
private string $url;
|
||||
private User $user;
|
||||
|
||||
public function __construct(private Movie $movie)
|
||||
{
|
||||
$this->url = config('services.omdb.api_url') . config('services.omdb.api_key');
|
||||
$this->user = auth()->user();
|
||||
}
|
||||
|
||||
public function search(string $query, array $options = [])
|
||||
{
|
||||
$movie = Http::get($this->url . "&t=" . $query)->json();
|
||||
if ($movie['Response'] !== 'True') {
|
||||
throw new NotFoundHttpException("Movie not found");
|
||||
}
|
||||
|
||||
logger()->debug("Movie from OMDB: " . json_encode($movie));
|
||||
try {
|
||||
$existing_movie = $this->movie->where('imdb_id', $movie['imdbID'])->firstOrFail();
|
||||
return $existing_movie;
|
||||
} catch (Exception $e) {
|
||||
return Movie::fromOmdb(array_merge(
|
||||
$movie,
|
||||
["added_by" => $this->user->id])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue