diff --git a/src/animations.rs b/src/animations.rs index 2996d8a..7c492fd 100644 --- a/src/animations.rs +++ b/src/animations.rs @@ -100,6 +100,7 @@ impl Animation { } } +// Add animation #[post("/animation", data = "")] pub async fn animation(data: Json, db: &State) -> String { if data.key_frames.is_empty() { @@ -454,14 +455,10 @@ pub fn get_animation(name: &str, db: &State) -> Result })? .next(); - println!("got here 1"); - if next.is_none() { return Ok(None); } - println!("got here 2"); - let mut animation = next.unwrap()?; struct KeyFrameId { @@ -472,8 +469,6 @@ pub fn get_animation(name: &str, db: &State) -> Result let mut stmt = conn.prepare("SELECT id, duration from keyframe where animation=?1 order by i asc")?; - println!("got here 3"); - let mut map = stmt.query_map([animation.id], |row| { Ok(KeyFrameId { id: row.get(0)?, @@ -592,3 +587,33 @@ pub async fn get_active( }) .to_string(); } + +/** + * + * get animation + * + */ +#[get("/get/")] +pub async fn get_animation_request(name: &str, db: &State) -> String { + let animation = get_animation(name, db); + + if animation.is_err() { + return json!(ApiResponse { + code: 500, + message: "Failed to get animation".to_string() + }) + .to_string(); + } + + let animation = animation.ok(); + + if let Some(animation) = animation { + return json!(animation).to_string(); + } else { + return json!(ApiResponse { + code: 500, + message: "Animation not found".to_string() + }) + .to_string(); + } +} diff --git a/src/main.rs b/src/main.rs index 7fd3602..ba3194e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -224,6 +224,7 @@ async fn main() -> GResult { animations::clear, animations::delete, animations::clear_all, + animations::get_animation_request, ], ) .manage(conn_pool_arc.clone())