model is modified

This commit is contained in:
병준 박 2022-09-01 09:44:16 +00:00
parent 33b4baccf5
commit f828b707a9
5 changed files with 41 additions and 65 deletions

View File

@ -36,7 +36,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tokio-cron-scheduler = { version = "0" } tokio-cron-scheduler = { version = "0" }
uuid = { version = "0", features = ["serde", "v4", "v5"] } uuid = { version = "0", features = ["serde", "v4", "v5"] }
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.89-snapshot" } beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.92-snapshot" }
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.75-snapshot" } beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.78-snapshot" }
[build-dependencies] [build-dependencies]

View File

@ -3,15 +3,15 @@ use beteran_common_rust as bcr;
use diesel::{result::Error, sql_query, RunQueryDsl}; use diesel::{result::Error, sql_query, RunQueryDsl};
use std::fmt::Write; use std::fmt::Write;
static MEMBER_COUNT_QUERY: &str = " static BETTING_HISTORY_COUNT_QUERY: &str = "
SELECT SELECT
COUNT(akbh.id) COUNT(akbh.id)
FROM api_kgon_betting_history as akbh FROM api_kgon_betting_history as akbh
INNER JOIN members _m INNER JOIN members m
ON _m.username = akbh.site_username ON m.username = akbh.site_username
"; ";
static MEMBER_QUERY: &str = " static BETTING_HISTORY_QUERY: &str = "
SELECT SELECT
akbh.id as akbh_id , akbh.id as akbh_id ,
akbh.vendor_id as akbh_vendor_id , akbh.vendor_id as akbh_vendor_id ,
@ -37,27 +37,29 @@ SELECT
akbh.created_at as akbh_created_at , akbh.created_at as akbh_created_at ,
akbh.utc_created_at as akbh_utc_created_at, akbh.utc_created_at as akbh_utc_created_at,
_m.id as _m_id, m.id as m_id,
_m.site_id as _m_site_id, m.site_id as m_site_id,
_m.member_class_id as _m_member_class_id, m.member_class_id as m_member_class_id,
_m.member_level_id as _m_member_level_id, m.member_level_id as m_member_level_id,
_m.username as _m_username, m.username as m_username,
_m.password as _m_password, m.password as m_password,
_m.nickname as _m_nickname, m.nickname as m_nickname,
_m.mobile_phone_number as _m_mobile_phone_number, m.mobile_phone_number as m_mobile_phone_number,
_m.state as _m_state, m.state as m_state,
_m.state_changed_at as _m_state_changed_at, m.state_changed_at as m_state_changed_at,
_m.parent_member_id as _m_parent_member_id, m.parent_member_id as m_parent_member_id,
_m.child_member_count as _m_child_member_count, m.child_member_count as m_child_member_count,
_m.last_signined_ip as _m_last_signined_ip, m.last_signined_ip as m_last_signined_ip,
_m.last_signined_at as _m_last_signined_at, m.last_signined_at as m_last_signined_at,
_m.created_at as _m_created_at, m.created_at as m_created_at,
_m.updated_at as _m_updated_at, m.updated_at as m_updated_at,
_m.deleted_at as _m_deleted_at m.deleted_at as m_deleted_at
FROM api_kgon_betting_history as akbh FROM api_kgon_betting_history as akbh
INNER JOIN members _m INNER JOIN members m
ON _m.username = akbh.site_username ON m.username = akbh.site_username
"; ";
pub struct Composition {} pub struct Composition {}
@ -86,7 +88,7 @@ impl Composition {
WHERE WHERE
akbh.id = $1 akbh.id = $1
", ",
MEMBER_QUERY BETTING_HISTORY_QUERY
); );
match sql_query(query) match sql_query(query)
@ -113,7 +115,7 @@ impl Composition {
WHERE WHERE
m.id = $1 m.id = $1
", ",
MEMBER_QUERY BETTING_HISTORY_QUERY
); );
match sql_query(query) match sql_query(query)
@ -163,9 +165,9 @@ impl Composition {
}; };
let property = match property.as_str() { let property = match property.as_str() {
"member_id" => "_m.id".to_string(), "member_id" => "m.id".to_string(),
"username" => "_m.username".to_string(), "username" => "m.username".to_string(),
"nickname" => "_m.nickname".to_string(), "nickname" => "m.nickname".to_string(),
"vendor_id" => "akbh.vendor_id".to_string(), "vendor_id" => "akbh.vendor_id".to_string(),
"vendor_name" => "akbh.vendor_name".to_string(), "vendor_name" => "akbh.vendor_name".to_string(),
"game_id" => "akbh.game_id".to_string(), "game_id" => "akbh.game_id".to_string(),
@ -210,7 +212,7 @@ impl Composition {
write!(&mut query_where, " AND ") write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?; .map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
} }
write!(&mut query_where, "_m.id = '{}'", sp) write!(&mut query_where, "m.id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?; .map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
} }
@ -514,7 +516,7 @@ impl Composition {
} }
let mut query = String::new(); let mut query = String::new();
write!(&mut query, "{}", MEMBER_COUNT_QUERY) write!(&mut query, "{}", BETTING_HISTORY_COUNT_QUERY)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?; .map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
let query_where = self.get_find_all(find_all)?; let query_where = self.get_find_all(find_all)?;
@ -541,7 +543,7 @@ impl Composition {
find_all: &models::FindAll, find_all: &models::FindAll,
) -> Result<Vec<models::BettingHistoryModel>, Error> { ) -> Result<Vec<models::BettingHistoryModel>, Error> {
let mut query = String::new(); let mut query = String::new();
write!(&mut query, "{}", MEMBER_QUERY) write!(&mut query, "{}", BETTING_HISTORY_QUERY)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?; .map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
let query_where = self.get_find_all(find_all)?; let query_where = self.get_find_all(find_all)?;

View File

@ -50,18 +50,6 @@ pub struct BettingHistoryModel {
pub created_at: i64, pub created_at: i64,
/// ///
pub utc_created_at: i64, pub utc_created_at: i64,
///
pub m_site_id: uuid::Uuid,
///
pub m_member_class_id: uuid::Uuid,
///
pub m_member_level_id: uuid::Uuid,
///
pub m_parent_member_id: Option<uuid::Uuid>,
///
pub m_nickname: String,
///
pub m_mobile_phone_number: Option<String>,
} }
impl QueryableByName<diesel::pg::Pg> for BettingHistoryModel { impl QueryableByName<diesel::pg::Pg> for BettingHistoryModel {
@ -90,12 +78,6 @@ impl QueryableByName<diesel::pg::Pg> for BettingHistoryModel {
category: row.get("akbh_category")?, category: row.get("akbh_category")?,
created_at: row.get("akbh_created_at")?, created_at: row.get("akbh_created_at")?,
utc_created_at: row.get("akbh_utc_created_at")?, utc_created_at: row.get("akbh_utc_created_at")?,
m_site_id: row.get("_m_site_id")?,
m_member_class_id: row.get("_m_member_class_id")?,
m_member_level_id: row.get("_m_member_level_id")?,
m_nickname: row.get("_m_nickname")?,
m_mobile_phone_number: row.get("_m_mobile_phone_number")?,
m_parent_member_id: row.get("_m_parent_member_id")?,
}) })
} }
} }
@ -177,3 +159,5 @@ pub struct FindAll {
/// ///
pub sorts: Option<Vec<bcr::pagination::Sort>>, pub sorts: Option<Vec<bcr::pagination::Sort>>,
} }
/////////////////////////////// temparary definitions ///////////////////////////////////////////

