diff --git a/app/Jobs/InstaGetTopMediasJob.php b/app/Jobs/InstaGetTopMediasJob.php index efa5dc3..a4cdc88 100644 --- a/app/Jobs/InstaGetTopMediasJob.php +++ b/app/Jobs/InstaGetTopMediasJob.php @@ -10,6 +10,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use App\Enums\ExcludeTypeEnum; +use Exception; class InstaGetTopMediasJob implements ShouldQueue { @@ -107,7 +108,11 @@ class InstaGetTopMediasJob implements ShouldQueue */ public function handle(int $count = 0, array $params = []) { - $json = $this->callApi($params); + try { + $json = $this->callApi($params); + } catch (\Exception $e) { + // TODO : handle exception + }//end try foreach ($json->data as $ig_media) { if ($count < $this->nb_medias) { if ($this->excludePosts->where('value', $ig_media->id)->isNotEmpty()) { @@ -123,7 +128,9 @@ class InstaGetTopMediasJob implements ShouldQueue 'permalink' => $ig_media->permalink, 'timestamp' => $ig_media->timestamp, 'like_count' => isset($ig_media->like_count) ? $ig_media->like_count : null, - 'comments_count' => $ig_media->comments_count + 'comments_count' => $ig_media->comments_count, + 'username' => $username, + 'caption' => $ig_media->caption, ]; $media = new InstaMedia(); @@ -178,10 +185,10 @@ class InstaGetTopMediasJob implements ShouldQueue if ($status === 200) { return \json_decode($res->getBody()); } else { - \dd($res->getBody()); + throw new \Exception($res->getBody()); } } catch (\GuzzleHttp\Exception\ClientException $e) { - echo $e->getMessage(); + throw new \Exception($e); } //end try } @@ -217,10 +224,10 @@ class InstaGetTopMediasJob implements ShouldQueue } } } else { - \dd($res->getBody()); + throw new \Exception($res->getBody()); } } catch (\GuzzleHttp\Exception\ClientException $e) { - echo $e->getMessage(); + throw new \Exception($e); } //end try } } diff --git a/app/Models/InstaMedia.php b/app/Models/InstaMedia.php index 6c0f41a..5f8b534 100644 --- a/app/Models/InstaMedia.php +++ b/app/Models/InstaMedia.php @@ -25,6 +25,8 @@ class InstaMedia extends Model 'permalink', 'timestamp', 'like_count', - 'comments_count' + 'comments_count', + 'username', + 'caption' ]; } diff --git a/config/services.php b/config/services.php index d5fa152..b783d24 100644 --- a/config/services.php +++ b/config/services.php @@ -45,13 +45,14 @@ return [ "like_count", "comments_count", "permalink", - "timestamp" + "timestamp", + "caption" ]) ), 'ig_hashtag_id' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_IGHASHTAGID'), 'user_id' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_USERID'), 'limit' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_LIMIT', 25), - 'nb_medias' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_NBMEDIAS', 25), + 'nb_medias' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_NBMEDIAS', 30), ] ] ] diff --git a/database/migrations/2023_02_10_103952_create_insta_medias_table.php b/database/migrations/2023_02_10_103952_create_insta_medias_table.php index 88cdb6f..2d6dd66 100644 --- a/database/migrations/2023_02_10_103952_create_insta_medias_table.php +++ b/database/migrations/2023_02_10_103952_create_insta_medias_table.php @@ -21,6 +21,8 @@ return new class extends Migration $table->string("timestamp"); $table->bigInteger("comments_count"); $table->bigInteger("like_count")->nullable(); + $table->string('username'); + $table->text('caption'); $table->timestamps(); }); }