chore: added endpoint to get animation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andre Henriques 2023-07-02 11:10:16 +01:00
parent a4c913eedc
commit dc8064b90d
2 changed files with 32 additions and 6 deletions

View File

@ -100,6 +100,7 @@ impl Animation {
} }
} }
// Add animation
#[post("/animation", data = "<data>")] #[post("/animation", data = "<data>")]
pub async fn animation(data: Json<Animation>, db: &State<DBPool>) -> String { pub async fn animation(data: Json<Animation>, db: &State<DBPool>) -> String {
if data.key_frames.is_empty() { if data.key_frames.is_empty() {
@ -454,14 +455,10 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
})? })?
.next(); .next();
println!("got here 1");
if next.is_none() { if next.is_none() {
return Ok(None); return Ok(None);
} }
println!("got here 2");
let mut animation = next.unwrap()?; let mut animation = next.unwrap()?;
struct KeyFrameId { struct KeyFrameId {
@ -472,8 +469,6 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
let mut stmt = let mut stmt =
conn.prepare("SELECT id, duration from keyframe where animation=?1 order by i asc")?; 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| { let mut map = stmt.query_map([animation.id], |row| {
Ok(KeyFrameId { Ok(KeyFrameId {
id: row.get(0)?, id: row.get(0)?,
@ -592,3 +587,33 @@ pub async fn get_active(
}) })
.to_string(); .to_string();
} }
/**
*
* get animation
*
*/
#[get("/get/<name>")]
pub async fn get_animation_request(name: &str, db: &State<DBPool>) -> 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();
}
}

View File

@ -224,6 +224,7 @@ async fn main() -> GResult {
animations::clear, animations::clear,
animations::delete, animations::delete,
animations::clear_all, animations::clear_all,
animations::get_animation_request,
], ],
) )
.manage(conn_pool_arc.clone()) .manage(conn_pool_arc.clone())