diff --git a/backend/src/api/eatery.rs b/backend/src/api/eatery.rs new file mode 100644 index 0000000..4012fc0 --- /dev/null +++ b/backend/src/api/eatery.rs @@ -0,0 +1,52 @@ +use serde::{Serialize, Deserialize}; +use actix_web::{web::Path, Responder, HttpResponse}; +use oracle::{Connection, Error}; +use log::{error}; + +const ORACLE_USER: &str = "timmy"; +const ORACLE_PASS: &str = "timmy"; + +#[derive(Serialize, Deserialize, Debug, Default)] +struct food_item { + item_id: u32, + eatery_id: u32, + item_name: String, + serving_size: f32, + calories: f32, + fat: f32, + sat_fat: f32, + trans_fat: f32, + carbs: f32, + fiber: f32, + sugar: f32, + protein: f32, + sodium: f32, + potassium: f32, + cholesterol: f32 +} + + +pub fn menu(eatery: Path) -> impl Responder { + let eatery = eatery.into_inner(); + let conn = match Connection::connect(ORACLE_USER, ORACLE_PASS, "") { + Ok(c) => c, + Err(e) => { + error!("Unable to reach oracle server: {}", e); + return HttpResponse::InternalServerError(); + } + }; + + let mut stmt = match conn.statement("select * from menu_item natural join nutrition_info food where menu_item.eatery_id = :1").build() { + Ok(s) => s, + Err(e) => { + error!("Unable to build statement: {}", e); + return HttpResponse::InternalServerError(); + } + }; + + + let rows = stmt.query(&[&eatery]).unwrap().collect(); + println!("{}", rows); + HttpResponse::Ok() + +} diff --git a/backend/src/api/mod.rs b/backend/src/api/mod.rs index 34b2ad4..80bcc35 100644 --- a/backend/src/api/mod.rs +++ b/backend/src/api/mod.rs @@ -1,2 +1,3 @@ pub mod user; +pub mod eatery; diff --git a/backend/src/api/user.rs b/backend/src/api/user.rs index 81d1057..0cffdee 100644 --- a/backend/src/api/user.rs +++ b/backend/src/api/user.rs @@ -156,7 +156,7 @@ fn create_user(username: &str, password: &str, first_name: &str, last_name: &str } }; - let mut new_table = conn.statement("create table week_:netid ( item_id number(5), foreign key (item_id) references menu_item (id))").build()?; + let mut new_table = conn.statement("create table :net_id ( item_id number(5), foreign key (item_id) references menu_item (id))").build()?; match new_table.execute_named(&[("net_id", &username)]) { Ok(_) => { diff --git a/backend/src/main.rs b/backend/src/main.rs index ef0f741..169b24c 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -50,6 +50,10 @@ async fn main() -> std::io::Result<()> { web::resource("/signup") .route(web::post().to(api::user::signup)) ) + .service( + web::resource("/eatery/{eatery_id}") + .route(web::get().to(api::eatery::menu)) + ) .route("/", web::get().to(api_index)) ) .route("/", web::get().to(index))