From dfc328b636e08278520d8bac11317cf695f1c6f1 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Mon, 5 Sep 2022 08:06:17 +0000 Subject: [PATCH] model is modified --- .../up.sql | 7 +-- src/api/betting/models.rs | 46 ++++++++++++++----- src/api/member_account/api.rs | 12 ++++- src/api/member_account/models.rs | 2 +- src/repositories/betting_history/models.rs | 28 ++++++----- src/repositories/betting_history/schema.rs | 14 +++--- .../betting_history/synchronizer.rs | 18 ++++++-- 7 files changed, 90 insertions(+), 37 deletions(-) diff --git a/migrations/202208101000_api_kgon_betting_history/up.sql b/migrations/202208101000_api_kgon_betting_history/up.sql index 4a7c601..fd0faa3 100644 --- a/migrations/202208101000_api_kgon_betting_history/up.sql +++ b/migrations/202208101000_api_kgon_betting_history/up.sql @@ -10,14 +10,15 @@ CREATE TABLE IF NOT EXISTS api_kgon_betting_history ( cash DOUBLE PRECISION, before_cash DOUBLE PRECISION, after_cash DOUBLE PRECISION, - key TEXT NOT NULL, - ref_id TEXT NOT NULL, - o_ref_id TEXT NOT NULL, group_key TEXT, + detail TEXT, is_bonus BOOLEAN NOT NULL, is_promo BOOLEAN NOT NULL, is_jackpot BOOLEAN NOT NULL, site_username TEXT NOT NULL, + key TEXT NOT NULL, + ref_id TEXT NOT NULL, + o_ref_id TEXT, betting_type TEXT NOT NULL, category TEXT NOT NULL, created_at BIGINT NOT NULL, diff --git a/src/api/betting/models.rs b/src/api/betting/models.rs index f319740..31fd32b 100644 --- a/src/api/betting/models.rs +++ b/src/api/betting/models.rs @@ -2,45 +2,69 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct Betting { + /// KGON 거래 고유 코드 pub _id: String, + /// 게임사 코드 #[serde(rename = "vendorId")] pub vendor_id: i64, + /// 게임사 #[serde(rename = "vendorName")] pub vendor_name: String, + /// 게임코드 #[serde(rename = "gameId")] pub game_id: i64, + /// 게임명 #[serde(rename = "gameName")] pub game_name: String, + /// 게임종류 #[serde(rename = "gameCategory")] pub game_category: String, + /// 게임형식 #[serde(rename = "gameType")] pub game_type: String, + /// 환율 pub currency: String, + /// 거래금액 pub cash: f64, + /// 이전보유금액 #[serde(rename = "beforeCash")] pub before_cash: f64, + /// 이후보유금액 #[serde(rename = "afterCash")] pub after_cash: f64, + /// 사이트 매장 코드 + #[serde(rename = "groupKey")] + pub group_key: Option, + /// 게임 데이터 + pub detail: Option, + /// 보너스 여부 + #[serde(rename = "isBonus")] + pub is_bonus: bool, + /// 프로모션 여부 + #[serde(rename = "isPromo")] + pub is_promo: bool, + /// 잭팟 여부 + #[serde(rename = "isJackpot")] + pub is_jackpot: bool, + /// 사이트 회원 아이디 + #[serde(rename = "siteUsername")] + pub site_username: String, + /// 게임사 고유코드 pub key: String, + /// 게임사 상위 배팅 코드 #[serde(rename = "refId")] pub ref_id: String, #[serde(rename = "oRefId")] - pub o_ref_id: String, - #[serde(rename = "groupKey")] - pub group_key: Option, - #[serde(rename = "isBonus")] - pub is_bonus: bool, - #[serde(rename = "isPromo")] - pub is_promo: bool, - #[serde(rename = "isJackpot")] - pub is_jackpot: bool, - #[serde(rename = "siteUsername")] - pub site_username: String, + pub o_ref_id: Option, + /// 결과로서 turn_bet, turn_win, turn_draw, turn_cancel이 존재 #[serde(rename = "type")] pub betting_type: String, + /// 카테고리 pub category: String, + /// 일자 - 파트너의 timezone 반영 #[serde(rename = "createdAt")] pub created_at: String, + /// UTC TIME 으로서 한국시간에서 9시간이 빠진 시간입니다. 다음 검색시 sdate에 입력하세요 #[serde(rename = "utcCreatedAt")] pub utc_created_at: String, } diff --git a/src/api/member_account/api.rs b/src/api/member_account/api.rs index f23c427..a54a63a 100644 --- a/src/api/member_account/api.rs +++ b/src/api/member_account/api.rs @@ -69,7 +69,17 @@ impl Api { let balance = r.balance.unwrap_or(0.00); let balance_bota = r.balance_bota.unwrap_or(0.00); let balance_sum = r.balance_sum.unwrap_or(0.00); - let companies = r.companies; + let companies = match r.companies { + Some(v) => { + let vv = serde_json::from_value::(v).map_err(|e| Error { + code: -1, + msg: Some(e.to_string()), + })?; + + Some(vv) + } + None => None, + }; Ok(models::GetBalanceForUserResponse { balance, diff --git a/src/api/member_account/models.rs b/src/api/member_account/models.rs index 22c5681..f977f31 100644 --- a/src/api/member_account/models.rs +++ b/src/api/member_account/models.rs @@ -13,7 +13,7 @@ pub struct _GetBalanceForUserResponse { pub balance_bota: Option, #[serde(rename = "balanceSum")] pub balance_sum: Option, - pub companies: Option, + pub companies: Option, } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/repositories/betting_history/models.rs b/src/repositories/betting_history/models.rs index 2f7a1e7..56b805b 100644 --- a/src/repositories/betting_history/models.rs +++ b/src/repositories/betting_history/models.rs @@ -28,14 +28,10 @@ pub struct BettingHistory { /// pub after_cash: f64, /// - pub key: String, - /// - pub ref_id: String, - /// - pub o_ref_id: String, - /// pub group_key: Option, /// + pub detail: Option, + /// pub is_bonus: bool, /// pub is_promo: bool, @@ -44,6 +40,12 @@ pub struct BettingHistory { /// pub site_username: String, /// + pub key: String, + /// + pub ref_id: String, + /// + pub o_ref_id: Option, + /// pub betting_type: String, /// pub category: String, @@ -80,14 +82,10 @@ pub struct NewBettingHistory { /// pub after_cash: f64, /// - pub key: String, - /// - pub ref_id: String, - /// - pub o_ref_id: String, - /// pub group_key: Option, /// + pub detail: Option, + /// pub is_bonus: bool, /// pub is_promo: bool, @@ -96,6 +94,12 @@ pub struct NewBettingHistory { /// pub site_username: String, /// + pub key: String, + /// + pub ref_id: String, + /// + pub o_ref_id: Option, + /// pub betting_type: String, /// pub category: String, diff --git a/src/repositories/betting_history/schema.rs b/src/repositories/betting_history/schema.rs index f326ce9..ecec0a8 100644 --- a/src/repositories/betting_history/schema.rs +++ b/src/repositories/betting_history/schema.rs @@ -27,14 +27,10 @@ table! { /// after_cash -> Double, /// - key -> Text, - /// - ref_id -> Text, - /// - o_ref_id -> Text, - /// group_key -> Nullable, /// + detail -> Nullable, + /// is_bonus -> Bool, /// is_promo -> Bool, @@ -43,6 +39,12 @@ table! { /// site_username -> Text, /// + key -> Text, + /// + ref_id -> Text, + /// + o_ref_id -> Nullable, + /// betting_type -> Text, /// category -> Text, diff --git a/src/synchronizations/betting_history/synchronizer.rs b/src/synchronizations/betting_history/synchronizer.rs index 81898a0..64e34ba 100644 --- a/src/synchronizations/betting_history/synchronizer.rs +++ b/src/synchronizations/betting_history/synchronizer.rs @@ -137,6 +137,17 @@ impl Synchronizer { }); } }; + let detail = match b.detail { + Some(v) => { + let vv = serde_json::from_value::(v).map_err(|e| api::core::models::Error { + code: -1, + msg: Some(format!("serde_json::from_value error: {}", e)), + })?; + + Some(vv) + } + None => None, + }; new_betting_history.push(repositories::betting_history::models::NewBettingHistory { id: b._id, @@ -150,14 +161,15 @@ impl Synchronizer { cash: b.cash, before_cash: b.before_cash, after_cash: b.after_cash, - key: b.key, - ref_id: b.ref_id, - o_ref_id: b.o_ref_id, group_key: b.group_key, + detail, is_bonus: b.is_bonus, is_promo: b.is_promo, is_jackpot: b.is_jackpot, site_username: b.site_username, + key: b.key, + ref_id: b.ref_id, + o_ref_id: b.o_ref_id, betting_type: b.betting_type, category: b.category, created_at,