From cf8ac547907d67046c743697807fc9dcc73fbc85 Mon Sep 17 00:00:00 2001 From: Djonathan Date: Mon, 27 Jun 2022 10:48:34 -0300 Subject: [PATCH] Implement news integration. --- app/Helpers/CustomHelpers.php | 11 ++++++++++ app/Http/Controllers/NewsController.php | 22 +++++++++++++++++++ app/Http/Resources/NewsResource.php | 19 ++++++++++++++++ .../Economy/EconomyRepository.php | 18 +-------------- composer.json | 1 + config/services.php | 4 ++++ routes/api.php | 2 ++ 7 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 app/Http/Controllers/NewsController.php create mode 100644 app/Http/Resources/NewsResource.php diff --git a/app/Helpers/CustomHelpers.php b/app/Helpers/CustomHelpers.php index 7af831c..850916b 100644 --- a/app/Helpers/CustomHelpers.php +++ b/app/Helpers/CustomHelpers.php @@ -31,3 +31,14 @@ if (!function_exists('stats_standard_deviation')) { return sqrt($carry / $n); } } + +if (!function_exists('xmlToObject')) { + + function xmlToObject($link): SimpleXMLElement|bool + { + if (!$link){ + abort(500, 'Error.'); + } + return @simplexml_load_string(@file_get_contents($link), 'SimpleXMLElement', LIBXML_NOCDATA); + } +} diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php new file mode 100644 index 0000000..11d1587 --- /dev/null +++ b/app/Http/Controllers/NewsController.php @@ -0,0 +1,22 @@ +children()), true); + return (new NewsResource($resource)) + ->response() + ->setStatusCode(Response::HTTP_OK); + } catch (\Exception $ex) { + return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/Http/Resources/NewsResource.php b/app/Http/Resources/NewsResource.php new file mode 100644 index 0000000..36ce8bf --- /dev/null +++ b/app/Http/Resources/NewsResource.php @@ -0,0 +1,19 @@ +execute($params, $field) + return $this->execute($params, $field) ->where(DB::raw("TO_DATE(economia.mes, 'YYMM')"), ">=", DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - interval '1' year")) @@ -68,10 +68,6 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt ->orderBy('mes') ->orderBy('dad_estimado') ->get(); - - $t = $this->array_sort_by_column($test, 'mes'); - - dd($t); } public function getCaptiveMonthlyEconomy($params) @@ -161,16 +157,4 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt return $arr; } - - public function array_sort_by_column(&$array, $column, $direction = SORT_ASC) { - $reference_array = array(); - - foreach($array as $key => $row) { - $reference_array[$key] = $row[$column]; - } - - return array_multisort($reference_array, $direction, $array); - } - - } diff --git a/composer.json b/composer.json index b5661e4..691e838 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.1", "ext-fileinfo": "*", + "ext-simplexml": "*", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.11", "laravel/sanctum": "^2.14.1", diff --git a/config/services.php b/config/services.php index 0ace530..c655e88 100644 --- a/config/services.php +++ b/config/services.php @@ -31,4 +31,8 @@ return [ 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), ], + 'webhook' => [ + 'news' => env('WEBHOOK_NEWS') + ] + ]; diff --git a/routes/api.php b/routes/api.php index 7a59a81..e94c7d7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -72,6 +72,8 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () { Route::post('notify', [\App\Http\Controllers\NotificationController::class, 'notify']); Route::get('aboutUs', [\App\Http\Controllers\AboutUsController::class, 'index']); + + Route::get('news', [\App\Http\Controllers\NewsController::class, 'send']); });