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>")]
pub async fn animation(data: Json<Animation>, db: &State<DBPool>) -> String {
if data.key_frames.is_empty() {
@ -454,14 +455,10 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
})?
.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<DBPool>) -> Result<Option<Animation>
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/<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::delete,
animations::clear_all,
animations::get_animation_request,
],
)
.manage(conn_pool_arc.clone())