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
{
$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();

View File

@ -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',

View File

@ -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,