ConsultancyProject_2_ETL/dashboard/app/Api.php

86 lines
1.7 KiB
PHP
Raw Normal View History

2024-12-18 15:14:13 +01:00
<?php
namespace App;
use Illuminate\Support\Facades\Cache;
2024-12-18 15:14:13 +01:00
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);
}
2024-12-18 15:14:13 +01:00
$get = Http::get($request);
if($get->successful()){
$result = $get->json();
Cache::put($request, $result);
return $result;
2024-12-18 15:14:13 +01:00
}
return null;
}
public static function propertiesPerRegion()
{
return self::get('/region/properties');
}
2024-12-18 19:52:06 +01:00
public static function propertiesGrowth()
{
return self::get('/properties/growth');
}
public static function propertiesGeo()
{
return self::get('/properties/geo');
}
2024-12-18 15:14:13 +01:00
public static function propertyExtractions(int $id)
{
2024-12-18 19:52:06 +01:00
return self::get("/property/{$id}/extractions");
}
public static function propertyCapacities(int $id)
{
return self::get("/property/{$id}/capacities");
}
2024-12-18 19:52:06 +01:00
public static function propertyBase(int $id): mixed
{
return self::get("/property/{$id}/base");
2024-12-18 15:14:13 +01:00
}
2024-12-20 21:46:54 +01:00
public static function regionCapacities(int $id): mixed
{
return self::get("/region/{$id}/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}");
}
2024-12-18 15:14:13 +01:00
}