同步 receiveSwitch 當 Error 把連線清除 20250605

This commit is contained in:
allen.yan 2025-06-05 09:28:21 +08:00
parent 39872d5aac
commit de64bf2d45
3 changed files with 13 additions and 7 deletions

View File

@ -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"
* )
*/

View File

@ -305,10 +305,16 @@ class RoomControlController extends Controller
if (!$room) {
return ApiResponse::error('房間不存在');
}
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);

View File

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