diff --git a/app/Enums/RoomStatus.php b/app/Enums/RoomStatus.php index 72ae246..3339443 100644 --- a/app/Enums/RoomStatus.php +++ b/app/Enums/RoomStatus.php @@ -8,7 +8,7 @@ use App\Enums\Traits\HasLabels; * @OA\Schema( * schema="RoomStatus", * type="string", - * enum={"active", "closed", "fire", "maintenance"}, + * enum={"active", "closed", "fire", "error"}, * example="error" * ) */ diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index 9403583..cd35a74 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -305,10 +305,16 @@ class RoomControlController extends Controller if (!$room) { return ApiResponse::error('房間不存在'); } - - $room->status=$validated['command']; - $room->started_at=$validated['started_at']; - $room->ended_at=$validated['ended_at']; + if($validated['command']==='error'){ + $room->is_online=0; + $room->status=$validated['command']; + $room->started_at=null; + $room->ended_at=null; + }else{ + $room->status=$validated['command']; + $room->started_at=$validated['started_at']; + $room->ended_at=$validated['ended_at']; + } $room->save(); return ApiResponse::success($room); diff --git a/app/Http/Requests/SendRoomSwitchCommandRequest.php b/app/Http/Requests/SendRoomSwitchCommandRequest.php index 049d84a..07b8bcc 100644 --- a/app/Http/Requests/SendRoomSwitchCommandRequest.php +++ b/app/Http/Requests/SendRoomSwitchCommandRequest.php @@ -10,7 +10,7 @@ use Illuminate\Foundation\Http\FormRequest; * 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="command", type="string", enum={"active", "closed", "fire", "error"}, example="active"), * @OA\Property(property="started_at", type="string", nullable=true, example="2025-05-19 09:31:00"), * @OA\Property(property="ended_at", type="string", nullable=true, example="2025-05-19 09:31:00") * ) @@ -27,7 +27,7 @@ class SendRoomSwitchCommandRequest extends ApiRequest return [ 'branch_name' => ['required','string','exists:branches,name'], 'room_name' => ['required','string'], - 'command' => ['required','in:active,closed,fire'], + 'command' => ['required','in:active,closed,fire,error'], 'started_at'=> ['nullable','date_format:Y-m-d H:i:s'], 'ended_at' => ['nullable','date_format:Y-m-d H:i:s'], ];