chore: apps_services & cleanup

This commit is contained in:
Jesús Pérez Lorenzo 2021-10-09 00:59:41 +01:00
parent d4f5bbce45
commit 8a9fa96599
2 changed files with 15 additions and 92 deletions

View File

@ -7,8 +7,8 @@ use warp::{
};
use reqenv::ReqEnv;
/*
use crate::topographic_anatomy::defs::{TaStore,TaData,TaQueryFilters,TopographicAnatomy};
use zterton::kloud::utils::{lng_t,get_lang_items_str,load_lang};
use crate::app_profile::defs::{PrflStore,PrflData,PrflQueryFilters,Profile};
use defs::kloud::utils::{lng_t,get_lang_items_str,load_lang};
//use zterton::models::{AppStore, AppData};
use crate::defs::AppDB;
@ -23,9 +23,6 @@ use crate::auth::defs::{
custom_reject
};
*/
// use ::topographic_anatomy::{TopographicAnatomy};
// use ::tracking_point::{TrackingPoint};
// use crate::tracking_point::defs::{TrackingPoint};
//use app_auth::{UserCtx};
use kloud::{
defs::{
@ -62,7 +59,7 @@ pub async fn table(
} else {
app_ctx = "";
}
let lang_items = serde_json::to_string(&LangItems::new("langs/ta","es","yaml"))
let lang_items = serde_json::to_string(&LangItems::new("langs/prfl","es","yaml"))
.unwrap_or_else(|_| String::from(""));
let mut data_hash: HashMap<String, String> = HashMap::new();
data_hash.insert("lang".to_string(), lang.to_owned());
@ -145,7 +142,7 @@ pub async fn list(
// println!("User: {} | {}",&user.user_id,&user.token);
// println!("LANG: {}",language);
// if prfx.as_str() == "ta" {
// if prfx.as_str() == "prfl" {
// let cur = db.colls.ta.entries.read();
// }
// let allow_origin = reqenv.websrvr().allow_origin;
@ -153,9 +150,9 @@ pub async fn list(
Ok(_auth) => {
// dbg!("auth: {}",&auth);
match prfx.as_str() {
"ta" => {
"prfl" => {
/* let data = CollsData::get_ta_entries(db.colls.clone()).await;
let data_out: Vec<TopographicAnatomy> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let data_out: Vec<Profile> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
@ -178,32 +175,6 @@ pub async fn list(
// Ok(warp::reply::json(&result))
*/
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
/* let data = CollsData::get_tp_entries(db.colls.clone()).await;
let data_out: Vec<TrackingPoint> = data.iter().enumerate().filter(|(idx,(itm,_))|{
let mut skip = false;
if !opts.id.is_empty() && !itm.contains(&opts.id) { skip = true; }
if opts.start > 0 && idx < &(opts.start as usize) { skip = true; }
if opts.end > 0 && idx > &(opts.end as usize) { skip = true; }
!skip
}).map(|(_,(_,value))| value).cloned().collect();
*/
let data_out: Vec<String> = Vec::new();
let result = serde_json::to_string(&data_out).unwrap_or_else(|_| String::from(""));
Ok(warp::http::Response::builder()
.body(result.to_string())
.into_response())
/*
Ok(warp::reply::with_header(
// warp::reply::json(&CollsData::get_tp_entries(db.colls.clone()).await),
warp::http::Response::new(result),
// warp::http::Response::new(body),
"Access-Control-Allow-Origin",
&allow_origin))
// Ok(warp::reply::json(&result))
*/
},
_ => {
//let result="";
let result = format!("list for '{}' undefined",&prfx);
@ -260,7 +231,7 @@ pub async fn list(
}
// warp::generic::Either<(std::string::String,), (std::string::String,)>
// pub async fn create(
// create: TopographicAnatomy,
// create: Profile,
// db: DataDBs,
// prfx: String,
// ) -> Result<impl Reply, Rejection> {
@ -298,8 +269,8 @@ pub async fn insert(
// dbg!("auth: {}",&auth);
/*
match prfx.as_str() {
"ta" => {
match serde_json::from_str::<TopographicAnatomy>(&data.str_data) {
"prfl" => {
match serde_json::from_str::<Profile>(&data.str_data) {
Ok(item) => {
if db.colls.ta.entries.read().contains_key(&data.id) {
if data.id != item.id {
@ -333,32 +304,6 @@ pub async fn insert(
}
}
},
"tp" => {
// let result = CollsData::get_tp_entries(db.colls.clone()).await;
match serde_json::from_str::<TrackingPoint>(&data.str_data) {
Ok(item) => {
if db.colls.tp.entries.read().contains_key(&data.id) {
db.colls.tp.entries.write().insert(item.id.to_owned(), item.to_owned());
println!("UPDATED tracking_point id: {}",&item.id);
result = format!("UPDATED: {}",&item.id);
} else {
db.colls.tp.entries.write().insert(item.id.to_owned(), item.to_owned());
println!("CREATED tracking_point id: {}",&item.id);
result = format!("CREATED: {}",&item.id);
}
},
Err(e) => {
println!("Error {} parse insert : {}",&prfx,e);
result = format!("ERROR: {} parse insert: '{}'",&prfx,e);
}
}
},
_ => {
result = format!("ERROR: list for '{}' undefined",&prfx);
// (AuthError::UserNotFoundError.to_string())
println!("{}",&result);
}
};
*/
},
Err(e) => {
@ -394,7 +339,7 @@ pub async fn delete(
// dbg!("auth: {}",&auth);
/*
match prfx.as_str() {
"ta" => {
"prfl" => {
if db.colls.ta.entries.read().contains_key(&data.id) {
db.colls.ta.entries.write().remove(&data.id);
if db.colls.ta.entries.read().contains_key(&data.id) {
@ -408,26 +353,6 @@ pub async fn delete(
result = format!("ERROR: topographic_anatomy NOT found: '{}'",&data.id);
}
},
"tp" => {
if db.colls.tp.entries.read().contains_key(&data.id) {
db.colls.tp.entries.write().remove(&data.id);
if db.colls.tp.entries.read().contains_key(&data.id) {
println!("NOT DELETED tracking_point id: {}",&data.id);
result = format!("ERROR: tracking_point NOT deleted: '{}'",&data.id);
} else {
println!("DELETED tracking_point id: {}",&data.id);
result = format!("DELETED: tracking_point: '{}'",&data.id);
}
} else {
result = format!("ERROR: topographic_anatomy NOT found: '{}'",&data.id);
}
},
_ => {
result = format!("ERROR: list for '{}' undefined",&prfx);
// (AuthError::UserNotFoundError.to_string())
println!("{}",&result);
}
};
*/
},
Err(e) => {

View File

@ -8,9 +8,9 @@ use warp::{
use reqenv::ReqEnv;
use app_env::profile::Profile;
/*
use crate::topographic_anatomy::defs::{TaStore,TaData,TaQueryFilters,TopographicAnatomy};
use zterton::kloud::utils::{lng_t,get_lang_items_str,load_lang};
//use zterton::models::{AppStore, AppData};
use crate::app_profile::defs::{TaStore,TaData,TaQueryFilters,Profile};
use defs::kloud::utils::{lng_t,get_lang_items_str,load_lang};
//use defs::app_env::{AppStore, AppData};
use crate::defs::AppDB;
use crate::auth::defs::{
@ -24,9 +24,7 @@ use crate::auth::defs::{
custom_reject
};
*/
// use ::topographic_anatomy::{TopographicAnatomy};
// use ::tracking_point::{TrackingPoint};
// use crate::tracking_point::defs::{TrackingPoint};
// use ::app_profile::{Profile};
//use app_auth::{UserCtx};
use kloud::{
defs::{
@ -65,7 +63,7 @@ pub async fn langs(
// dbg!("auth: {}",&auth);
let lang = opts.lang.unwrap_or_else(|| String::from("es"));
let section = opts.section.unwrap_or_else(|| String::from(""));
let lang_items = LangItems::new("langs/ta",&lang,"yaml");
let lang_items = LangItems::new("langs/prfl",&lang,"yaml");
let result = lang_items.get_items_str(&section);
Ok(warp::http::Response::builder()
.body(result.to_string())