Skip to content

Commit 48ea4d3

Browse files
committed
Refactor API structures by removing unused fields and functions across backups, floating IPs, images, ISOs, and snapshots. Update related templates to enhance clarity and maintainability. Streamline product view by eliminating unnecessary display fields.
1 parent 4af2be7 commit 48ea4d3

16 files changed

Lines changed: 5 additions & 201 deletions

File tree

src/api/backups.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub struct BackupProfileView {
99
pub schedule_frequency: Option<String>,
1010
pub monthly_price: Option<f64>,
1111
pub max_files: Option<i32>,
12-
pub created_at: Option<i64>,
1312
}
1413

1514
/// Load backup profiles from the API
@@ -32,7 +31,6 @@ pub async fn load_backups(
3231
schedule_frequency: obj.get("scheduleFrequency").and_then(|v| v.as_str()).map(|s| s.to_string()),
3332
monthly_price: obj.get("monthlyPrice").and_then(|v| v.as_f64()),
3433
max_files: obj.get("maxFiles").and_then(|v| v.as_i64()).map(|i| i as i32),
35-
created_at: obj.get("createdAt").and_then(|v| v.as_i64()),
3634
});
3735
}
3836
}
@@ -43,17 +41,6 @@ pub async fn load_backups(
4341
backups
4442
}
4543

46-
/// Get backup profile for instance
47-
pub async fn get_backup_profile(
48-
client: &reqwest::Client,
49-
api_base_url: &str,
50-
api_token: &str,
51-
instance_id: &str,
52-
) -> Value {
53-
let endpoint = format!("/v1/backups/{}", instance_id);
54-
api_call(client, api_base_url, api_token, "GET", &endpoint, None, None).await
55-
}
56-
5744
/// Create backup profile
5845
pub async fn create_backup_profile(
5946
client: &reqwest::Client,
@@ -76,37 +63,3 @@ pub async fn create_backup_profile(
7663

7764
api_call(client, api_base_url, api_token, "POST", "/v1/backups", Some(payload), None).await
7865
}
79-
80-
/// Update backup profile
81-
pub async fn update_backup_profile(
82-
client: &reqwest::Client,
83-
api_base_url: &str,
84-
api_token: &str,
85-
instance_id: &str,
86-
schedule_frequency: &str,
87-
period_id: i32,
88-
schedule_week_days: Option<Vec<String>>,
89-
) -> Value {
90-
let mut payload = serde_json::json!({
91-
"instanceId": instance_id,
92-
"scheduleFrequency": schedule_frequency,
93-
"periodId": period_id
94-
});
95-
96-
if let Some(days) = schedule_week_days {
97-
payload["scheduleWeekDays"] = Value::Array(days.into_iter().map(Value::String).collect());
98-
}
99-
100-
api_call(client, api_base_url, api_token, "PUT", "/v1/backups", Some(payload), None).await
101-
}
102-
103-
/// Delete backup profile
104-
pub async fn delete_backup_profile(
105-
client: &reqwest::Client,
106-
api_base_url: &str,
107-
api_token: &str,
108-
instance_id: &str,
109-
) -> Value {
110-
let endpoint = format!("/v1/backups/{}", instance_id);
111-
api_call(client, api_base_url, api_token, "DELETE", &endpoint, None, None).await
112-
}

src/api/floating_ips.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub struct FloatingIpView {
1010
pub instance_id: Option<String>,
1111
pub auto_renew: bool,
1212
pub customer_note: Option<String>,
13-
pub created_at: Option<i64>,
1413
}
1514

1615
/// Paginated result structure for floating IPs
@@ -55,7 +54,6 @@ pub async fn load_floating_ips(
5554
instance_id: obj.get("instanceId").and_then(|v| v.as_str()).map(|s| s.to_string()),
5655
auto_renew: obj.get("autoRenew").and_then(|v| v.as_bool()).unwrap_or(false),
5756
customer_note: obj.get("customerNote").and_then(|v| v.as_str()).map(|s| s.to_string()),
58-
created_at: obj.get("createdAt").and_then(|v| v.as_i64()),
5957
});
6058
}
6159
}

src/api/images.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,17 @@ use serde_json::Value;
44
/// Image view structure
55
#[derive(Clone, Debug)]
66
pub struct ImageView {
7-
pub id: String,
87
pub name: String,
9-
pub url: String,
108
pub status: String,
119
pub region_id: String,
1210
pub format: Option<String>,
13-
pub decompress: Option<String>,
14-
pub created_at: Option<i64>,
1511
}
1612

1713
/// Paginated result structure for images
1814
#[derive(Clone, Debug)]
1915
pub struct PaginatedImages {
2016
pub images: Vec<ImageView>,
2117
pub total_count: usize,
22-
pub current_page: usize,
23-
pub total_pages: usize,
24-
pub per_page: usize,
2518
}
2619

2720
/// Load images from the API
@@ -50,14 +43,10 @@ pub async fn load_images(
5043
for item in arr {
5144
if let Some(obj) = item.as_object() {
5245
images.push(ImageView {
53-
id: obj.get("id").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5446
name: obj.get("name").and_then(|v| v.as_str()).unwrap_or("").to_string(),
55-
url: obj.get("url").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5647
status: obj.get("status").and_then(|v| v.as_str()).unwrap_or("UNKNOWN").to_string(),
5748
region_id: obj.get("regionId").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5849
format: obj.get("format").and_then(|v| v.as_str()).map(|s| s.to_string()),
59-
decompress: obj.get("decompress").and_then(|v| v.as_str()).map(|s| s.to_string()),
60-
created_at: obj.get("createdAt").and_then(|v| v.as_i64()),
6150
});
6251
}
6352
}
@@ -68,15 +57,10 @@ pub async fn load_images(
6857
}
6958

7059
let actual_total = if total_count > 0 { total_count } else { images.len() };
71-
let total_pages = if per_page > 0 { actual_total.div_ceil(per_page) } else { 1 };
72-
let current_page = if page >= 1 { page } else { 1 };
7360

7461
PaginatedImages {
7562
images,
7663
total_count: actual_total,
77-
current_page,
78-
total_pages,
79-
per_page,
8064
}
8165
}
8266

@@ -108,24 +92,3 @@ pub async fn download_image(
10892
api_call(client, api_base_url, api_token, "POST", "/v1/images", Some(payload), None).await
10993
}
11094

111-
/// Get image details
112-
pub async fn get_image(
113-
client: &reqwest::Client,
114-
api_base_url: &str,
115-
api_token: &str,
116-
image_id: &str,
117-
) -> Value {
118-
let endpoint = format!("/v1/images/{}", image_id);
119-
api_call(client, api_base_url, api_token, "GET", &endpoint, None, None).await
120-
}
121-
122-
/// Delete an image
123-
pub async fn delete_image(
124-
client: &reqwest::Client,
125-
api_base_url: &str,
126-
api_token: &str,
127-
image_id: &str,
128-
) -> Value {
129-
let endpoint = format!("/v1/images/{}", image_id);
130-
api_call(client, api_base_url, api_token, "DELETE", &endpoint, None, None).await
131-
}

src/api/iso.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@ use serde_json::Value;
44
/// ISO view structure
55
#[derive(Clone, Debug)]
66
pub struct IsoView {
7-
pub id: String,
87
pub name: String,
9-
pub url: String,
108
pub status: String,
119
pub region_id: String,
1210
pub use_virtio: bool,
13-
pub created_at: Option<i64>,
1411
}
1512

1613
/// Paginated result structure for ISOs
1714
#[derive(Clone, Debug)]
1815
pub struct PaginatedIsos {
1916
pub isos: Vec<IsoView>,
2017
pub total_count: usize,
21-
pub current_page: usize,
22-
pub total_pages: usize,
23-
pub per_page: usize,
2418
}
2519

2620
/// Load ISOs from the API
@@ -49,13 +43,10 @@ pub async fn load_isos(
4943
for item in arr {
5044
if let Some(obj) = item.as_object() {
5145
isos.push(IsoView {
52-
id: obj.get("id").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5346
name: obj.get("name").and_then(|v| v.as_str()).unwrap_or("").to_string(),
54-
url: obj.get("url").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5547
status: obj.get("status").and_then(|v| v.as_str()).unwrap_or("UNKNOWN").to_string(),
5648
region_id: obj.get("regionId").and_then(|v| v.as_str()).unwrap_or("").to_string(),
5749
use_virtio: obj.get("useVirtio").and_then(|v| v.as_bool()).unwrap_or(true),
58-
created_at: obj.get("createdAt").and_then(|v| v.as_i64()),
5950
});
6051
}
6152
}
@@ -66,15 +57,10 @@ pub async fn load_isos(
6657
}
6758

6859
let actual_total = if total_count > 0 { total_count } else { isos.len() };
69-
let total_pages = if per_page > 0 { actual_total.div_ceil(per_page) } else { 1 };
70-
let current_page = if page >= 1 { page } else { 1 };
7160

7261
PaginatedIsos {
7362
isos,
7463
total_count: actual_total,
75-
current_page,
76-
total_pages,
77-
per_page,
7864
}
7965
}
8066

@@ -97,24 +83,3 @@ pub async fn download_iso(
9783
api_call(client, api_base_url, api_token, "POST", "/v1/iso", Some(payload), None).await
9884
}
9985

100-
/// Get ISO details
101-
pub async fn get_iso(
102-
client: &reqwest::Client,
103-
api_base_url: &str,
104-
api_token: &str,
105-
iso_id: &str,
106-
) -> Value {
107-
let endpoint = format!("/v1/iso/{}", iso_id);
108-
api_call(client, api_base_url, api_token, "GET", &endpoint, None, None).await
109-
}
110-
111-
/// Delete an ISO
112-
pub async fn delete_iso(
113-
client: &reqwest::Client,
114-
api_base_url: &str,
115-
api_token: &str,
116-
iso_id: &str,
117-
) -> Value {
118-
let endpoint = format!("/v1/iso/{}", iso_id);
119-
api_call(client, api_base_url, api_token, "DELETE", &endpoint, None, None).await
120-
}

