models are added
This commit is contained in:
parent
417fca6558
commit
5742160487
|
@ -37,7 +37,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
|||
tokio-cron-scheduler = { version = "0" }
|
||||
uuid = { version = "0", features = ["serde", "v4", "v5"] }
|
||||
|
||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.78-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.63-snapshot" }
|
||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.79-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.64-snapshot" }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
203
src/compositions/member_bank_deposit/composition.rs
Normal file
203
src/compositions/member_bank_deposit/composition.rs
Normal file
|
@ -0,0 +1,203 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
use super::models;
|
||||
use crate::repositories;
|
||||
use diesel::{result::Error, sql_query, RunQueryDsl};
|
||||
use std::fmt::Write;
|
||||
|
||||
static MEMBER_QUERY: &str = "
|
||||
SELECT
|
||||
mbd.id as mbd_id,
|
||||
mbd.member_id as mbd_member_id,
|
||||
mbd.name as mbd_name,
|
||||
mbd.amount as mbd_amount,
|
||||
mbd.memo as mbd_memo,
|
||||
mbd.state as mbd_state,
|
||||
mbd.state_changed_at as mbd_state_changed_at,
|
||||
mbd.created_at as mbd_created_at,
|
||||
mbd.updated_at as mbd_updated_at,
|
||||
|
||||
_m.id as _m_id,
|
||||
_m.site_id as _m_site_id,
|
||||
_m.member_class_id as _m_member_class_id,
|
||||
_m.member_level_id as _m_member_level_id,
|
||||
_m.username as _m_username,
|
||||
_m.password as _m_password,
|
||||
_m.nickname as _m_nickname,
|
||||
_m.mobile_phone_number as _m_mobile_phone_number,
|
||||
_m.state as _m_state,
|
||||
_m.state_changed_at as _m_state_changed_at,
|
||||
_m.parent_member_id as _m_parent_member_id,
|
||||
_m.child_member_count as _m_child_member_count,
|
||||
_m.last_signined_ip as _m_last_signined_ip,
|
||||
_m.last_signined_at as _m_last_signined_at,
|
||||
_m.created_at as _m_created_at,
|
||||
_m.updated_at as _m_updated_at,
|
||||
_m.deleted_at as _m_deleted_at
|
||||
|
||||
FROM member_bank_deposits as mbd
|
||||
INNER JOIN members _m
|
||||
ON _m.id = mbd.member_id
|
||||
";
|
||||
|
||||
pub struct Composition {}
|
||||
|
||||
impl std::fmt::Debug for Composition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Composition of members").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Composition {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Composition {
|
||||
///
|
||||
pub fn new() -> Composition {
|
||||
Composition {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<Option<models::MemberBankDepositModel>, Error> {
|
||||
let query = format!(
|
||||
"
|
||||
{}
|
||||
WHERE
|
||||
mbd.id = $1
|
||||
",
|
||||
MEMBER_QUERY
|
||||
);
|
||||
|
||||
match sql_query(query)
|
||||
.bind::<diesel::sql_types::Uuid, _>(id)
|
||||
.get_result::<models::MemberBankDepositModel>(conn)
|
||||
{
|
||||
Ok(m) => Ok(Some(m)),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(None),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn selects(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
ids: Vec<uuid::Uuid>,
|
||||
) -> Result<Vec<models::MemberBankDepositModel>, Error> {
|
||||
if ids.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let mut query_where_id_in = String::new();
|
||||
|
||||
for id in ids {
|
||||
if !query_where_id_in.is_empty() {
|
||||
write!(&mut query_where_id_in, " , ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
write!(&mut query_where_id_in, " '{}' ", id)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
let query = format!(
|
||||
"
|
||||
{}
|
||||
WHERE
|
||||
mbd.id IN ({})
|
||||
",
|
||||
MEMBER_QUERY, query_where_id_in
|
||||
);
|
||||
|
||||
println!("query: {}", query);
|
||||
|
||||
match sql_query(query).get_results::<models::MemberBankDepositModel>(conn) {
|
||||
Ok(m) => Ok(m),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(vec![]),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
find_all: &repositories::member_bank_deposit::models::FindAll,
|
||||
) -> Result<Vec<models::MemberBankDepositModel>, Error> {
|
||||
let mut query = String::new();
|
||||
write!(&mut query, "{}", MEMBER_QUERY)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
|
||||
let mut query_where = String::new();
|
||||
|
||||
if let Some(s) = &find_all.search {
|
||||
if let Some(sp) = s.member_id {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbd.member_id = '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.name_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbd.name like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = s.amount {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbd.amount = '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.memo_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbd.memo like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = s.state {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbd.state = '{:?}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
}
|
||||
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query, " WHERE {}", query_where)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
println!("query: {}", query);
|
||||
|
||||
match sql_query(query).get_results::<models::MemberBankDepositModel>(conn) {
|
||||
Ok(m) => Ok(m),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(vec![]),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
7
src/compositions/member_bank_deposit/mod.rs
Normal file
7
src/compositions/member_bank_deposit/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod composition;
|
||||
///
|
||||
pub mod models;
|
64
src/compositions/member_bank_deposit/models.rs
Normal file
64
src/compositions/member_bank_deposit/models.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
//!
|
||||
//!
|
||||
use crate::repositories::member::models::Member as _Member;
|
||||
use crate::repositories::member_bank_deposit::schema::MemberBankDepositState;
|
||||
use diesel::deserialize::QueryableByName;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, PartialEq, Debug, Clone)]
|
||||
pub struct MemberBankDepositModel {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub member: _Member,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub state: MemberBankDepositState,
|
||||
///
|
||||
pub state_changed_at: i64,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
impl QueryableByName<diesel::pg::Pg> for MemberBankDepositModel {
|
||||
fn build<R: diesel::row::NamedRow<diesel::pg::Pg>>(row: &R) -> diesel::deserialize::Result<Self> {
|
||||
let member = _Member {
|
||||
id: row.get("_m_id")?,
|
||||
site_id: row.get("_m_site_id")?,
|
||||
member_class_id: row.get("_m_member_class_id")?,
|
||||
member_level_id: row.get("_m_member_level_id")?,
|
||||
username: row.get("_m_username")?,
|
||||
password: row.get("_m_password")?,
|
||||
nickname: row.get("_m_nickname")?,
|
||||
mobile_phone_number: row.get("_m_mobile_phone_number")?,
|
||||
state: row.get("_m_state")?,
|
||||
state_changed_at: row.get("_m_state_changed_at")?,
|
||||
parent_member_id: row.get("_m_parent_member_id")?,
|
||||
child_member_count: row.get("_m_child_member_count")?,
|
||||
last_signined_ip: row.get("_m_last_signined_ip")?,
|
||||
last_signined_at: row.get("_m_last_signined_at")?,
|
||||
created_at: row.get("_m_created_at")?,
|
||||
updated_at: row.get("_m_updated_at")?,
|
||||
deleted_at: row.get("_m_deleted_at")?,
|
||||
};
|
||||
|
||||
Ok(MemberBankDepositModel {
|
||||
id: row.get("mbd_id")?,
|
||||
member,
|
||||
name: row.get("mbd_name")?,
|
||||
amount: row.get("mbd_amount")?,
|
||||
memo: row.get("mbd_memo")?,
|
||||
state: row.get("mbd_state")?,
|
||||
state_changed_at: row.get("mbd_state_changed_at")?,
|
||||
created_at: row.get("mbd_created_at")?,
|
||||
updated_at: row.get("mbd_updated_at")?,
|
||||
})
|
||||
}
|
||||
}
|
249
src/compositions/member_bank_withdraw/composition.rs
Normal file
249
src/compositions/member_bank_withdraw/composition.rs
Normal file
|
@ -0,0 +1,249 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
use super::models;
|
||||
use crate::repositories;
|
||||
use diesel::{result::Error, sql_query, RunQueryDsl};
|
||||
use std::fmt::Write;
|
||||
|
||||
static MEMBER_QUERY: &str = "
|
||||
SELECT
|
||||
mbw.id as mbw_id,
|
||||
mbw.member_id as mbw_member_id,
|
||||
mbw.bank_name as mbw_bank_name,
|
||||
mbw.name as mbw_name,
|
||||
mbw.account_number as mbw_account_number,
|
||||
mbw.amount as mbw_amount,
|
||||
mbw.password as mbw_password,
|
||||
mbw.memo as mbw_memo,
|
||||
mbw.state as mbw_state,
|
||||
mbw.state_changed_at as mbw_state_changed_at,
|
||||
mbw.created_at as mbw_created_at,
|
||||
mbw.updated_at as mbw_updated_at,
|
||||
|
||||
_m.id as _m_id,
|
||||
_m.site_id as _m_site_id,
|
||||
_m.member_class_id as _m_member_class_id,
|
||||
_m.member_level_id as _m_member_level_id,
|
||||
_m.username as _m_username,
|
||||
_m.password as _m_password,
|
||||
_m.nickname as _m_nickname,
|
||||
_m.mobile_phone_number as _m_mobile_phone_number,
|
||||
_m.state as _m_state,
|
||||
_m.state_changed_at as _m_state_changed_at,
|
||||
_m.parent_member_id as _m_parent_member_id,
|
||||
_m.child_member_count as _m_child_member_count,
|
||||
_m.last_signined_ip as _m_last_signined_ip,
|
||||
_m.last_signined_at as _m_last_signined_at,
|
||||
_m.created_at as _m_created_at,
|
||||
_m.updated_at as _m_updated_at,
|
||||
_m.deleted_at as _m_deleted_at
|
||||
|
||||
FROM member_bank_withdraws as mbw
|
||||
INNER JOIN members _m
|
||||
ON _m.id = mbw.member_id
|
||||
";
|
||||
|
||||
pub struct Composition {}
|
||||
|
||||
impl std::fmt::Debug for Composition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Composition of members").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Composition {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Composition {
|
||||
///
|
||||
pub fn new() -> Composition {
|
||||
Composition {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<Option<models::MemberBankWithdrawModel>, Error> {
|
||||
let query = format!(
|
||||
"
|
||||
{}
|
||||
WHERE
|
||||
mbw.id = $1
|
||||
",
|
||||
MEMBER_QUERY
|
||||
);
|
||||
|
||||
match sql_query(query)
|
||||
.bind::<diesel::sql_types::Uuid, _>(id)
|
||||
.get_result::<models::MemberBankWithdrawModel>(conn)
|
||||
{
|
||||
Ok(m) => Ok(Some(m)),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(None),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn selects(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
ids: Vec<uuid::Uuid>,
|
||||
) -> Result<Vec<models::MemberBankWithdrawModel>, Error> {
|
||||
if ids.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let mut query_where_id_in = String::new();
|
||||
|
||||
for id in ids {
|
||||
if !query_where_id_in.is_empty() {
|
||||
write!(&mut query_where_id_in, " , ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
write!(&mut query_where_id_in, " '{}' ", id)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
let query = format!(
|
||||
"
|
||||
{}
|
||||
WHERE
|
||||
mbw.id IN ({})
|
||||
",
|
||||
MEMBER_QUERY, query_where_id_in
|
||||
);
|
||||
|
||||
println!("query: {}", query);
|
||||
|
||||
match sql_query(query).get_results::<models::MemberBankWithdrawModel>(conn) {
|
||||
Ok(m) => Ok(m),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(vec![]),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_by_username(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
username: &str,
|
||||
) -> Result<Option<models::MemberBankWithdrawModel>, Error> {
|
||||
let query = format!(
|
||||
"
|
||||
{}
|
||||
WHERE
|
||||
_m.username = $1
|
||||
",
|
||||
MEMBER_QUERY
|
||||
);
|
||||
|
||||
match sql_query(query)
|
||||
.bind::<diesel::sql_types::Text, _>(username)
|
||||
.get_result::<models::MemberBankWithdrawModel>(conn)
|
||||
{
|
||||
Ok(m) => Ok(Some(m)),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(None),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
find_all: &repositories::member_bank_withdraw::models::FindAll,
|
||||
) -> Result<Vec<models::MemberBankWithdrawModel>, Error> {
|
||||
let mut query = String::new();
|
||||
write!(&mut query, "{}", MEMBER_QUERY)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
|
||||
let mut query_where = String::new();
|
||||
|
||||
if let Some(s) = &find_all.search {
|
||||
if let Some(sp) = s.member_id {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.member_id = '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.bank_name_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.bank_name like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.name_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.name like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.account_number_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.account_number like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = s.amount {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.amount = '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = &s.memo_like {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.memo like '{}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
if let Some(sp) = s.state {
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query_where, " AND ")
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
write!(&mut query_where, "mbw.state = '{:?}'", sp)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
}
|
||||
|
||||
if !query_where.is_empty() {
|
||||
write!(&mut query, " WHERE {}", query_where)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
println!("query: {}", query);
|
||||
|
||||
match sql_query(query).get_results::<models::MemberBankWithdrawModel>(conn) {
|
||||
Ok(m) => Ok(m),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(vec![]),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
7
src/compositions/member_bank_withdraw/mod.rs
Normal file
7
src/compositions/member_bank_withdraw/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod composition;
|
||||
///
|
||||
pub mod models;
|
73
src/compositions/member_bank_withdraw/models.rs
Normal file
73
src/compositions/member_bank_withdraw/models.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
//!
|
||||
//!
|
||||
use crate::repositories::member::models::Member as _Member;
|
||||
use crate::repositories::member_bank_withdraw::schema::MemberBankWithdrawState;
|
||||
use diesel::deserialize::QueryableByName;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, PartialEq, Debug, Clone)]
|
||||
pub struct MemberBankWithdrawModel {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub member: _Member,
|
||||
///
|
||||
pub bank_name: String,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub state: MemberBankWithdrawState,
|
||||
///
|
||||
pub state_changed_at: i64,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
impl QueryableByName<diesel::pg::Pg> for MemberBankWithdrawModel {
|
||||
fn build<R: diesel::row::NamedRow<diesel::pg::Pg>>(row: &R) -> diesel::deserialize::Result<Self> {
|
||||
let member = _Member {
|
||||
id: row.get("_m_id")?,
|
||||
site_id: row.get("_m_site_id")?,
|
||||
member_class_id: row.get("_m_member_class_id")?,
|
||||
member_level_id: row.get("_m_member_level_id")?,
|
||||
username: row.get("_m_username")?,
|
||||
password: row.get("_m_password")?,
|
||||
nickname: row.get("_m_nickname")?,
|
||||
mobile_phone_number: row.get("_m_mobile_phone_number")?,
|
||||
state: row.get("_m_state")?,
|
||||
state_changed_at: row.get("_m_state_changed_at")?,
|
||||
parent_member_id: row.get("_m_parent_member_id")?,
|
||||
child_member_count: row.get("_m_child_member_count")?,
|
||||
last_signined_ip: row.get("_m_last_signined_ip")?,
|
||||
last_signined_at: row.get("_m_last_signined_at")?,
|
||||
created_at: row.get("_m_created_at")?,
|
||||
updated_at: row.get("_m_updated_at")?,
|
||||
deleted_at: row.get("_m_deleted_at")?,
|
||||
};
|
||||
|
||||
Ok(MemberBankWithdrawModel {
|
||||
id: row.get("mbw_id")?,
|
||||
member,
|
||||
bank_name: row.get("mbw_bank_name")?,
|
||||
name: row.get("mbw_name")?,
|
||||
account_number: row.get("mbw_account_number")?,
|
||||
amount: row.get("mbw_amount")?,
|
||||
password: row.get("mbw_password")?,
|
||||
memo: row.get("mbw_memo")?,
|
||||
state: row.get("mbw_state")?,
|
||||
state_changed_at: row.get("mbw_state_changed_at")?,
|
||||
created_at: row.get("mbw_created_at")?,
|
||||
updated_at: row.get("mbw_updated_at")?,
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
pub mod member;
|
||||
pub mod member_bank_deposit;
|
||||
pub mod member_bank_withdraw;
|
||||
pub mod member_referrer;
|
||||
pub mod site;
|
||||
|
|
|
@ -32,10 +32,13 @@ impl Repository {
|
|||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_resource: &models::NewMemberBankDeposit,
|
||||
) -> Result<models::MemberBankDeposit, Error> {
|
||||
) -> Result<uuid::Uuid, Error> {
|
||||
use member_bank_deposits::dsl;
|
||||
|
||||
let inserted = diesel::insert_into(member_bank_deposits::table)
|
||||
.values(new_resource)
|
||||
.get_result::<models::MemberBankDeposit>(conn)?;
|
||||
.returning(dsl::id)
|
||||
.get_result(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
|
|
@ -32,10 +32,13 @@ impl Repository {
|
|||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_resource: &models::NewMemberBankWithdraw,
|
||||
) -> Result<models::MemberBankWithdraw, Error> {
|
||||
) -> Result<uuid::Uuid, Error> {
|
||||
use member_bank_withdraws::dsl;
|
||||
|
||||
let inserted = diesel::insert_into(member_bank_withdraws::table)
|
||||
.values(new_resource)
|
||||
.get_result::<models::MemberBankWithdraw>(conn)?;
|
||||
.returning(dsl::id)
|
||||
.get_result(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compositions;
|
||||
use crate::repositories;
|
||||
use beteran_protobuf_rust as bpr;
|
||||
|
||||
|
@ -19,6 +20,24 @@ impl From<&repositories::member_bank_deposit::models::MemberBankDeposit>
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&compositions::member_bank_deposit::models::MemberBankDepositModel>
|
||||
for bpr::models::member_bank_deposit::MemberBankDepositModel
|
||||
{
|
||||
fn from(d: &compositions::member_bank_deposit::models::MemberBankDepositModel) -> Self {
|
||||
bpr::models::member_bank_deposit::MemberBankDepositModel {
|
||||
id: d.id.to_string(),
|
||||
member: Some(bpr::models::member::Member::from(&d.member)),
|
||||
name: d.name.clone(),
|
||||
amount: d.amount as u32,
|
||||
memo: d.memo.clone(),
|
||||
state: d.state as i32,
|
||||
state_changed_at: d.state_changed_at as u64,
|
||||
created_at: d.created_at as u64,
|
||||
updated_at: d.updated_at as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for repositories::member_bank_deposit::schema::MemberBankDepositState {
|
||||
fn from(s: i32) -> Self {
|
||||
match s {
|
||||
|
|
|
@ -22,6 +22,7 @@ pub struct Service {
|
|||
site_repository: repositories::site::repository::Repository,
|
||||
site_composition: compositions::site::composition::Composition,
|
||||
member_bank_deposit_repository: repositories::member_bank_deposit::repository::Repository,
|
||||
member_bank_deposit_composition: compositions::member_bank_deposit::composition::Composition,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Service {
|
||||
|
@ -46,6 +47,8 @@ impl Service {
|
|||
site_composition: compositions::site::composition::Composition::new(),
|
||||
member_bank_deposit_repository:
|
||||
repositories::member_bank_deposit::repository::Repository::new(),
|
||||
member_bank_deposit_composition:
|
||||
compositions::member_bank_deposit::composition::Composition::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +170,7 @@ impl Service {
|
|||
})
|
||||
})?;
|
||||
|
||||
let s = self
|
||||
let inserted_id = self
|
||||
.member_bank_deposit_repository
|
||||
.insert(
|
||||
&conn,
|
||||
|
@ -186,15 +189,26 @@ impl Service {
|
|||
})
|
||||
})?;
|
||||
|
||||
let inserted = self
|
||||
.member_bank_deposit_composition
|
||||
.select(&conn, inserted_id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
})
|
||||
})?;
|
||||
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member_bank_deposit::CreateMemberBankDepositResponse {
|
||||
error: None,
|
||||
result: Some(
|
||||
bpr::ss::member_bank_deposit::create_member_bank_deposit_response::Result {
|
||||
member_bank_deposit: Some(
|
||||
bpr::models::member_bank_deposit::MemberBankDeposit::from(&s),
|
||||
),
|
||||
member_bank_deposit: inserted
|
||||
.as_ref()
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDepositModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -354,7 +368,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let list = self
|
||||
.member_bank_deposit_repository
|
||||
.member_bank_deposit_composition
|
||||
.select_all(&conn, &find_all)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -372,7 +386,7 @@ impl Service {
|
|||
bpr::ss::member_bank_deposit::list_member_bank_deposits_response::Result {
|
||||
member_bank_deposits: list
|
||||
.iter()
|
||||
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(d))
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDepositModel::from)
|
||||
.collect(),
|
||||
},
|
||||
),
|
||||
|
@ -482,7 +496,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_deposit_repository
|
||||
.member_bank_deposit_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -499,7 +513,7 @@ impl Service {
|
|||
result: Some(
|
||||
bpr::ss::member_bank_deposit::get_member_bank_deposit_response::Result {
|
||||
member_bank_deposit: s
|
||||
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(&d)),
|
||||
.map(|d| bpr::models::member_bank_deposit::MemberBankDepositModel::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -626,7 +640,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_deposit_repository
|
||||
.member_bank_deposit_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -643,7 +657,7 @@ impl Service {
|
|||
result: Some(
|
||||
bpr::ss::member_bank_deposit::update_member_bank_deposit_response::Result {
|
||||
member_bank_deposit: s
|
||||
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(&d)),
|
||||
.map(|d| bpr::models::member_bank_deposit::MemberBankDepositModel::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -770,7 +784,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_deposit_repository
|
||||
.member_bank_deposit_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -788,7 +802,7 @@ impl Service {
|
|||
bpr::ss::member_bank_deposit::update_member_bank_deposit_response::Result {
|
||||
member_bank_deposit: s
|
||||
.as_ref()
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDeposit::from),
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDepositModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -813,7 +827,7 @@ impl Service {
|
|||
bpr::ss::member_bank_deposit::after_update_member_bank_deposit_for_state::Event {
|
||||
member_bank_deposit: s
|
||||
.as_ref()
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDeposit::from),
|
||||
.map(bpr::models::member_bank_deposit::MemberBankDepositModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compositions;
|
||||
use crate::repositories;
|
||||
use beteran_protobuf_rust as bpr;
|
||||
|
||||
|
@ -22,6 +23,27 @@ impl From<&repositories::member_bank_withdraw::models::MemberBankWithdraw>
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&compositions::member_bank_withdraw::models::MemberBankWithdrawModel>
|
||||
for bpr::models::member_bank_withdraw::MemberBankWithdrawModel
|
||||
{
|
||||
fn from(d: &compositions::member_bank_withdraw::models::MemberBankWithdrawModel) -> Self {
|
||||
bpr::models::member_bank_withdraw::MemberBankWithdrawModel {
|
||||
id: d.id.to_string(),
|
||||
member: Some(bpr::models::member::Member::from(&d.member)),
|
||||
bank_name: d.bank_name.clone(),
|
||||
account_number: d.account_number.clone(),
|
||||
password: d.password.clone(),
|
||||
name: d.name.clone(),
|
||||
amount: d.amount as u32,
|
||||
memo: d.memo.clone(),
|
||||
state: d.state as i32,
|
||||
state_changed_at: d.state_changed_at as u64,
|
||||
created_at: d.created_at as u64,
|
||||
updated_at: d.updated_at as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for repositories::member_bank_withdraw::schema::MemberBankWithdrawState {
|
||||
fn from(s: i32) -> Self {
|
||||
match s {
|
||||
|
|
|
@ -22,6 +22,7 @@ pub struct Service {
|
|||
site_repository: repositories::site::repository::Repository,
|
||||
site_composition: compositions::site::composition::Composition,
|
||||
member_bank_withdraw_repository: repositories::member_bank_withdraw::repository::Repository,
|
||||
member_bank_withdraw_composition: compositions::member_bank_withdraw::composition::Composition,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Service {
|
||||
|
@ -46,6 +47,8 @@ impl Service {
|
|||
site_composition: compositions::site::composition::Composition::new(),
|
||||
member_bank_withdraw_repository:
|
||||
repositories::member_bank_withdraw::repository::Repository::new(),
|
||||
member_bank_withdraw_composition:
|
||||
compositions::member_bank_withdraw::composition::Composition::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +180,7 @@ impl Service {
|
|||
memo: request.memo,
|
||||
};
|
||||
|
||||
let s = self
|
||||
let inserted_id = self
|
||||
.member_bank_withdraw_repository
|
||||
.insert(&conn, &new_member_bank_withdraw)
|
||||
.map_err(|e| {
|
||||
|
@ -188,15 +191,26 @@ impl Service {
|
|||
})
|
||||
})?;
|
||||
|
||||
let inserted = self
|
||||
.member_bank_withdraw_composition
|
||||
.select(&conn, inserted_id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
})
|
||||
})?;
|
||||
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member_bank_withdraw::CreateMemberBankWithdrawResponse {
|
||||
error: None,
|
||||
result: Some(
|
||||
bpr::ss::member_bank_withdraw::create_member_bank_withdraw_response::Result {
|
||||
member_bank_withdraw: Some(
|
||||
bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&s),
|
||||
),
|
||||
member_bank_withdraw: inserted
|
||||
.as_ref()
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -357,7 +371,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let list = self
|
||||
.member_bank_withdraw_repository
|
||||
.member_bank_withdraw_composition
|
||||
.select_all(&conn, &find_all)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -375,7 +389,7 @@ impl Service {
|
|||
bpr::ss::member_bank_withdraw::list_member_bank_withdraws_response::Result {
|
||||
member_bank_withdraws: list
|
||||
.iter()
|
||||
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(d))
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from)
|
||||
.collect(),
|
||||
},
|
||||
),
|
||||
|
@ -485,7 +499,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_withdraw_repository
|
||||
.member_bank_withdraw_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -502,7 +516,7 @@ impl Service {
|
|||
result: Some(
|
||||
bpr::ss::member_bank_withdraw::get_member_bank_withdraw_response::Result {
|
||||
member_bank_withdraw: s
|
||||
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&d)),
|
||||
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -632,7 +646,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_withdraw_repository
|
||||
.member_bank_withdraw_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -649,7 +663,7 @@ impl Service {
|
|||
result: Some(
|
||||
bpr::ss::member_bank_withdraw::update_member_bank_withdraw_response::Result {
|
||||
member_bank_withdraw: s
|
||||
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&d)),
|
||||
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -776,7 +790,7 @@ impl Service {
|
|||
})?;
|
||||
|
||||
let s = self
|
||||
.member_bank_withdraw_repository
|
||||
.member_bank_withdraw_composition
|
||||
.select(&conn, id)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
|
@ -793,7 +807,7 @@ impl Service {
|
|||
result: Some(
|
||||
bpr::ss::member_bank_withdraw::update_member_bank_withdraw_for_state_response::Result {
|
||||
member_bank_withdraw: s.as_ref()
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdraw::from),
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
@ -818,7 +832,7 @@ impl Service {
|
|||
bpr::ss::member_bank_withdraw::after_update_member_bank_withdraw_for_state::Event {
|
||||
member_bank_withdraw: s
|
||||
.as_ref()
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdraw::from),
|
||||
.map(bpr::models::member_bank_withdraw::MemberBankWithdrawModel::from),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user