From dc8064b90dea2378bb2ddc56dc6542fc96ed04ed Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Sun, 2 Jul 2023 11:10:16 +0100 Subject: [PATCH] chore: added endpoint to get animation --- src/animations.rs | 37 +++++++++++++++++++++++++++++++------ src/main.rs | 1 + 2 files changed, 32 insertions(+), 6 deletions(-) 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())