Moved more stuff into actions, and made one endpoint for homepage data

This commit is contained in:
Henry Whitaker
2021-03-07 10:43:07 +00:00
parent a2d8886bae
commit 75c5a49398
7 changed files with 173 additions and 40 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Actions;
use App\Helpers\SettingsHelper;
use App\Speedtest;
use Cache;
use Carbon\Carbon;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
class GetSpeedtestTimeData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run($days = 7)
{
$ttl = Carbon::now()->addDays(1);
return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
if ($showFailed === true) {
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->orderBy('created_at', 'asc')
->get();
}
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->where('failed', false)
->orderBy('created_at', 'asc')
->get();
});
}
}