Cleanup method of giving cards

This commit is contained in:
Ethan O'Brien
2024-02-28 12:41:55 -06:00
parent c787bec84e
commit ca220a14db
3 changed files with 55 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
use json::JsonValue;
use json::{object, JsonValue};
use crate::encryption;
use actix_web::{
HttpResponse
@@ -23,3 +23,29 @@ pub fn send(data: JsonValue) -> HttpResponse {
HttpResponse::Ok().body(resp)
}
pub fn error_resp() -> HttpResponse {
send(object!{})
}
// true - added
// false - already has
pub fn give_character(id: String, user: &mut JsonValue) -> bool {
for (_i, data) in user["card_list"].members().enumerate() {
if data["master_card_id"].to_string() == id {
return false;
}
}
let to_push = object!{
"id": id.clone(),
"master_card_id": id,
"exp": 0,
"skill_exp": 0,
"evolve": [],
"created_date_time": timestamp()
};
user["card_list"].push(to_push.clone()).unwrap();
true
}