From a45c139db7e9d4ae1bf8abf2bd722d1a347adcd7 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Wed, 28 May 2025 10:21:05 +0800 Subject: [PATCH] =?UTF-8?q?Send=20Room=20Switch=20command=20=E4=B8=AD?= =?UTF-8?q?=E5=8E=9F=20branch=5Fid=20=E6=94=B9=E6=88=90=20=E7=94=A8branch?= =?UTF-8?q?=5Fname=2020250528?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/RoomControlController.php | 5 +---- app/Http/Requests/SendRoomSwitchCommandRequest.php | 6 +++--- app/Livewire/Admin/RoomDetailModal.php | 6 +++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index efdd6fa..af93f8c 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -70,9 +70,6 @@ class RoomControlController extends Controller */ public function receiveRegister(ReceiveRoomRegisterRequest $request): JsonResponse { - $data = $request->only(['branch', 'room_name', 'room_ip', 'email']); // 不記錄密碼 - Log::info('Token Request Payload:', $data); - // 1. 驗證帳密(登入用) $credentials = $request->only('email', 'password'); @@ -257,7 +254,7 @@ class RoomControlController extends Controller $validated = $request->validated(); $room = Room::where([ - ['branch_id', $validated['branch_id']], + ['branch_name', $validated['branch_name']], ['name', $validated['room_name']], ])->first(); diff --git a/app/Http/Requests/SendRoomSwitchCommandRequest.php b/app/Http/Requests/SendRoomSwitchCommandRequest.php index ba5a533..928d646 100644 --- a/app/Http/Requests/SendRoomSwitchCommandRequest.php +++ b/app/Http/Requests/SendRoomSwitchCommandRequest.php @@ -7,8 +7,8 @@ use Illuminate\Foundation\Http\FormRequest; /** * @OA\Schema( * schema="SendRoomSwitchCommandRequest", - * required={"branch_id", "room_name", "command"}, - * @OA\Property(property="branch_id", type="integer", example="5"), + * required={"branch_name", "room_name", "command"}, + * @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="room_name", type="string", example="pc102"), * @OA\Property(property="command", type="string", enum={"active", "closed", "fire", "maintenance"}, example="active"), * @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"), @@ -25,7 +25,7 @@ class SendRoomSwitchCommandRequest extends ApiRequest public function rules(): array { return [ - 'branch_id' => 'required|integer', + 'branch_name' =>'required|string|exists:branches,name', 'room_name' => 'required|string', 'command' => 'required|string', 'started_at' => 'nullable|date_format:Y-m-d H:i:s', diff --git a/app/Livewire/Admin/RoomDetailModal.php b/app/Livewire/Admin/RoomDetailModal.php index 5883175..bcac030 100644 --- a/app/Livewire/Admin/RoomDetailModal.php +++ b/app/Livewire/Admin/RoomDetailModal.php @@ -3,6 +3,7 @@ namespace App\Livewire\Admin; use App\Models\Room; +use App\Models\Branch; use Livewire\Component; use App\Services\ApiClient; @@ -20,11 +21,13 @@ class RoomDetailModal extends Component ]; public $room; + public $branch; public bool $showModal = false; public function openModal($roomId) { $this->room = Room::find($roomId); + $this->branch = Branch::find($this->room->branch_id); $this->showModal = true; } public function closeModal() @@ -63,8 +66,9 @@ class RoomDetailModal extends Component } protected function buildNotifyData(string $command, $startedAt = null, $endedAt = null): array { + return [ - 'branch_id' => $this->room->branch_id ?? 0, + 'branch_name' => $this->branch->name ?? '', 'room_name' => $this->room->name ?? '', 'command' => $command, 'started_at' => $startedAt ? $startedAt->toDateTimeString() : null,