54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?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'],
|
||
]);
|
||
}
|
||
}
|