mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 04:10:25 +00:00
Add dispatched_by field to results and update related logic (#2431)
Co-authored-by: Alex Justesen <1144087+alexjustesen@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -38,6 +38,7 @@ class SpeedtestController extends ApiController
|
||||
|
||||
$result = RunSpeedtestAction::run(
|
||||
serverId: $request->input('server_id'),
|
||||
dispatchedBy: $request->user()->id,
|
||||
);
|
||||
|
||||
return $this->sendResponse(
|
||||
|
||||
@@ -34,6 +34,7 @@ class ResultResource extends JsonResource
|
||||
'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(),
|
||||
|
||||
@@ -53,6 +53,7 @@ class RunSpeedtestAction extends Component implements HasActions, HasForms
|
||||
|
||||
RunSpeedtest::run(
|
||||
serverId: $serverId,
|
||||
dispatchedBy: Auth::id(),
|
||||
);
|
||||
|
||||
Notification::make()
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
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
|
||||
{
|
||||
@@ -45,4 +46,12 @@ class Result extends Model
|
||||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user