adding menu items
This commit is contained in:
52
backend/src/api/eatery.rs
Normal file
52
backend/src/api/eatery.rs
Normal file
@@ -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<String>) -> 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()
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod eatery;
|
||||||
|
|
||||||
|
|||||||
@@ -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)]) {
|
match new_table.execute_named(&[("net_id", &username)]) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
web::resource("/signup")
|
web::resource("/signup")
|
||||||
.route(web::post().to(api::user::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(api_index))
|
||||||
)
|
)
|
||||||
.route("/", web::get().to(index))
|
.route("/", web::get().to(index))
|
||||||
|
|||||||
Reference in New Issue
Block a user