From e55adae3dc08ced115acd8a62491db8481aec4e2 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Mon, 22 Aug 2022 02:07:51 +0000 Subject: [PATCH] refactoring --- .vscode/launch.json | 12 ++++---- src/api/game/api.rs | 14 ++++----- src/api/game/models.rs | 6 ++-- src/api/member/api.rs | 5 +--- src/api/member_account/api.rs | 55 +++++++---------------------------- 5 files changed, 28 insertions(+), 64 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1085b59..fefa4b0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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}" diff --git a/src/api/game/api.rs b/src/api/game/api.rs index 6490e1f..5ab5231 100644 --- a/src/api/game/api.rs +++ b/src/api/game/api.rs @@ -86,7 +86,10 @@ impl Api { } /// - pub async fn play(&self, data: models::PlayRequest) -> Result { + pub async fn get_game_url( + &self, + data: models::GetGameUrlRequest, + ) -> Result { 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::().await { + reqwest::StatusCode::OK => match res.json::().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, diff --git a/src/api/game/models.rs b/src/api/game/models.rs index 4f9e03c..ab285f7 100644 --- a/src/api/game/models.rs +++ b/src/api/game/models.rs @@ -29,7 +29,7 @@ pub struct ListGamesResponse { pub games: Vec, } -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, #[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, diff --git a/src/api/member/api.rs b/src/api/member/api.rs index ff49b8f..3db875a 100644 --- a/src/api/member/api.rs +++ b/src/api/member/api.rs @@ -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 }) } diff --git a/src/api/member_account/api.rs b/src/api/member_account/api.rs index a41ca1e..2930a39 100644 --- a/src/api/member_account/api.rs +++ b/src/api/member_account/api.rs @@ -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,