Organize databases

This commit is contained in:
Ethan O'Brien
2024-05-09 16:39:31 -05:00
parent 248979f2cb
commit 98aed96701
33 changed files with 240 additions and 314 deletions

View File

@@ -1,25 +1,9 @@
use json::{object, JsonValue};
use json::object;
use actix_web::{HttpResponse, HttpRequest};
use lazy_static::lazy_static;
use crate::router::{userdata, global, items};
use crate::router::{userdata, global, items, databases};
use crate::encryption;
lazy_static! {
static ref SHOP_INFO: JsonValue = {
let mut info = object!{};
let items = json::parse(include_str!("json/shop_item.json")).unwrap();
for (_i, data) in items.members().enumerate() {
info[data["id"].to_string()] = data.clone();
}
info
};
}
fn get_item_info(id: i64) -> JsonValue {
SHOP_INFO[id.to_string()].clone()
}
pub fn shop(req: HttpRequest) -> HttpResponse {
let key = global::get_login(req.headers(), "");
let user = userdata::get_acc(&key);
@@ -40,7 +24,7 @@ pub fn buy(req: HttpRequest, body: String) -> HttpResponse {
let mut user = userdata::get_acc(&key);
let user_home = userdata::get_acc_home(&key);
let item = get_item_info(body["master_shop_item_id"].as_i64().unwrap());
let item = &databases::SHOP_INFO[body["master_shop_item_id"].to_string()];
items::remove_gems(&mut user, item["price"].as_i64().unwrap());
items::give_shop(item["masterShopRewardId"].as_i64().unwrap(), item["price"].as_i64().unwrap(), &mut user);