week progress lookup and remove warnings
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use actix_web::{web::Path, Responder, HttpResponse, web::Json};
|
use actix_web::{web::Path, web::Json};
|
||||||
use oracle::Connection;
|
use oracle::Connection;
|
||||||
use log::error;
|
use log::error;
|
||||||
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use oracle::{Result, Connection};
|
use oracle::{Result, Connection};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use log::{info, error};
|
use log::error;
|
||||||
use actix_web::{web::Json};
|
use actix_web::{web::Json};
|
||||||
|
|
||||||
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use rand::{prelude::Rng, distributions::Alphanumeric };
|
|||||||
use oracle::{Connection, Error};
|
use oracle::{Connection, Error};
|
||||||
use log::{info, warn, error};
|
use log::{info, warn, error};
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
use actix_web::{web, Responder, HttpRequest, HttpMessage, HttpResponse, cookie};
|
use actix_web::{web, Responder, HttpRequest, HttpMessage, HttpResponse};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
use crate::config::{ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR};
|
||||||
|
|
||||||
@@ -41,7 +41,6 @@ pub async fn login(request: HttpRequest, body: web::Json<Entry>) -> impl Respond
|
|||||||
println!("{:?}", body);
|
println!("{:?}", body);
|
||||||
match authenticate(net_id, password) {
|
match authenticate(net_id, password) {
|
||||||
Some(user) => {
|
Some(user) => {
|
||||||
let id = Identity::login(&request.extensions(), net_id.into()).unwrap();
|
|
||||||
web::Json(user);
|
web::Json(user);
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
},
|
},
|
||||||
@@ -52,8 +51,7 @@ pub async fn login(request: HttpRequest, body: web::Json<Entry>) -> impl Respond
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn logout(user: Identity) -> impl Responder {
|
pub async fn logout() -> impl Responder {
|
||||||
user.logout();
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use actix_web::{self, Responder, web::Json, HttpResponse};
|
use actix_web::{self, Responder, web::{Json, Path}, HttpResponse};
|
||||||
use oracle::{Connection, Result};
|
use oracle::{Connection, Result};
|
||||||
use crate::config::{ORACLE_PASS, ORACLE_USER, ORACLE_CON_STR};
|
use crate::config::{ORACLE_PASS, ORACLE_USER, ORACLE_CON_STR};
|
||||||
|
|
||||||
@@ -28,6 +28,28 @@ pub struct MenuItems {
|
|||||||
item_list: Vec<u32>
|
item_list: Vec<u32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
|
pub struct WeekData{
|
||||||
|
week: Vec<ItemResult>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
|
pub struct ItemResult{
|
||||||
|
item_id: Option<u32>,
|
||||||
|
amount: Option<u32>,
|
||||||
|
item_name: Option<String>,
|
||||||
|
calories: Option<f32>,
|
||||||
|
fat_g: Option<f32>,
|
||||||
|
sat_fat_g: Option<f32>,
|
||||||
|
trans_fat_g: Option<f32>,
|
||||||
|
carbs_g: Option<f32>,
|
||||||
|
fiber_g: Option<f32>,
|
||||||
|
sugar_g: Option<f32>,
|
||||||
|
protein_g: Option<f32>,
|
||||||
|
sodium_mg: Option<f32>,
|
||||||
|
potassium_mg: Option<f32>,
|
||||||
|
cholesterol_mg: Option<f32>
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn week(item: Json<ItemData>) -> impl Responder {
|
pub async fn week(item: Json<ItemData>) -> impl Responder {
|
||||||
|
|
||||||
@@ -54,6 +76,21 @@ pub async fn week_meals(items: Json<MenuItems>) -> impl Responder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn week_lookup(net_id: Path<String>) -> Json<WeekData> {
|
||||||
|
|
||||||
|
let net_id = net_id.into_inner();
|
||||||
|
|
||||||
|
match get_week(&net_id) {
|
||||||
|
Ok(week) => Json(week),
|
||||||
|
Err(e) => {
|
||||||
|
error!("failed to grab week info from {}: {}", net_id, e);
|
||||||
|
Json(WeekData::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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)? ;
|
||||||
|
|
||||||
@@ -123,3 +160,36 @@ fn add_menu_items(items: MenuItems) -> Result<()> {
|
|||||||
info!("inserted menu items into week table {}", items.net_id);
|
info!("inserted menu items into week table {}", items.net_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn get_week(net_id: &str) -> Result<WeekData> {
|
||||||
|
|
||||||
|
let conn = Connection::connect(ORACLE_USER, ORACLE_PASS, ORACLE_CON_STR)?;
|
||||||
|
let mut stmt = conn.statement(format!("select * from {}", net_id).as_str()).build()?;
|
||||||
|
|
||||||
|
let rows = stmt.query(&[])?;
|
||||||
|
let mut week = WeekData::default();
|
||||||
|
|
||||||
|
for row_result in rows {
|
||||||
|
let row = row_result?;
|
||||||
|
week.week.push( ItemResult {
|
||||||
|
item_id: row.get(0).unwrap_or(None),
|
||||||
|
amount: row.get(1).unwrap_or(None),
|
||||||
|
item_name: row.get(2).unwrap_or(None),
|
||||||
|
calories: row.get(3).unwrap_or(None),
|
||||||
|
fat_g: row.get(4).unwrap_or(None),
|
||||||
|
sat_fat_g: row.get(5).unwrap_or(None),
|
||||||
|
trans_fat_g: row.get(6).unwrap_or(None),
|
||||||
|
carbs_g: row.get(7).unwrap_or(None),
|
||||||
|
fiber_g: row.get(8).unwrap_or(None),
|
||||||
|
sugar_g: row.get(9).unwrap_or(None),
|
||||||
|
protein_g: row.get(10).unwrap_or(None),
|
||||||
|
sodium_mg: row.get(11).unwrap_or(None),
|
||||||
|
potassium_mg: row.get(12).unwrap_or(None),
|
||||||
|
cholesterol_mg: row.get(13).unwrap_or(None) });
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(week)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
web::resource("/week_meals")
|
web::resource("/week_meals")
|
||||||
.route(web::post().to(api::week::week_meals))
|
.route(web::post().to(api::week::week_meals))
|
||||||
)
|
)
|
||||||
/* .service(
|
.service(
|
||||||
web::resource("/week_progress/{net_id}")
|
web::resource("/week_progress/{net_id}")
|
||||||
.route(web::get().to(api::week::week_lookup))
|
.route(web::get().to(api::week::week_lookup))
|
||||||
) */
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/menu_search")
|
web::resource("/menu_search")
|
||||||
.route(web::post().to(api::menu::menu_search))
|
.route(web::post().to(api::menu::menu_search))
|
||||||
|
|||||||
Reference in New Issue
Block a user