Implement news integration.
This commit is contained in:
parent
aaccbd83c8
commit
cf8ac54790
@ -31,3 +31,14 @@ if (!function_exists('stats_standard_deviation')) {
|
|||||||
return sqrt($carry / $n);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
22
app/Http/Controllers/NewsController.php
Normal file
22
app/Http/Controllers/NewsController.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Resources\NewsResource;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class NewsController extends Controller
|
||||||
|
{
|
||||||
|
public function send()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$xmlObject = xmlToObject(config('services.webhook.news'));
|
||||||
|
$resource = @json_decode(@json_encode($xmlObject->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Http/Resources/NewsResource.php
Normal file
19
app/Http/Resources/NewsResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class NewsResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -60,7 +60,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
"economia.dad_estimado"
|
"economia.dad_estimado"
|
||||||
];
|
];
|
||||||
|
|
||||||
$test = $this->execute($params, $field)
|
return $this->execute($params, $field)
|
||||||
->where(DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
->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"))
|
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('mes')
|
||||||
->orderBy('dad_estimado')
|
->orderBy('dad_estimado')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$t = $this->array_sort_by_column($test, 'mes');
|
|
||||||
|
|
||||||
dd($t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCaptiveMonthlyEconomy($params)
|
public function getCaptiveMonthlyEconomy($params)
|
||||||
@ -161,16 +157,4 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
return $arr;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
"ext-fileinfo": "*",
|
"ext-fileinfo": "*",
|
||||||
|
"ext-simplexml": "*",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"laravel/framework": "^9.11",
|
"laravel/framework": "^9.11",
|
||||||
"laravel/sanctum": "^2.14.1",
|
"laravel/sanctum": "^2.14.1",
|
||||||
|
|||||||
@ -31,4 +31,8 @@ return [
|
|||||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'webhook' => [
|
||||||
|
'news' => env('WEBHOOK_NEWS')
|
||||||
|
]
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@ -72,6 +72,8 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
|||||||
Route::post('notify', [\App\Http\Controllers\NotificationController::class, 'notify']);
|
Route::post('notify', [\App\Http\Controllers\NotificationController::class, 'notify']);
|
||||||
|
|
||||||
Route::get('aboutUs', [\App\Http\Controllers\AboutUsController::class, 'index']);
|
Route::get('aboutUs', [\App\Http\Controllers\AboutUsController::class, 'index']);
|
||||||
|
|
||||||
|
Route::get('news', [\App\Http\Controllers\NewsController::class, 'send']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user