b2in/app/Http/Controllers/Api/CabinetTabletController.php
2026-04-10 17:18:17 +02:00

54 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\CabinetTabletSetting;
use Illuminate\Http\JsonResponse;
class CabinetTabletController extends Controller
{
/**
* Full status response for the info-tablet.
*/
public function status(): JsonResponse
{
$settings = CabinetTabletSetting::current();
$computed = $settings->computeStatus();
return response()->json([
'store_status' => $computed['status'],
'today_close' => $computed['today_close'],
'next_open' => $computed['next_open'],
'notice_headline' => $settings->notice_headline,
'notice_subtext' => $settings->notice_subtext,
'override_open_today' => $settings->override_open_today,
'override_close_today' => $settings->override_close_today,
'next_appointment' => [
'date' => $settings->next_appointment_date?->format('Y-m-d'),
'time' => $settings->next_appointment_time,
],
'hours' => $settings->getHoursArray(),
'contact' => [
'phone' => $settings->contact_phone,
'email' => $settings->contact_email,
],
'updated_at' => $settings->updated_at?->toIso8601String(),
]);
}
/**
* Lightweight check returns the timestamp and current computed status
* so the tablet can detect both settings changes and time-based open/close transitions.
*/
public function check(): JsonResponse
{
$settings = CabinetTabletSetting::current();
$computed = $settings->computeStatus();
return response()->json([
'updated_at' => $settings->updated_at?->toIso8601String(),
'store_status' => $computed['status'],
]);
}
}