refactor: handle macros code in tuono_lib crate

This commit is contained in:
Valerio Ageno
2024-06-15 12:15:51 +02:00
parent 8b4db423b4
commit 70b4b9c28f
8 changed files with 63 additions and 41 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
// src/routes/index.rs
use serde::{Deserialize, Serialize};
use tuono_lib::{Request, Response};
use tuono_lib::{Props, Request, Response};
const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";
@@ -20,8 +20,8 @@ async fn get_all_pokemons(_req: Request<'_>, fetch: reqwest::Client) -> Response
return match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
let data = res.json::<Pokemons>().await.unwrap();
Response::Props(Box::new(data))
Response::Props(Props::new(data))
}
Err(_err) => Response::Props(Box::new(Pokemons { results: vec![] })),
Err(_err) => Response::Props(Props::new(Pokemons { results: vec![] })),
};
}
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use tuono_lib::{Request, Response};
use tuono_lib::{Props, Request, Response};
const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";
@@ -19,9 +19,9 @@ async fn get_pokemon(req: Request<'_>, fetch: reqwest::Client) -> Response {
return match fetch.get(format!("{POKEMON_API}/{pokemon}")).send().await {
Ok(res) => {
let data = res.json::<Pokemon>().await.unwrap();
Response::Props(Box::new(data))
Response::Props(Props::new(data))
}
Err(_err) => Response::Props(Box::new(Pokemon {
Err(_err) => Response::Props(Props::new(Pokemon {
name: "Nope".to_string(),
id: 0,
weight: 0,