added menu item end
This commit is contained in:
@@ -22,6 +22,13 @@ pub struct ItemData{
|
|||||||
cholesterol_mg: Option<f32>
|
cholesterol_mg: Option<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
|
pub struct MenuItems {
|
||||||
|
net_id: String,
|
||||||
|
item_list: Vec<u32>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn week(item: Json<ItemData>) -> impl Responder {
|
pub async fn week(item: Json<ItemData>) -> impl Responder {
|
||||||
|
|
||||||
let item = item.into_inner();
|
let item = item.into_inner();
|
||||||
@@ -34,6 +41,19 @@ pub async fn week(item: Json<ItemData>) -> impl Responder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn week_meals(items: Json<MenuItems>) -> impl Responder {
|
||||||
|
let items = items.into_inner();
|
||||||
|
let netid = items.net_id.clone();
|
||||||
|
|
||||||
|
match add_menu_items(items) {
|
||||||
|
Ok(_) => HttpResponse::Ok(),
|
||||||
|
Err(e) => {
|
||||||
|
error!("Unable to add menu items to table {}: {}", netid, e);
|
||||||
|
HttpResponse::InternalServerError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn add_item(item: &ItemData) -> Result<()> {
|
fn add_item(item: &ItemData) -> Result<()> {
|
||||||
let conn = Connection::connect(ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR)? ;
|
let conn = Connection::connect(ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR)? ;
|
||||||
|
|
||||||
@@ -72,3 +92,33 @@ fn add_item(item: &ItemData) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn add_menu_items(items: MenuItems) -> Result<()> {
|
||||||
|
let conn = Connection::connect(ORACLE_USER,ORACLE_PASS, ORACLE_CON_STR)?;
|
||||||
|
|
||||||
|
let mut stmt = conn.statement(format!("insert into {} values (
|
||||||
|
:item_id,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
1)", items.net_id).as_str()).build()?;
|
||||||
|
|
||||||
|
for item in items.item_list {
|
||||||
|
stmt.execute_named(&[("item_id",&item)])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.commit()?;
|
||||||
|
conn.close()?;
|
||||||
|
info!("inserted menu items into week table {}", items.net_id);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
web::resource("/week_plan")
|
web::resource("/week_plan")
|
||||||
.route(web::post().to(api::week::week))
|
.route(web::post().to(api::week::week))
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/week_meals")
|
||||||
|
.route(web::post().to(api::week::week_meals))
|
||||||
|
)
|
||||||
.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