Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6741fab
Merge pull request #1 from alexjustesen/main
cinderblockgames Mar 9, 2023
08e2013
Adding speedtest/latest.
cinderblockgames Mar 9, 2023
cd0a161
Create SpeedtestController.php
cinderblockgames Mar 9, 2023
80c1c50
Create SpeedtestHelper.php
cinderblockgames Mar 9, 2023
b91b657
Merge branch 'alexjustesen:main' into homepage-api
cinderblockgames Mar 9, 2023
43831d5
Create GetLatestSpeedtestData.php
cinderblockgames Mar 9, 2023
be39a15
Attempting to fix error.
cinderblockgames Mar 9, 2023
c406c9c
Undoing previous change.
cinderblockgames Mar 9, 2023
79e6c21
Adding back henrywhitaker3/laravel-actions.
cinderblockgames Mar 9, 2023
be06ef3
Adding back henrywhitaker3/laravel-actions.
cinderblockgames Mar 9, 2023
08fc634
Hoping for the best here..
cinderblockgames Mar 9, 2023
5d541fd
Switching to new Model.
cinderblockgames Mar 9, 2023
38698d7
Removing extra data.
cinderblockgames Mar 9, 2023
ce0b854
Translating to Mbps.
cinderblockgames Mar 9, 2023
7d6544f
Merge branch 'alexjustesen:main' into homepage-api
cinderblockgames Mar 9, 2023
625c4fc
Merge pull request #2 from cinderblockgames/homepage-api
cinderblockgames Mar 9, 2023
4ffbfd5
Simplifying.
cinderblockgames Mar 9, 2023
a479943
Delete GetLatestSpeedtestData.php
cinderblockgames Mar 9, 2023
c63dba0
Update composer.json
cinderblockgames Mar 9, 2023
001a2bb
Reverting.
cinderblockgames Mar 9, 2023
93eddec
Merge pull request #3 from cinderblockgames/streamline
cinderblockgames Mar 9, 2023
51aade0
Further consolidating.
cinderblockgames Mar 9, 2023
f4c7191
Delete SpeedtestHelper.php
cinderblockgames Mar 9, 2023
e49b141
Missed adding the model.
cinderblockgames Mar 9, 2023
51cde7f
refactored to more modern coding standards
alexjustesen Mar 9, 2023
03f7594
Merge pull request #4 from alexjustesen/cinderblockgames/main
cinderblockgames Mar 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/Http/Controllers/API/Speedtest/GetLatestController.php
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
],
]);
}
}
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\API\Speedtest\GetLatestController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand All @@ -17,3 +18,6 @@
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});

Route::get('/speedtest/latest', GetLatestController::class)
->name('speedtest.latest');