Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion app/Actions/Ookla/RunSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ class RunSpeedtest
{
use AsAction;

public function handle(bool $scheduled = false, ?int $serverId = null): mixed
public function handle(bool $scheduled = false, ?int $serverId = null, ?int $dispatchedBy = null): mixed
{
$result = Result::create([
'data->server->id' => $serverId,
'service' => ResultService::Ookla,
'status' => ResultStatus::Waiting,
'scheduled' => $scheduled,
'dispatched_by' => $dispatchedBy,
]);

SpeedtestWaiting::dispatch($result);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/V1/SpeedtestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __invoke(Request $request)

$result = RunSpeedtestAction::run(
serverId: $request->input('server_id'),
dispatchedBy: $request->user()->id,
);

return $this->sendResponse(
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/V1/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function toArray(Request $request): array
'healthy' => $this->healthy,
'status' => $this->status,
'scheduled' => $this->scheduled,
'dispatched_by' => $this->dispatched_by,
'comments' => $this->comments,
'data' => $this->data,
'created_at' => $this->created_at->toDateTimestring(),
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Topbar/RunSpeedtestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function speedtestAction(): Action

RunSpeedtest::run(
serverId: $serverId,
dispatchedBy: Auth::id(),
);

Notification::make()
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Result extends Model
{
Expand Down Expand Up @@ -45,4 +46,12 @@ public function prunable(): Builder
{
return static::where('created_at', '<=', now()->subDays(config('speedtest.prune_results_older_than')));
}

/**
* Get the user who dispatched this speedtest.
*/
public function dispatchedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'dispatched_by');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('results', function (Blueprint $table) {
$table->foreignId('dispatched_by')->nullable()->constrained('users')->nullOnDelete();
});
}
};
Loading