API 加入 room/heartbeat 20250522
This commit is contained in:
parent
3bbb1a5cc0
commit
d2f5576f94
@ -4,7 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\SendRoomSwitchCommandRequest;
|
||||
use App\Http\Requests\ReceiveRoomRegisterRequest;
|
||||
use App\Http\Requests\ReceiveRoomStatusRequest;
|
||||
use App\Http\Requests\ReceiveRoomStatusDataRequest;
|
||||
use App\Services\TcpSocketClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@ -99,7 +99,7 @@ class RoomControlController extends Controller
|
||||
}
|
||||
|
||||
// 6. 更新包廂資訊
|
||||
$room->internal_ip = $request->ip();
|
||||
$room->internal_ip = $validated['room_ip'];
|
||||
$room->port = 1000; // 預設值
|
||||
$room->is_online =1;
|
||||
$room->status = RoomStatus::Closed;
|
||||
@ -112,15 +112,57 @@ class RoomControlController extends Controller
|
||||
'room' => $room,
|
||||
]);
|
||||
}
|
||||
public function StatusReport(ReceiveRoomStatusRequest $request)
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/room/heartbeat",
|
||||
* summary="包廂心跳封包指令",
|
||||
* description="。",
|
||||
* operationId="heartbeatRoomCommand",
|
||||
* tags={"Room Control"},
|
||||
* security={{"Authorization":{}}},
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
* @OA\JsonContent(ref="#/components/schemas/ReceiveRoomStatusDataRequest")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="成功傳送指令並回傳 TCP 回應",
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
* @OA\Property(property="data", ref="#/components/schemas/MachineStatus")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=401,
|
||||
* description="Unauthorized",
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
* @OA\Property(property="code", type="string", example="UNAUTHORIZED"),
|
||||
* @OA\Property(property="message", type="string", example="Unauthorized"),
|
||||
* @OA\Property(property="data", type="null")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
* @OA\Parameter(
|
||||
* name="Accept",
|
||||
* in="header",
|
||||
* required=true,
|
||||
* @OA\Schema(type="string", default="application/json")
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function StatusReport(ReceiveRoomStatusDataRequest $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'hostname' => 'required|string',
|
||||
'ip' => 'required|string',
|
||||
'cpu' => 'nullable|numeric',
|
||||
'memory' => 'nullable|numeric',
|
||||
'disk' => 'nullable|numeric',
|
||||
'status' => 'required|string',
|
||||
return ApiResponse::success([
|
||||
'data' => MachineStatus::create($request->validated()),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
* required={"branch_id", "room_name", "email" ,"password"},
|
||||
* @OA\Property(property="branch_id", type="integer", example="1"),
|
||||
* @OA\Property(property="room_name", type="string", example="102"),
|
||||
* @OA\Property(property="room_ip", type="string", example="192.168.1.1"),
|
||||
* @OA\Property(property="email", type="string", example="XX@gmail.com"),
|
||||
* @OA\Property(property="password", type="string", example="XXX"),
|
||||
* )
|
||||
@ -26,6 +27,7 @@ class ReceiveRoomRegisterRequest extends ApiRequest
|
||||
return [
|
||||
'branch_id' => 'required|integer|exists:branches,id',
|
||||
'room_name' => 'required|string',
|
||||
'room_ip' => 'required|string',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
];
|
||||
|
@ -6,7 +6,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="ReceiveRoomStatusRequest",
|
||||
* schema="ReceiveRoomStatusDataRequest",
|
||||
* required={"hostname", "ip", "status"},
|
||||
* @OA\Property(property="hostname", type="string", example=""),
|
||||
* @OA\Property(property="ip", type="string", example=""),
|
||||
@ -16,7 +16,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
* @OA\Property(property="status", type="string", example=""),
|
||||
* )
|
||||
*/
|
||||
class ReceiveRoomStatusRequest extends ApiRequest
|
||||
class ReceiveRoomStatusDataRequest extends ApiRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
@ -4,6 +4,18 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="MachineStatus",
|
||||
* type="object",
|
||||
* @OA\Property(property="hostname", type="string", example=""),
|
||||
* @OA\Property(property="ip", type="string", example=""),
|
||||
* @OA\Property(property="cpu", type="string"),
|
||||
* @OA\Property(property="memory", type="string", example=""),
|
||||
* @OA\Property(property="disk", type="string", example=""),
|
||||
* @OA\Property(property="status", type="string", example=""),
|
||||
* )
|
||||
*/
|
||||
class MachineStatus extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
|
@ -12,5 +12,5 @@ Route::post('/room/receiveRegister', [RoomControlController::class, 'receiveRegi
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::get('/profile', [AuthController::class, 'profile']);
|
||||
Route::post('/room/sendSwitch', [RoomControlController::class, 'sendSwitch']);
|
||||
Route::post('/room/system-status', [RoomControlController::class, 'StatusReport']);
|
||||
Route::post('/room/heartbeat', [RoomControlController::class, 'StatusReport']);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user