mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2025-10-09 00:47:19 +08:00
Cleanup method of giving cards
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user