diff --git a/Cargo.toml b/Cargo.toml index e937594..86810d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/migrations/202207011100_member_bank_account/up.sql b/migrations/202207011100_member_bank_account/up.sql index c903f6f..47df3f4 100644 --- a/migrations/202207011100_member_bank_account/up.sql +++ b/migrations/202207011100_member_bank_account/up.sql @@ -1,12 +1,13 @@ CREATE TABLE IF NOT EXISTS member_bank_accounts ( - id UUID DEFAULT uuid_generate_v4(), - member_id UUID NOT NULL, - bank_id UUID NOT NULL, - name TEXT NOT NULL, - account_number 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), + id UUID DEFAULT uuid_generate_v4(), + member_id UUID NOT NULL, + 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), PRIMARY KEY (id), CONSTRAINT fk_member_bank_accounts_member_id FOREIGN KEY(member_id) diff --git a/src/compositions/member/composition.rs b/src/compositions/member/composition.rs index 4838c67..621e52b 100644 --- a/src/compositions/member/composition.rs +++ b/src/compositions/member/composition.rs @@ -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, diff --git a/src/compositions/member/models.rs b/src/compositions/member/models.rs index 4a881b9..4a92db7 100644 --- a/src/compositions/member/models.rs +++ b/src/compositions/member/models.rs @@ -19,6 +19,8 @@ pub struct MemberModel { /// pub member_level: _MemberLevel, /// + pub bank_account: Option, + /// pub username: String, /// pub password: String, @@ -31,8 +33,6 @@ pub struct MemberModel { /// pub state_changed_at: Option, /// - pub bank_account: Option, - /// pub referrer_member: Option<_Member>, /// pub referred_count: i64, @@ -99,6 +99,7 @@ impl QueryableByName 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, /// pub created_at: i64, diff --git a/src/repositories/member_bank_account/models.rs b/src/repositories/member_bank_account/models.rs index a502ef1..9234595 100644 --- a/src/repositories/member_bank_account/models.rs +++ b/src/repositories/member_bank_account/models.rs @@ -16,6 +16,8 @@ pub struct MemberBankAccount { /// pub account_number: String, /// + pub exchange_password: String, + /// pub memo: Option, /// pub created_at: i64, @@ -36,6 +38,8 @@ pub struct NewMemberBankAccount { /// pub account_number: String, /// + pub exchange_password: String, + /// pub memo: Option, } @@ -50,6 +54,8 @@ pub struct ModifyMemberBankAccount { /// pub account_number: String, /// + pub exchange_password: String, + /// pub memo: Option, } diff --git a/src/repositories/member_bank_account/repository.rs b/src/repositories/member_bank_account/repository.rs index af31c11..b4f74e7 100644 --- a/src/repositories/member_bank_account/repository.rs +++ b/src/repositories/member_bank_account/repository.rs @@ -58,6 +58,26 @@ impl Repository { } } + /// + pub fn select_by_member_id( + &self, + conn: &diesel::PgConnection, + member_id: uuid::Uuid, + ) -> Result, Error> { + use member_bank_accounts::dsl; + + match member_bank_accounts::table + .filter(dsl::member_id.eq(member_id)) + .first::(conn) + { + Ok(m) => Ok(Some(m)), + Err(e) => match e { + diesel::result::Error::NotFound => Ok(None), + _ => Err(e), + }, + } + } + /// pub fn select_all_count( &self, diff --git a/src/repositories/member_bank_account/schema.rs b/src/repositories/member_bank_account/schema.rs index 410d4a4..113819e 100644 --- a/src/repositories/member_bank_account/schema.rs +++ b/src/repositories/member_bank_account/schema.rs @@ -15,6 +15,8 @@ table! { /// account_number -> Text, /// + exchange_password -> Text, + /// memo -> Nullable, /// created_at -> BigInt, diff --git a/src/services/member/models.rs b/src/services/member/models.rs index 8965a87..10733dc 100644 --- a/src/services/member/models.rs +++ b/src/services/member/models.rs @@ -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() diff --git a/src/services/member/service.rs b/src/services/member/service.rs index 467f99e..baf4c78 100644 --- a/src/services/member/service.rs +++ b/src/services/member/service.rs @@ -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, diff --git a/src/services/member_bank_account/models.rs b/src/services/member_bank_account/models.rs index 6e83660..1568684 100644 --- a/src/services/member_bank_account/models.rs +++ b/src/services/member_bank_account/models.rs @@ -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, diff --git a/src/services/member_bank_account/service.rs b/src/services/member_bank_account/service.rs index a2f4dec..9dbff96 100644 --- a/src/services/member_bank_account/service.rs +++ b/src/services/member_bank_account/service.rs @@ -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| {