fix: last commit
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Andre Henriques 2023-07-02 18:08:41 +01:00
parent 99e8a25686
commit c249de3a82

View File

@ -282,22 +282,13 @@ fn add_animation_to_db(
* *
*/ */
#[get("/stop/<name>")] #[get("/stop/<name>")]
pub async fn stop_animation(name: &str, stop_sender: &State<ASender<String>>) -> String { pub async fn stop_animation(name: &str, action: &State<ASender<Action>>) -> String {
let r = stop_sender.lock().unwrap().send(name.to_string()); let r = action.lock().unwrap().send(Action::Stop(name.to_string()));
if r.is_err() || r.ok().is_none() { if r.is_err() || r.ok().is_none() {
return json!(ApiResponse { return get_error_message("Something went wrong");
code: 500,
message: "Something went wrong".to_string()
})
.to_string();
} }
json!(ApiResponse { create_message(200, "Configuration was successful")
code: 200,
message: "Configuration was successful".to_string()
})
.to_string()
} }
/** /**
@ -311,44 +302,18 @@ pub async fn start_animation(
action: &State<ASender<Action>>, action: &State<ASender<Action>>,
db: &State<DBPool>, db: &State<DBPool>,
) -> String { ) -> String {
println!("try to get animation!"); let animation = get_animation_or_string_error(name, db);
let animation = get_animation(name, db); if let Err(animation) = animation {
println!("{:?}!", animation); return animation;
if animation.is_err() || animation.as_ref().ok().is_none() {
return json!(ApiResponse {
code: 500,
message: format!("Probelms with the db: {:?}", animation.err()).to_string()
})
.to_string();
} }
let animation = animation.ok().unwrap();
if animation.is_none() {
return json!(ApiResponse {
code: 404,
message: "Animation not found".to_string()
})
.to_string();
}
let animation = animation.unwrap(); let animation = animation.unwrap();
let r = action.lock().unwrap().send(Action::Start(animation)); let r = action.lock().unwrap().send(Action::Start(animation));
if r.is_err() || r.as_ref().ok().is_none() { if r.is_err() || r.as_ref().ok().is_none() {
return json!(ApiResponse { return get_error_message("Probelms with the sender");
code: 500,
message: "Probelms with the sender".to_string()
})
.to_string();
} }
json!(ApiResponse { create_message(200, "Started animation")
code: 200,
message: "Started animation".to_string()
})
.to_string()
} }
/** /**
@ -359,56 +324,27 @@ pub async fn start_animation(
#[get("/clear/<name>")] #[get("/clear/<name>")]
pub async fn clear( pub async fn clear(
name: &str, name: &str,
start_sender: &State<ASender<Animation>>,
db: &State<DBPool>, db: &State<DBPool>,
action: &State<ASender<Action>>, action: &State<ASender<Action>>,
) -> String { ) -> String {
let r = action.lock().unwrap().send(Action::Clear); let action = lock().unwrap();
let r = action.send(Action::Clear);
if r.is_err() || r.ok().is_none() { if r.is_err() || r.ok().is_none() {
return json!(ApiResponse { return get_error_message("Something went wrong");
code: 500,
message: "Something went wrong".to_string()
})
.to_string();
} }
let animation = get_animation(name, db); let animation = get_animation_or_string_error(name, db);
if let Err(error) = animation {
if animation.is_err() || animation.as_ref().ok().is_none() { return error;
return json!(ApiResponse {
code: 500,
message: format!("Probelms with the db: {:?}", animation.err()).to_string()
})
.to_string();
} }
let animation = animation.ok().unwrap();
if animation.is_none() {
return json!(ApiResponse {
code: 404,
message: "Animation not found".to_string()
})
.to_string();
}
let animation = animation.unwrap(); let animation = animation.unwrap();
let r = start_sender.lock().unwrap().send(animation); let r = action.send(Action::Start(animation));
if r.is_err() || r.as_ref().ok().is_none() { if r.is_err() || r.as_ref().ok().is_none() {
return json!(ApiResponse { return get_error_message("Probelms with the db");
code: 500,
message: "Probelms with the db".to_string()
})
.to_string();
} }
json!(ApiResponse { create_message(200, "Started animation")
code: 200,
message: "Started animation".to_string()
})
.to_string()
} }
#[get("/clearall")] #[get("/clearall")]
@ -416,18 +352,10 @@ pub async fn clear_all(action: &State<ASender<Action>>) -> String {
let r = action.lock().unwrap().send(Action::Clear); let r = action.lock().unwrap().send(Action::Clear);
if r.is_err() || r.ok().is_none() { if r.is_err() || r.ok().is_none() {
return json!(ApiResponse { return get_error_message("Something went wrong");
code: 500,
message: "Something went wrong".to_string()
})
.to_string();
} }
json!(ApiResponse { create_message(200, "Cleared all the animations")
code: 200,
message: "Cleared all the animations".to_string()
})
.to_string()
} }
pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>, Box<dyn Error>> { pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>, Box<dyn Error>> {