chore: fix a few issues

This commit is contained in:
Nathan Lamy 2025-08-26 00:27:33 +02:00
parent 1b73fe2cbb
commit d6dc15b4a3
3 changed files with 13 additions and 7 deletions

View file

@ -107,7 +107,7 @@ pub async fn post_submittable_meals(
pub async fn post_selected_meals(
meals: &[Meal],
user_id: &str,
user_id: &i64,
config: &Settings,
) -> Result<(), Box<dyn std::error::Error>> {
let api_url = get_config(config, "api");

View file

@ -183,8 +183,14 @@ async fn process_job(
}
}
} else if job["type"] == 4 || job["type"] == 5 {
let user_id = job["user_id"].as_str().unwrap_or_default();
println!("Submitting meals for user: {}", user_id);
let user_id = job["user_id"].as_number().unwrap().as_i64().unwrap_or(-1);
if user_id == -1 {
eprintln!("Job does not contain a valid user ID.");
return Err(redis::RedisError::from((
redis::ErrorKind::InvalidClientConfig,
"Job missing valid user ID",
)));
}
// Authenticate (job data contains password and username)
let username = job["bj_username"].as_str().unwrap_or_default();
@ -212,7 +218,7 @@ async fn process_job(
if job["type"] == 5 {
// Set auth failed in Redis
let auth_key = format!("auth_success_{}", user_id);
con.set_ex(&auth_key, false, 300)?;
con.set_ex(&auth_key, "ERROR", 300)?;
}
eprintln!("Failed to login: {}", err);
return Err(redis::RedisError::from((
@ -273,7 +279,7 @@ async fn process_job(
let meals = meals.unwrap();
// Post selected meals to API
let res = post_selected_meals(&meals, user_id, config).await;
let res = post_selected_meals(&meals, &user_id, config).await;
if res.is_err() {
eprintln!("Failed to post selected meals: {}", res.unwrap_err());
return Err(redis::RedisError::from((
@ -285,7 +291,7 @@ async fn process_job(
} else if job["type"] == 5 {
// Set auth successful in Redis
let auth_key = format!("auth_success_{}", user_id);
con.set_ex(&auth_key, true, 300)?;
con.set_ex(&auth_key, "SUCCESS", 300)?;
}
} else {
// Authenticate

View file

@ -59,7 +59,7 @@ pub async fn login(
.collect();
if session_id.is_empty() {
return Err("Failed to get session ID".into());
return Err("Invalid credentials".into());
}
Ok(session_id.join("; "))