schneespur/schneespur/app/Http/Controllers/Api/OwnTracksController.php
Michael b8e426ba2d Restructure: move code into schneespur/ subdirectory, fix Umlauts
- Move all application code into schneespur/ subdirectory for cleaner
  GitHub presentation (README, LICENSE, INSTALL guides stay in root)
- Fix German Umlaut encoding in INSTALL.de.md and README.md
  (ae→ä, oe→ö, ue→ü throughout)
- ZIP download structure remains flat (code in root) for easy deployment
2026-05-17 13:52:39 +00:00

49 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\GpsPoint;
use App\Services\JobLifecycleService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class OwnTracksController extends Controller
{
public function store(Request $request): JsonResponse
{
if ($request->input('_type') !== 'location') {
return response()->json([], 200);
}
$validated = $request->validate([
'lat' => 'required|numeric',
'lon' => 'required|numeric',
'tst' => 'required|integer',
'alt' => 'nullable|numeric',
'batt' => 'nullable|integer',
'vel' => 'nullable|integer',
'acc' => 'nullable|integer',
]);
$activeJob = app(JobLifecycleService::class)->findActiveJob($request->user());
if ($activeJob === null) {
return response()->json([], 200);
}
GpsPoint::create([
'user_id' => $request->user()->id,
'job_id' => $activeJob->id,
'lat' => $validated['lat'],
'lon' => $validated['lon'],
'timestamp' => $validated['tst'],
'altitude' => $validated['alt'] ?? null,
'battery' => $validated['batt'] ?? null,
'velocity' => $validated['vel'] ?? null,
'accuracy' => $validated['acc'] ?? null,
]);
return response()->json([], 200);
}
}