feat: create struct from json response and create a table view

This commit is contained in:
2026-05-03 16:55:23 +02:00
parent 58687643fb
commit 175f5459a8
5 changed files with 61 additions and 15 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn Error>> {
ui.on_request_text_input(|text| {
println!("User input: {}", text);
let response = rutracker::search(&text);
let _response = rutracker::search(&text);
});
ui.run()?;
+16
View File
@@ -1,5 +1,16 @@
use serde_derive::Deserialize;
use serde_derive::Serialize;
use serde_json::Value;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Software {
pub author: String,
pub leechers: String,
pub seeders: String,
pub title: String,
pub url: String,
}
#[tokio::main]
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
@@ -7,6 +18,11 @@ pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
let text = results.text().await?;
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
let data = &v["data"];
for item in data.as_array().unwrap() {
let software: Software =
serde_json::from_value(item.clone()).expect("Failed to deserialize");
println!("{:?}", software);
}
println!("{:?}", data);
Ok(v)
}