-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopAnime.php
52 lines (44 loc) · 1.5 KB
/
TopAnime.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace App\Modules\Jikan\Jobs;
use App\Models\Anime;
use App\Modules\Jikan\JikanFacade;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Middleware\RateLimited;
class TopAnime implements ShouldQueue
{
use Queueable;
public function __construct(readonly private int $page = 1) {}
public function handle(): void
{
$response = JikanFacade::top()->animes([
'page' => $this->page,
]);
foreach ($response['data'] as $anime) {
Anime::updateOrCreate([
'mal_id' => $anime['mal_id'],
], [
'url' => $anime['url'],
'title' => $anime['title'],
'type' => $anime['type'],
'source' => $anime['source'],
'status' => $anime['status'],
'episodes' => $anime['episodes'],
'duration' => $anime['duration'],
'rating' => $anime['rating'],
'score' => $anime['score'],
'popularity' => $anime['popularity'],
'synopsis' => $anime['synopsis'],
'aired_from' => $anime['aired']['from'],
'aired_to' => $anime['aired']['to'],
]);
}
if ($response['pagination']['has_next_page']) {
$this->dispatch($response['pagination']['current_page'] + 1);
}
}
public function middleware(): array
{
return [new RateLimited('jikan')];
}
}