refactoring

This commit is contained in:
병준 박 2022-08-22 02:07:51 +00:00
parent 40e687c5d9
commit e55adae3dc
5 changed files with 28 additions and 64 deletions

12
.vscode/launch.json vendored
View File

@ -23,9 +23,9 @@
"URL_DATABASE": "postgresql://beteran:qwer5795QWER@192.168.50.205:25432/beteran",
"URL_BROKER": "nats://192.168.50.205:4222",
"QUEUE_BROKER": "bet.beteran",
"K_URL": "https://dev-mw.kgonapi.com",
"K_USERNAME": "Turbo77",
"K_SECRET": "c23d770b873b2ce95747abc57052beb0",
"K_URL": "https://dev-v1.kgonapi.com/",
"K_USERNAME": "turbo78",
"K_SECRET": "561b6f4d6e4c5f1b8a3473c43c3caa84",
},
"args": [],
"cwd": "${workspaceFolder}"
@ -50,9 +50,9 @@
"URL_DATABASE": "postgresql://beteran:qwer5795QWER@192.168.50.205:25432/beteran",
"URL_BROKER": "nats://192.168.50.205:4222",
"QUEUE_BROKER": "bet.beteran",
"K_URL": "https://dev-mw.kgonapi.com",
"K_USERNAME": "Turbo77",
"K_SECRET": "c23d770b873b2ce95747abc57052beb0",
"K_URL": "https://dev-v1.kgonapi.com/",
"K_USERNAME": "turbo78",
"K_SECRET": "561b6f4d6e4c5f1b8a3473c43c3caa84",
},
"args": [],
"cwd": "${workspaceFolder}"

View File

@ -86,7 +86,10 @@ impl Api {
}
///
pub async fn play(&self, data: models::PlayRequest) -> Result<models::PlayResponse, Error> {
pub async fn get_game_url(
&self,
data: models::GetGameUrlRequest,
) -> Result<models::GetGameUrlResponse, Error> {
let mut params = HashMap::new();
params.insert("vendorKey", data.vendor_key);
@ -130,7 +133,7 @@ impl Api {
};
match res.status() {
reqwest::StatusCode::OK => match res.json::<models::_PlayResponse>().await {
reqwest::StatusCode::OK => match res.json::<models::_GetGameUrlResponse>().await {
Ok(r) => {
if r.code != 0 {
return Err(Error {
@ -147,12 +150,9 @@ impl Api {
Some(v) => v,
None => "".to_string(),
};
let balance = match r.balance {
Some(v) => v,
None => 0,
};
let balance = r.balance.unwrap_or(0);
Ok(models::PlayResponse {
Ok(models::GetGameUrlResponse {
user_id,
url,
balance,

View File

@ -29,7 +29,7 @@ pub struct ListGamesResponse {
pub games: Vec<Game>,
}
pub struct PlayRequest {
pub struct GetGameUrlRequest {
pub vendor_key: String,
pub game_key: String,
pub username: String,
@ -41,7 +41,7 @@ pub struct PlayRequest {
}
#[derive(Serialize, Deserialize, Debug)]
pub struct _PlayResponse {
pub struct _GetGameUrlResponse {
pub code: i64,
pub msg: Option<String>,
#[serde(rename = "userId")]
@ -51,7 +51,7 @@ pub struct _PlayResponse {
}
#[derive(Debug)]
pub struct PlayResponse {
pub struct GetGameUrlResponse {
pub user_id: String,
pub url: String,
pub balance: i64,

View File

@ -135,10 +135,7 @@ impl Api {
});
}
let id = match r.id {
Some(v) => v,
None => 0,
};
let id = r.id.unwrap_or(0);
Ok(models::CreateMemberResponse { id })
}

View File

@ -66,22 +66,10 @@ impl Api {
});
}
let balance = match r.balance {
Some(v) => v,
None => 0,
};
let balance_bota = match r.balance_bota {
Some(v) => v,
None => 0,
};
let balance_sum = match r.balance_sum {
Some(v) => v,
None => 0,
};
let companies = match r.companies {
Some(v) => v,
None => 0,
};
let balance = r.balance.unwrap_or(0);
let balance_bota = r.balance_bota.unwrap_or(0);
let balance_sum = r.balance_sum.unwrap_or(0);
let companies = r.companies.unwrap_or(0);
Ok(models::GetBalanceForUserResponse {
balance,
@ -139,14 +127,8 @@ impl Api {
});
}
let balance = match r.balance {
Some(v) => v,
None => 0,
};
let balance_bota = match r.balance_bota {
Some(v) => v,
None => 0,
};
let balance = r.balance.unwrap_or(0);
let balance_bota = r.balance_bota.unwrap_or(0);
Ok(models::GetBalanceForPartnerResponse {
balance,
@ -214,10 +196,7 @@ impl Api {
});
}
let balance = match r.balance {
Some(v) => v,
None => 0,
};
let balance = r.balance.unwrap_or(0);
Ok(models::CreateDepositResponse { balance })
}
@ -278,22 +257,10 @@ impl Api {
});
}
let balance = match r.balance {
Some(v) => v,
None => 0,
};
let balance_cash = match r.balance_cash {
Some(v) => v,
None => 0,
};
let balance_cash_bota = match r.balance_cash_bota {
Some(v) => v,
None => 0,
};
let amount = match r.amount {
Some(v) => v,
None => 0,
};
let balance = r.balance.unwrap_or(0);
let balance_cash = r.balance_cash.unwrap_or(0);
let balance_cash_bota = r.balance_cash_bota.unwrap_or(0);
let amount = r.amount.unwrap_or(0);
Ok(models::CreateWithdrawResponse {
balance,