WIP: dummy data for routes

This commit is contained in:
Will Galebach 2024-01-24 18:35:45 +00:00
parent 13a7d31fd8
commit c1cc7102ed

View File

@ -224,21 +224,54 @@ fn handle_http_request(
"/apps" => {
match method.as_str() {
"GET" => {
// Return a list of fake apps
// TODO: Return a list of the user's apps
(StatusCode::OK, None, serde_json::to_vec(&vec![
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "Chess".to_string(),
icon: "".to_string(),
package_name: "chess".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "File Transfer".to_string(),
icon: "".to_string(),
package_name: "file_transfer".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
])?)
},
"POST" => {
// Add an app
(StatusCode::CREATED, None, format!("Installed").into_bytes())
},
_ => (StatusCode::METHOD_NOT_ALLOWED, None, format!("Invalid method {} for {}", method, path).into_bytes())
}
},
"/apps/:id" => {
let Some(app_id) = path.split("/").last() else {
return Err(anyhow::anyhow!("No app ID"));
};
match method.as_str() {
"PUT" => {
// Update an app
(StatusCode::NO_CONTENT, None, format!("Updated").into_bytes())
},
"DELETE" => {
// Uninstall an app
(StatusCode::NO_CONTENT, None, format!("Uninstalled").into_bytes())
},
_ => (StatusCode::METHOD_NOT_ALLOWED, None, format!("Invalid method {} for {}", method, path).into_bytes())
}
@ -247,6 +280,32 @@ fn handle_http_request(
match method.as_str() {
"GET" => {
// Return a list of latest apps
(StatusCode::OK, None, serde_json::to_vec(&vec![
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "Remote".to_string(),
icon: "".to_string(),
package_name: "remote".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "Happy Path".to_string(),
icon: "".to_string(),
package_name: "happy_path".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
])?)
},
_ => (StatusCode::METHOD_NOT_ALLOWED, None, format!("Invalid method {} for {}", method, path).into_bytes())
}
@ -254,8 +313,37 @@ fn handle_http_request(
"/apps/search/:query" => {
match method.as_str() {
"GET" => {
let Some(query) = path.split("/").last() else {
return Err(anyhow::anyhow!("No query"));
};
// Return a list of apps matching the query
// Query by name, publisher, package_name, description, website
(StatusCode::OK, None, serde_json::to_vec(&vec![
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "Winch".to_string(),
icon: "".to_string(),
package_name: "winch".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
PackageListing {
owner: our.node.clone(),
publisher: our.node.clone(),
name: "Bucket".to_string(),
icon: "".to_string(),
package_name: "bucket".to_string(),
description: Some("A test app".to_string()),
website: Some("https://example.com".to_string()),
rating: 3.0,
versions: HashMap::new(),
mirrors: vec![],
},
])?)
},
_ => (StatusCode::METHOD_NOT_ALLOWED, None, format!("Invalid method {} for {}", method, path).into_bytes())
}