-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alex Justesen <alexjustesen@users.noreply.github.com>
- Loading branch information
1 parent
3628dcd
commit dc456ff
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/Http/Controllers/API/Speedtest/GetLatestController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API\Speedtest; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Result; | ||
|
||
class GetLatestController extends Controller | ||
{ | ||
/** | ||
* Handle the incoming request. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function __invoke() | ||
{ | ||
$latest = Result::query() | ||
->latest() | ||
->firstOr(function () { | ||
return response()->json([ | ||
'message' => 'No results found.', | ||
], 404); | ||
}); | ||
|
||
return response()->json([ | ||
'message' => 'ok', | ||
'data' => [ | ||
'id' => $latest->id, | ||
'ping' => $latest->ping, | ||
'download' => ! blank($latest->download) ? formatBits(formatBytestoBits($latest->download), 4, false) : null, | ||
'upload' => ! blank($latest->upload) ? formatBits(formatBytestoBits($latest->upload), 4, false) : null, | ||
'server_id' => $latest->server_id, | ||
'server_host' => $latest->server_host, | ||
'server_name' => $latest->server_name, | ||
'url' => $latest->url, | ||
'scheduled' => $latest->scheduled, | ||
'failed' => $latest->successful, | ||
'created_at' => $latest->created_at->toISOString(), | ||
'updated_at' => $latest->created_at->toISOString(), // faking updated at to match legacy api payload | ||
], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters