ConsultancyProject_2_ETL/dashboard/app/Api.php

94 lines
2.0 KiB
PHP

<?php
namespace App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class Api
{
public function __construct()
{
}
public static function get(string $path, string $query = ''): ?array
{
$endpoint = env('FASTAPI_URI');
$request = $endpoint.$path;
if (Cache::has($request)) {
return Cache::get($request);
}
$get = Http::timeout(800)->get($request);
if($get->successful()){
$result = $get->json();
Cache::put($request, $result);
return $result;
}
return null;
}
public static function propertiesPerRegion()
{
return self::get('/region/properties');
}
public static function propertiesGrowth()
{
return self::get('/properties/growth');
}
public static function propertiesGeo()
{
return self::get('/properties/geo');
}
public static function propertyExtractions(int $id)
{
return self::get("/property/{$id}/extractions");
}
public static function propertyCapacities(int $id)
{
return self::get("/property/{$id}/capacities");
}
public static function propertyBase(int $id): mixed
{
return self::get("/property/{$id}/base");
}
public static function regionPropertyCapacities(int $id): mixed
{
return self::get("/region/{$id}/properties/capacities");
}
public static function propertyCapacitiesMonthly(int $id, string $date): mixed
{
return self::get("/property/{$id}/capacities/monthly/{$date}");
}
public static function propertyCapacitiesDaily(int $id, string $date): mixed
{
return self::get("/property/{$id}/capacities/weekdays/{$date}");
}
public static function propertyNeighbours(int $id): mixed
{
return self::get("/property/{$id}/neighbours");
}
public static function regionCapacities(int $id): mixed
{
return self::get("/region/{$id}/capacities");
}
}