src/api/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub use floating_ips::{
2828
load_floating_ips, create_floating_ips, update_floating_ip, release_floating_ip,
2929
FloatingIpView,
3030
};
31-
pub use iso::{load_isos, download_iso, get_iso, delete_iso, IsoView};
32-
pub use images::{load_images, download_image, get_image, delete_image, ImageView};
33-
pub use backups::{load_backups, get_backup_profile, create_backup_profile, update_backup_profile, delete_backup_profile, BackupProfileView};
31+
pub use iso::{load_isos, download_iso, IsoView};
32+
pub use images::{load_images, download_image, ImageView};
33+
pub use backups::{load_backups, create_backup_profile, BackupProfileView};

src/api/products.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,36 +104,26 @@ pub async fn load_products(
104104
}
105105

106106
// Build display fields for templates
107-
let name = id.clone();
108-
let display_name = name.clone();
109107
let description = "".to_string(); // Not in OpenAPI schema
110108
let tags = "".to_string(); // Not in OpenAPI schema
111-
109+
112110
let mut spec_entries = Vec::new();
113-
let mut cpu = None;
114-
let mut ram = None;
115-
let mut storage = None;
116-
let mut bandwidth = None;
117111

118112
let spec = &plan.specification;
119113
if spec.cpu > 0.0 {
120114
let val = spec.cpu.to_string();
121-
cpu = Some(format!("{} vCPU", val));
122115
spec_entries.push(ProductEntry { term: "CPU".into(), value: format!("{} vCPU", val) });
123116
}
124117
if spec.ram > 0.0 {
125118
let val = spec.ram.to_string();
126-
ram = Some(format!("{} GB", val));
127119
spec_entries.push(ProductEntry { term: "RAM".into(), value: format!("{} GB", val) });
128120
}
129121
if spec.storage > 0.0 {
130122
let val = spec.storage.to_string();
131-
storage = Some(format!("{} GB", val));
132123
spec_entries.push(ProductEntry { term: "Storage".into(), value: format!("{} GB", val) });
133124
}
134125
if spec.bandwidth_in_tb > 0.0 {
135126
let val = spec.bandwidth_in_tb.to_string();
136-
bandwidth = Some(format!("{} TB", val));
137127
spec_entries.push(ProductEntry { term: "Bandwidth".into(), value: format!("{} TB", val) });
138128
}
139129

@@ -161,16 +151,10 @@ pub async fn load_products(
161151
overall_activeness,
162152
ddos_activeness,
163153
price_items,
164-
name,
165-
display_name,
166154
description,
167155
tags,
168156
spec_entries,
169157
price_entries,
170-
cpu,
171-
ram,
172-
storage,
173-
bandwidth,
174158
});
175159
}
176160
}

src/api/snapshots.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ pub struct SnapshotView {
99
pub size: Option<i64>,
1010
pub status: String,
1111
pub created_at: Option<i64>,
12-
pub last_restored_at: Option<i64>,
13-
pub is_instance_deleted: bool,
1412
pub instance_id: String,
15-
pub region_id: Option<String>,
1613
}
1714

1815
/// Paginated result structure for snapshots
@@ -62,10 +59,7 @@ pub async fn load_snapshots(
6259
size: obj.get("size").and_then(|v| v.as_i64()),
6360
status: obj.get("status").and_then(|v| v.as_str()).unwrap_or("").to_string(),
6461
created_at: obj.get("createdAt").and_then(|v| v.as_i64()),
65-
last_restored_at: obj.get("lastRestoredAt").and_then(|v| v.as_i64()),
66-
is_instance_deleted: obj.get("isInstanceDeleted").and_then(|v| v.as_bool()).unwrap_or(false),
6762
instance_id: obj.get("instanceId").and_then(|v| v.as_str()).unwrap_or("").to_string(),
68-
region_id: obj.get("regionId").and_then(|v| v.as_str()).map(|s| s.to_string()),
6963
});
7064
}
7165
}

src/handlers/images.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub async fn images_list_get(
6767
flash_messages,
6868
has_flash_messages,
6969
images: &paginated.images,
70-
current_page: paginated.current_page,
71-
total_pages: paginated.total_pages,
72-
per_page: paginated.per_page,
7370
total_count: paginated.total_count,
7471
},
7572
)

src/handlers/instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub async fn instance_detail(
113113
products
114114
.into_iter()
115115
.find(|p| p.id == pid)
116-
.map(|p| p.name)
116+
.map(|p| p.id.clone())
117117
.unwrap_or(pid.clone())
118118
} else {
119119
pid.clone()

src/handlers/iso.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub async fn isos_list_get(
6767
flash_messages,
6868
has_flash_messages,
6969
isos: &paginated.isos,
70-
current_page: paginated.current_page,
71-
total_pages: paginated.total_pages,
72-
per_page: paginated.per_page,
7370
total_count: paginated.total_count,
7471
},
7572
)

0 commit comments

Comments
 (0)