member, member_bank_account are modified
This commit is contained in:
parent
39e7a78e76
commit
6828925563
|
@ -31,7 +31,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.58-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.42-snapshot" }
|
||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.60-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.44-snapshot" }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS member_bank_accounts (
|
|||
bank_id UUID NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
account_number TEXT NOT NULL,
|
||||
exchange_password TEXT NOT NULL,
|
||||
memo TEXT,
|
||||
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
|
||||
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
|
||||
|
|
|
@ -73,6 +73,7 @@ SELECT
|
|||
mba.bank_id as mba_bank_id,
|
||||
mba.name as mba_name,
|
||||
mba.account_number as mba_account_number,
|
||||
mba.exchange_password as mba_exchange_password,
|
||||
mba.memo as mba_memo,
|
||||
mba.created_at as mba_created_at,
|
||||
mba.updated_at as mba_updated_at,
|
||||
|
|
|
@ -19,6 +19,8 @@ pub struct MemberModel {
|
|||
///
|
||||
pub member_level: _MemberLevel,
|
||||
///
|
||||
pub bank_account: Option<MemberBankAccountModel>,
|
||||
///
|
||||
pub username: String,
|
||||
///
|
||||
pub password: String,
|
||||
|
@ -31,8 +33,6 @@ pub struct MemberModel {
|
|||
///
|
||||
pub state_changed_at: Option<i64>,
|
||||
///
|
||||
pub bank_account: Option<MemberBankAccountModel>,
|
||||
///
|
||||
pub referrer_member: Option<_Member>,
|
||||
///
|
||||
pub referred_count: i64,
|
||||
|
@ -99,6 +99,7 @@ impl QueryableByName<diesel::pg::Pg> for MemberModel {
|
|||
bank,
|
||||
name: row.get("mba_name")?,
|
||||
account_number: row.get("mba_account_number")?,
|
||||
exchange_password: row.get("mba_exchange_password")?,
|
||||
memo: row.get("mba_memo")?,
|
||||
created_at: row.get("mba_created_at")?,
|
||||
updated_at: row.get("mba_updated_at")?,
|
||||
|
@ -167,6 +168,8 @@ pub struct MemberBankAccountModel {
|
|||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub exchange_password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
|
|
|
@ -16,6 +16,8 @@ pub struct MemberBankAccount {
|
|||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub exchange_password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
|
@ -36,6 +38,8 @@ pub struct NewMemberBankAccount {
|
|||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub exchange_password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -50,6 +54,8 @@ pub struct ModifyMemberBankAccount {
|
|||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub exchange_password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,26 @@ impl Repository {
|
|||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_by_member_id(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
member_id: uuid::Uuid,
|
||||
) -> Result<Option<models::MemberBankAccount>, Error> {
|
||||
use member_bank_accounts::dsl;
|
||||
|
||||
match member_bank_accounts::table
|
||||
.filter(dsl::member_id.eq(member_id))
|
||||
.first::<models::MemberBankAccount>(conn)
|
||||
{
|
||||
Ok(m) => Ok(Some(m)),
|
||||
Err(e) => match e {
|
||||
diesel::result::Error::NotFound => Ok(None),
|
||||
_ => Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all_count(
|
||||
&self,
|
||||
|
|
|
@ -15,6 +15,8 @@ table! {
|
|||
///
|
||||
account_number -> Text,
|
||||
///
|
||||
exchange_password -> Text,
|
||||
///
|
||||
memo -> Nullable<Text>,
|
||||
///
|
||||
created_at -> BigInt,
|
||||
|
|
|
@ -62,6 +62,10 @@ impl From<&compositions::member::models::MemberModel> for bpr::models::member::M
|
|||
member_level: Some(bpr::models::member_level::MemberLevel::from(
|
||||
&d.member_level,
|
||||
)),
|
||||
bank_account: d
|
||||
.bank_account
|
||||
.as_ref()
|
||||
.map(|d| bpr::models::member_bank_account::MemberBankAccountModel::from(d)),
|
||||
referrer_member: d
|
||||
.referrer_member
|
||||
.as_ref()
|
||||
|
|
|
@ -343,6 +343,7 @@ impl Service<'_> {
|
|||
bank_id,
|
||||
name: a.name,
|
||||
account_number: a.account_number,
|
||||
exchange_password: a.exchange_password,
|
||||
memo: None,
|
||||
};
|
||||
self
|
||||
|
@ -1007,10 +1008,28 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let password_hash = match request.password {
|
||||
Some(p) => match argon2::hash_encoded(
|
||||
p.as_bytes(),
|
||||
self.password_salt.as_bytes(),
|
||||
&self.argon2_config,
|
||||
) {
|
||||
Ok(p) => Some(p),
|
||||
Err(e) => {
|
||||
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
}));
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
let modify_member = repositories::member::models::ModifyMember {
|
||||
site_id,
|
||||
member_level_id,
|
||||
password: request.password,
|
||||
password: password_hash,
|
||||
mobile_phone_number: request.mobile_phone_number,
|
||||
};
|
||||
|
||||
|
@ -1025,6 +1044,53 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
if let Some(a) = request.bank_account {
|
||||
let id = uuid::Uuid::from_str(a.id.as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid bank_account.id param".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "bank_account.id".to_string(),
|
||||
value: a.id.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: e.to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let bank_id = uuid::Uuid::from_str(a.bank_id.as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid bank_account.bank_id param".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "bank_account.bank_id".to_string(),
|
||||
value: a.bank_id.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: e.to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let modify_member_bank_account =
|
||||
repositories::member_bank_account::models::ModifyMemberBankAccount {
|
||||
bank_id,
|
||||
name: a.name,
|
||||
account_number: a.account_number,
|
||||
exchange_password: a.exchange_password,
|
||||
memo: None,
|
||||
};
|
||||
self
|
||||
.member_bank_account_repository
|
||||
.update(&conn, id, &modify_member_bank_account)
|
||||
.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,
|
||||
})
|
||||
})?;
|
||||
}
|
||||
|
||||
let m = self.member_composition.select(&conn, id).map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::repositories;
|
||||
use crate::{compositions, repositories};
|
||||
use beteran_protobuf_rust as bpr;
|
||||
|
||||
impl From<&repositories::member_bank_account::models::MemberBankAccount>
|
||||
|
@ -11,6 +11,25 @@ impl From<&repositories::member_bank_account::models::MemberBankAccount>
|
|||
bank_id: d.bank_id.to_string(),
|
||||
name: d.name.clone(),
|
||||
account_number: d.account_number.to_string(),
|
||||
exchange_password: d.exchange_password.to_string(),
|
||||
memo: d.memo.clone(),
|
||||
created_at: d.created_at as u64,
|
||||
updated_at: d.updated_at as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&compositions::member::models::MemberBankAccountModel>
|
||||
for bpr::models::member_bank_account::MemberBankAccountModel
|
||||
{
|
||||
fn from(d: &compositions::member::models::MemberBankAccountModel) -> Self {
|
||||
bpr::models::member_bank_account::MemberBankAccountModel {
|
||||
id: d.id.to_string(),
|
||||
member_id: d.member_id.to_string(),
|
||||
bank: Some(bpr::models::bank::Bank::from(&d.bank)),
|
||||
name: d.name.clone(),
|
||||
account_number: d.account_number.clone(),
|
||||
exchange_password: d.exchange_password.clone(),
|
||||
memo: d.memo.clone(),
|
||||
created_at: d.created_at as u64,
|
||||
updated_at: d.updated_at as u64,
|
||||
|
|
|
@ -188,6 +188,7 @@ impl Service {
|
|||
bank_id,
|
||||
name: request.name,
|
||||
account_number: request.account_number,
|
||||
exchange_password: request.exchange_password,
|
||||
memo: request.memo,
|
||||
},
|
||||
)
|
||||
|
@ -658,10 +659,11 @@ impl Service {
|
|||
&conn,
|
||||
id,
|
||||
&repositories::member_bank_account::models::ModifyMemberBankAccount {
|
||||
name: request.name,
|
||||
memo: request.memo,
|
||||
bank_id,
|
||||
name: request.name,
|
||||
account_number: request.account_number,
|
||||
exchange_password: request.exchange_password,
|
||||
memo: request.memo,
|
||||
},
|
||||
)
|
||||
.map_err(|e| {
|
||||
|
|
Loading…
Reference in New Issue
Block a user