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