View File

@ -2,19 +2,10 @@ use crate::compositions;
use beteran_protobuf_rust as bpr; use beteran_protobuf_rust as bpr;
impl From<&compositions::betting::models::BettingHistoryModel> impl From<&compositions::betting::models::BettingHistoryModel>
for bpr::models::api::betting::BettingHistoryModel for bpr::models::api::betting::BettingHistory
{ {
fn from(d: &compositions::betting::models::BettingHistoryModel) -> Self { fn from(d: &compositions::betting::models::BettingHistoryModel) -> Self {
let member = Some(bpr::models::api::betting::betting_history_model::Member { bpr::models::api::betting::BettingHistory {
site_id: d.m_site_id.to_string(),
member_class_id: d.m_member_class_id.to_string(),
member_level_id: d.m_member_level_id.to_string(),
parent_member_id: d.m_parent_member_id.map(|v| v.to_string()),
nickname: d.m_nickname.clone(),
mobile_phone_number: d.m_mobile_phone_number.clone(),
});
bpr::models::api::betting::BettingHistoryModel {
id: d.id.clone(), id: d.id.clone(),
vendor_id: d.vendor_id as u64, vendor_id: d.vendor_id as u64,
vendor_name: d.vendor_name.clone(), vendor_name: d.vendor_name.clone(),
@ -38,7 +29,6 @@ impl From<&compositions::betting::models::BettingHistoryModel>
category: d.category.clone(), category: d.category.clone(),
created_at: d.created_at as u64, created_at: d.created_at as u64,
utc_created_at: d.utc_created_at as u64, utc_created_at: d.utc_created_at as u64,
member,
} }
} }
} }

View File

@ -29,7 +29,7 @@ impl Service {
pool: Pool<ConnectionManager<PgConnection>>, pool: Pool<ConnectionManager<PgConnection>>,
) -> Service { ) -> Service {
Service { Service {
connection_broker: connection_broker.clone(), connection_broker,
queue_broker, queue_broker,
pool, pool,
betting_composition: compositions::betting::composition::Composition::new(), betting_composition: compositions::betting::composition::Composition::new(),
@ -188,7 +188,7 @@ impl Service {
bpr::ss::api::betting::list_betting_history_response::Result { bpr::ss::api::betting::list_betting_history_response::Result {
betting_history: list betting_history: list
.iter() .iter()
.map(bpr::models::api::betting::BettingHistoryModel::from) .map(bpr::models::api::betting::BettingHistory::from)
.collect(), .collect(),
}, },
), ),