chore: fix a few issues
This commit is contained in:
		
							parent
							
								
									1b73fe2cbb
								
							
						
					
					
						commit
						d6dc15b4a3
					
				
					 3 changed files with 13 additions and 7 deletions
				
			
		|  | @ -107,7 +107,7 @@ pub async fn post_submittable_meals( | ||||||
| 
 | 
 | ||||||
| pub async fn post_selected_meals( | pub async fn post_selected_meals( | ||||||
|     meals: &[Meal], |     meals: &[Meal], | ||||||
|     user_id: &str, |     user_id: &i64, | ||||||
|     config: &Settings, |     config: &Settings, | ||||||
| ) -> Result<(), Box<dyn std::error::Error>> { | ) -> Result<(), Box<dyn std::error::Error>> { | ||||||
|     let api_url = get_config(config, "api"); |     let api_url = get_config(config, "api"); | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -183,8 +183,14 @@ async fn process_job( | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } else if job["type"] == 4 || job["type"] == 5 { |     } else if job["type"] == 4 || job["type"] == 5 { | ||||||
|         let user_id = job["user_id"].as_str().unwrap_or_default(); |         let user_id = job["user_id"].as_number().unwrap().as_i64().unwrap_or(-1); | ||||||
|         println!("Submitting meals for user: {}", user_id); |         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)
 |         // Authenticate (job data contains password and username)
 | ||||||
|         let username = job["bj_username"].as_str().unwrap_or_default(); |         let username = job["bj_username"].as_str().unwrap_or_default(); | ||||||
|  | @ -212,7 +218,7 @@ async fn process_job( | ||||||
|             if job["type"] == 5 { |             if job["type"] == 5 { | ||||||
|                 // Set auth failed in Redis
 |                 // Set auth failed in Redis
 | ||||||
|                 let auth_key = format!("auth_success_{}", user_id); |                 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); |             eprintln!("Failed to login: {}", err); | ||||||
|             return Err(redis::RedisError::from(( |             return Err(redis::RedisError::from(( | ||||||
|  | @ -273,7 +279,7 @@ async fn process_job( | ||||||
|             let meals = meals.unwrap(); |             let meals = meals.unwrap(); | ||||||
| 
 | 
 | ||||||
|             // Post selected meals to API
 |             // 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() { |             if res.is_err() { | ||||||
|                 eprintln!("Failed to post selected meals: {}", res.unwrap_err()); |                 eprintln!("Failed to post selected meals: {}", res.unwrap_err()); | ||||||
|                 return Err(redis::RedisError::from(( |                 return Err(redis::RedisError::from(( | ||||||
|  | @ -285,7 +291,7 @@ async fn process_job( | ||||||
|         } else if job["type"] == 5 { |         } else if job["type"] == 5 { | ||||||
|             // Set auth successful in Redis
 |             // Set auth successful in Redis
 | ||||||
|             let auth_key = format!("auth_success_{}", user_id); |             let auth_key = format!("auth_success_{}", user_id); | ||||||
|             con.set_ex(&auth_key, true, 300)?; |             con.set_ex(&auth_key, "SUCCESS", 300)?; | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         // Authenticate
 |         // Authenticate
 | ||||||
|  |  | ||||||
|  | @ -59,7 +59,7 @@ pub async fn login( | ||||||
|         .collect(); |         .collect(); | ||||||
| 
 | 
 | ||||||
|     if session_id.is_empty() { |     if session_id.is_empty() { | ||||||
|         return Err("Failed to get session ID".into()); |         return Err("Invalid credentials".into()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Ok(session_id.join("; ")) |     Ok(session_id.join("; ")) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Nathan Lamy
						Nathan Lamy