member, member_bank_account are modified

This commit is contained in:
병준 박 2022-08-15 04:41:26 +00:00
parent 39e7a78e76
commit 6828925563
11 changed files with 140 additions and 16 deletions

View File

@ -31,7 +31,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.58-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.42-snapshot" } beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.44-snapshot" }
[build-dependencies] [build-dependencies]

View File

@ -1,12 +1,13 @@
CREATE TABLE IF NOT EXISTS member_bank_accounts ( CREATE TABLE IF NOT EXISTS member_bank_accounts (
id UUID DEFAULT uuid_generate_v4(), id UUID DEFAULT uuid_generate_v4(),
member_id UUID NOT NULL, member_id UUID NOT NULL,
bank_id UUID NOT NULL, bank_id UUID NOT NULL,
name TEXT NOT NULL, name TEXT NOT NULL,
account_number TEXT NOT NULL, account_number TEXT NOT NULL,
memo TEXT, exchange_password TEXT NOT NULL,
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000), memo TEXT,
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000), created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT fk_member_bank_accounts_member_id CONSTRAINT fk_member_bank_accounts_member_id
FOREIGN KEY(member_id) FOREIGN KEY(member_id)

View File

@ -73,6 +73,7 @@ SELECT
mba.bank_id as mba_bank_id, mba.bank_id as mba_bank_id,
mba.name as mba_name, mba.name as mba_name,
mba.account_number as mba_account_number, mba.account_number as mba_account_number,
mba.exchange_password as mba_exchange_password,
mba.memo as mba_memo, mba.memo as mba_memo,
mba.created_at as mba_created_at, mba.created_at as mba_created_at,
mba.updated_at as mba_updated_at, mba.updated_at as mba_updated_at,

View File

@ -19,6 +19,8 @@ pub struct MemberModel {
/// ///
pub member_level: _MemberLevel, pub member_level: _MemberLevel,
/// ///
pub bank_account: Option<MemberBankAccountModel>,
///
pub username: String, pub username: String,
/// ///
pub password: String, pub password: String,
@ -31,8 +33,6 @@ pub struct MemberModel {
/// ///
pub state_changed_at: Option<i64>, pub state_changed_at: Option<i64>,
/// ///
pub bank_account: Option<MemberBankAccountModel>,
///
pub referrer_member: Option<_Member>, pub referrer_member: Option<_Member>,
/// ///
pub referred_count: i64, pub referred_count: i64,
@ -99,6 +99,7 @@ impl QueryableByName<diesel::pg::Pg> for MemberModel {
bank, bank,
name: row.get("mba_name")?, name: row.get("mba_name")?,
account_number: row.get("mba_account_number")?, account_number: row.get("mba_account_number")?,
exchange_password: row.get("mba_exchange_password")?,
memo: row.get("mba_memo")?, memo: row.get("mba_memo")?,
created_at: row.get("mba_created_at")?, created_at: row.get("mba_created_at")?,
updated_at: row.get("mba_updated_at")?, updated_at: row.get("mba_updated_at")?,
@ -167,6 +168,8 @@ pub struct MemberBankAccountModel {
/// ///
pub account_number: String, pub account_number: String,
/// ///
pub exchange_password: String,
///
pub memo: Option<String>, pub memo: Option<String>,
/// ///
pub created_at: i64, pub created_at: i64,

View File

@ -16,6 +16,8 @@ pub struct MemberBankAccount {
/// ///
pub account_number: String, pub account_number: String,
/// ///
pub exchange_password: String,
///
pub memo: Option<String>, pub memo: Option<String>,
/// ///
pub created_at: i64, pub created_at: i64,
@ -36,6 +38,8 @@ pub struct NewMemberBankAccount {
/// ///
pub account_number: String, pub account_number: String,
/// ///
pub exchange_password: String,
///
pub memo: Option<String>, pub memo: Option<String>,
} }
@ -50,6 +54,8 @@ pub struct ModifyMemberBankAccount {
/// ///
pub account_number: String, pub account_number: String,
/// ///
pub exchange_password: String,
///
pub memo: Option<String>, pub memo: Option<String>,
} }

View File

@ -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( pub fn select_all_count(
&self, &self,

View File

@ -15,6 +15,8 @@ table! {
/// ///
account_number -> Text, account_number -> Text,
/// ///
exchange_password -> Text,
///
memo -> Nullable<Text>, memo -> Nullable<Text>,
/// ///
created_at -> BigInt, created_at -> BigInt,

View File

@ -62,6 +62,10 @@ impl From<&compositions::member::models::MemberModel> for bpr::models::member::M
member_level: Some(bpr::models::member_level::MemberLevel::from( member_level: Some(bpr::models::member_level::MemberLevel::from(
&d.member_level, &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: d
.referrer_member .referrer_member
.as_ref() .as_ref()

View File

@ -343,6 +343,7 @@ impl Service<'_> {
bank_id, bank_id,
name: a.name, name: a.name,
account_number: a.account_number, account_number: a.account_number,
exchange_password: a.exchange_password,
memo: None, memo: None,
}; };
self 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 { let modify_member = repositories::member::models::ModifyMember {
site_id, site_id,
member_level_id, member_level_id,
password: request.password, password: password_hash,
mobile_phone_number: request.mobile_phone_number, 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| { let m = self.member_composition.select(&conn, id).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,

View File

@ -1,4 +1,4 @@
use crate::repositories; use crate::{compositions, repositories};
use beteran_protobuf_rust as bpr; use beteran_protobuf_rust as bpr;
impl From<&repositories::member_bank_account::models::MemberBankAccount> 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(), bank_id: d.bank_id.to_string(),
name: d.name.clone(), name: d.name.clone(),
account_number: d.account_number.to_string(), 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(), memo: d.memo.clone(),
created_at: d.created_at as u64, created_at: d.created_at as u64,
updated_at: d.updated_at as u64, updated_at: d.updated_at as u64,

View File

@ -188,6 +188,7 @@ impl Service {
bank_id, bank_id,
name: request.name, name: request.name,
account_number: request.account_number, account_number: request.account_number,
exchange_password: request.exchange_password,
memo: request.memo, memo: request.memo,
}, },
) )
@ -658,10 +659,11 @@ impl Service {
&conn, &conn,
id, id,
&repositories::member_bank_account::models::ModifyMemberBankAccount { &repositories::member_bank_account::models::ModifyMemberBankAccount {
name: request.name,
memo: request.memo,
bank_id, bank_id,
name: request.name,
account_number: request.account_number, account_number: request.account_number,
exchange_password: request.exchange_password,
memo: request.memo,
}, },
) )
.map_err(|e| { .map_err(|e| {