mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2026-01-01 02:27:21 +01:00
Moved more stuff into actions, and made one endpoint for homepage data
This commit is contained in:
52
app/Actions/GetLatestSpeedtestData.php
Normal file
52
app/Actions/GetLatestSpeedtestData.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Speedtest;
|
||||
use DB;
|
||||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||
|
||||
class GetLatestSpeedtestData implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* Run the action.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$data = SpeedtestHelper::latest();
|
||||
|
||||
$response = [
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
if (SettingsHelper::get('show_average')) {
|
||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['average'] = $avg;
|
||||
}
|
||||
|
||||
if (SettingsHelper::get('show_max')) {
|
||||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['maximum'] = $max;
|
||||
}
|
||||
|
||||
if (SettingsHelper::get('show_min')) {
|
||||
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['minimum'] = $min;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user