refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component (#1489)

* refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component
* feat(gui): Add network config saving and refactor RemoteManagement
This commit is contained in:
Mg Pig
2025-10-20 22:07:01 +08:00
committed by GitHub
parent 67ac9b00ff
commit eba9504fc2
27 changed files with 1040 additions and 793 deletions
+30 -3
View File
@@ -51,6 +51,11 @@ struct ValidateConfigJsonReq {
config: NetworkConfig,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct SaveNetworkJsonReq {
config: NetworkConfig,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct RunNetworkJsonReq {
config: NetworkConfig,
@@ -177,9 +182,9 @@ impl NetworkApi {
Path((machine_id, inst_id)): Path<(uuid::Uuid, uuid::Uuid)>,
) -> Result<(), HttpHandleError> {
client_mgr
.handle_remove_network_instance(
.handle_remove_network_instances(
(Self::get_user_id(&auth_session)?, machine_id),
inst_id,
vec![inst_id],
)
.await
.map_err(convert_error)
@@ -232,6 +237,28 @@ impl NetworkApi {
.map_err(convert_error)
}
async fn handle_save_network_config(
auth_session: AuthSession,
State(client_mgr): AppState,
Path((machine_id, inst_id)): Path<(uuid::Uuid, uuid::Uuid)>,
Json(payload): Json<SaveNetworkJsonReq>,
) -> Result<(), HttpHandleError> {
if payload.config.instance_id() != inst_id.to_string() {
return Err((
StatusCode::BAD_REQUEST,
other_error("Instance ID mismatch".to_string()).into(),
));
}
client_mgr
.handle_save_network_config(
(Self::get_user_id(&auth_session)?, machine_id),
inst_id,
payload.config,
)
.await
.map_err(convert_error)
}
async fn handle_get_network_config(
auth_session: AuthSession,
State(client_mgr): AppState,
@@ -269,7 +296,7 @@ impl NetworkApi {
)
.route(
"/api/v1/machines/:machine-id/networks/config/:inst-id",
get(Self::handle_get_network_config),
get(Self::handle_get_network_config).put(Self::handle_save_network_config),
)
}
}