mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Verify card exists before pushing
This commit is contained in:
parent
893a6f1543
commit
8d2e0a0293
1 changed files with 9 additions and 7 deletions
|
@ -55,8 +55,8 @@ pub fn tutorial(_req: HttpRequest, body: String) -> HttpResponse {
|
||||||
global::send(resp)
|
global::send(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_card_master_id(lottery_id: String, lottery_number: String) -> i32 {
|
fn get_card_master_id(lottery_id: String, lottery_number: String) -> Option<i64> {
|
||||||
return CARDS[lottery_id][lottery_number]["value"].as_i32().unwrap();
|
CARDS[lottery_id][lottery_number]["value"].as_i64()
|
||||||
}
|
}
|
||||||
fn random_number(lowest: usize, highest: usize) -> usize {
|
fn random_number(lowest: usize, highest: usize) -> usize {
|
||||||
if lowest == highest {
|
if lowest == highest {
|
||||||
|
@ -77,14 +77,16 @@ fn get_random_cards(count: usize) -> JsonValue {
|
||||||
while i < count {
|
while i < count {
|
||||||
let pool = pools[random_number(0, pools.len()-1)].clone();
|
let pool = pools[random_number(0, pools.len()-1)].clone();
|
||||||
let card = random_number(0, pool[1].as_usize().unwrap());
|
let card = random_number(0, pool[1].as_usize().unwrap());
|
||||||
|
if !get_card_master_id(pool[0].to_string(), card.to_string()).is_none() {
|
||||||
random_master_ids.push(array![pool[0].clone(), card]).unwrap();
|
random_master_ids.push(array![pool[0].clone(), card]).unwrap();
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let mut rv = array![];
|
let mut rv = array![];
|
||||||
for (_i, data) in random_master_ids.members().enumerate() {
|
for (_i, data) in random_master_ids.members().enumerate() {
|
||||||
let to_push = object!{
|
let to_push = object!{
|
||||||
"id": get_card_master_id(data[0].to_string(), data[1].to_string()),
|
"id": get_card_master_id(data[0].to_string(), data[1].to_string()).unwrap(),
|
||||||
"master_card_id": get_card_master_id(data[0].to_string(), data[1].to_string()),
|
"master_card_id": get_card_master_id(data[0].to_string(), data[1].to_string()).unwrap(),
|
||||||
"master_lottery_item_id": data[0].clone(),
|
"master_lottery_item_id": data[0].clone(),
|
||||||
"master_lottery_item_number": data[1].clone()
|
"master_lottery_item_number": data[1].clone()
|
||||||
};
|
};
|
||||||
|
@ -121,7 +123,7 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let item_id = (body["master_lottery_id"].to_string().parse::<i32>().unwrap() * 100) + 1;
|
let item_id = (body["master_lottery_id"].to_string().parse::<i32>().unwrap() * 100) + 1;
|
||||||
//tutorial
|
//tutorial
|
||||||
let new_card = object!{
|
let new_card = object!{
|
||||||
"master_card_id": get_card_master_id(item_id.to_string(), String::from("1")),
|
"master_card_id": get_card_master_id(item_id.to_string(), String::from("1")).unwrap(),
|
||||||
"master_lottery_item_id": item_id,
|
"master_lottery_item_id": item_id,
|
||||||
"master_lottery_item_number": 1
|
"master_lottery_item_number": 1
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue