Send Room Switch command 中原 branch_id 改成 用branch_name

20250528
This commit is contained in:
allen.yan 2025-05-28 10:21:05 +08:00
parent 7c8c3fe69b
commit a45c139db7
3 changed files with 9 additions and 8 deletions

View File

@ -70,9 +70,6 @@ class RoomControlController extends Controller
*/ */
public function receiveRegister(ReceiveRoomRegisterRequest $request): JsonResponse public function receiveRegister(ReceiveRoomRegisterRequest $request): JsonResponse
{ {
$data = $request->only(['branch', 'room_name', 'room_ip', 'email']); // 不記錄密碼
Log::info('Token Request Payload:', $data);
// 1. 驗證帳密(登入用) // 1. 驗證帳密(登入用)
$credentials = $request->only('email', 'password'); $credentials = $request->only('email', 'password');
@ -257,7 +254,7 @@ class RoomControlController extends Controller
$validated = $request->validated(); $validated = $request->validated();
$room = Room::where([ $room = Room::where([
['branch_id', $validated['branch_id']], ['branch_name', $validated['branch_name']],
['name', $validated['room_name']], ['name', $validated['room_name']],
])->first(); ])->first();

View File

@ -7,8 +7,8 @@ use Illuminate\Foundation\Http\FormRequest;
/** /**
* @OA\Schema( * @OA\Schema(
* schema="SendRoomSwitchCommandRequest", * schema="SendRoomSwitchCommandRequest",
* required={"branch_id", "room_name", "command"}, * required={"branch_name", "room_name", "command"},
* @OA\Property(property="branch_id", type="integer", example="5"), * @OA\Property(property="branch_name", type="string", example="測試"),
* @OA\Property(property="room_name", type="string", example="pc102"), * @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="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"), * @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 public function rules(): array
{ {
return [ return [
'branch_id' => 'required|integer', 'branch_name' =>'required|string|exists:branches,name',
'room_name' => 'required|string', 'room_name' => 'required|string',
'command' => 'required|string', 'command' => 'required|string',
'started_at' => 'nullable|date_format:Y-m-d H:i:s', 'started_at' => 'nullable|date_format:Y-m-d H:i:s',

View File

@ -3,6 +3,7 @@
namespace App\Livewire\Admin; namespace App\Livewire\Admin;
use App\Models\Room; use App\Models\Room;
use App\Models\Branch;
use Livewire\Component; use Livewire\Component;
use App\Services\ApiClient; use App\Services\ApiClient;
@ -20,11 +21,13 @@ class RoomDetailModal extends Component
]; ];
public $room; public $room;
public $branch;
public bool $showModal = false; public bool $showModal = false;
public function openModal($roomId) public function openModal($roomId)
{ {
$this->room = Room::find($roomId); $this->room = Room::find($roomId);
$this->branch = Branch::find($this->room->branch_id);
$this->showModal = true; $this->showModal = true;
} }
public function closeModal() public function closeModal()
@ -63,8 +66,9 @@ class RoomDetailModal extends Component
} }
protected function buildNotifyData(string $command, $startedAt = null, $endedAt = null): array protected function buildNotifyData(string $command, $startedAt = null, $endedAt = null): array
{ {
return [ return [
'branch_id' => $this->room->branch_id ?? 0, 'branch_name' => $this->branch->name ?? '',
'room_name' => $this->room->name ?? '', 'room_name' => $this->room->name ?? '',
'command' => $command, 'command' => $command,
'started_at' => $startedAt ? $startedAt->toDateTimeString() : null, 'started_at' => $startedAt ? $startedAt->toDateTimeString() : null,