Skip to content

Commit

Permalink
Update:update code and run command
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-fathi committed Dec 5, 2023
1 parent d25ba34 commit ff10f7a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();

// $schedule->command(NewsCommand::class)->hourly()
// ->runInBackground()->withoutOverlapping();
$schedule->command(NewsCommand::class)->everyMinute()->runInBackground()->withoutOverlapping();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Exceptions;

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

class Handler extends ExceptionHandler
Expand All @@ -27,4 +29,13 @@ public function register(): void
//
});
}

public function render($request, Throwable $exception)
{
if ($exception instanceof ModelNotFoundException) {
return response()->json(['message' => 'Resource not found'], 404);
}

return parent::render($request, $exception);
}
}
2 changes: 0 additions & 2 deletions app/Jobs/GuardianNewsAPICollectorJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ private function saveNews($results): void

} catch (\PDOException $e) {

dump("error");

continue;
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/Jobs/NewsAPICollectorJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ private function saveNews($articles): void

} catch (\PDOException $e) {

dump("error: ", $data['title'], $e);

continue;
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/Logic/Utility/EndPointFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
interface EndPointFetcher
{
/**
* @param $base_ur
* @param string $base_ur
*/
public function __construct($base_ur);

public function __construct(string $base_ur);

/**
* @param string $uri
Expand Down
20 changes: 17 additions & 3 deletions app/Logic/Utility/NewsFetcherUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

use GuzzleHttp\ClientInterface;

/**
*
*/
class NewsFetcherUtility implements EndPointFetcher
{
public ClientInterface $client;
/**
* @var \GuzzleHttp\ClientInterface|\GuzzleHttp\Client
*/
public ClientInterface|\GuzzleHttp\Client $client;

public function __construct($base_url)
/**
* @param string $base_url
*/
public function __construct(string $base_url)
{
$this->client = new \GuzzleHttp\Client([
'base_uri' => $base_url, // Replace with the actual base URI
Expand All @@ -17,9 +26,14 @@ public function __construct($base_url)
}


/**
* @param string $uri
* @param $queryParams
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get(string $uri, $queryParams)
{
dump($queryParams);
$res = $this->client->request('GET', $uri, ['query' => $queryParams]);
return json_decode($res->getBody()->getContents(), true);
}
Expand Down
3 changes: 1 addition & 2 deletions config/news_endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

return [
'news-api' => [

'key' => 'cedc49391f90414382ff139b743013c8',
'key' => '77ce12864b7548c5be2f474a81790e0b',
'base_url' => 'https://newsapi.org/v2/',
],

Expand Down

0 comments on commit ff10f7a

Please sign in to comment.