From 629527eebffb24066acd83373c825add63c03925 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Wed, 24 Aug 2022 06:38:09 +0000 Subject: [PATCH] member, member_bank_account are modified --- Cargo.toml | 4 +- src/repositories/member/models.rs | 10 +- src/repositories/member/repository.rs | 15 ++ .../member_bank_account/models.rs | 10 +- .../member_bank_account/repository.rs | 15 ++ src/services/bank/service.rs | 4 +- src/services/member/service.rs | 182 ++++++++++++++---- src/services/member_bank_account/service.rs | 151 ++++++++++++++- src/services/member_bank_deposit/service.rs | 4 +- src/services/member_bank_withdraw/service.rs | 4 +- src/services/member_class/service.rs | 4 +- src/services/member_game_setting/service.rs | 4 +- src/services/member_level/service.rs | 4 +- .../member_settlement_setting/service.rs | 4 +- 14 files changed, 359 insertions(+), 56 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f201ca1..ddea4dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,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.72-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.56-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.73-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.57-snapshot" } [build-dependencies] diff --git a/src/repositories/member/models.rs b/src/repositories/member/models.rs index 9ddd655..9fa40de 100644 --- a/src/repositories/member/models.rs +++ b/src/repositories/member/models.rs @@ -72,11 +72,17 @@ pub struct ModifyMember { /// pub member_level_id: Option, /// - pub password: Option, - /// pub mobile_phone_number: Option, } +/// +#[derive(AsChangeset, Debug, Clone)] +#[table_name = "members"] +pub struct ModifyMemberForPassword { + /// + pub password: String, +} + /// #[derive(AsChangeset, Debug, Clone)] #[table_name = "members"] diff --git a/src/repositories/member/repository.rs b/src/repositories/member/repository.rs index 6489b4b..33d6421 100644 --- a/src/repositories/member/repository.rs +++ b/src/repositories/member/repository.rs @@ -275,6 +275,21 @@ impl Repository { .map(|c| c as u64) } + /// + pub fn update_password( + &self, + conn: &diesel::PgConnection, + id: uuid::Uuid, + modify: &models::ModifyMemberForPassword, + ) -> Result { + use members::dsl; + + diesel::update(dsl::members.filter(dsl::id.eq(id))) + .set(modify) + .execute(conn) + .map(|c| c as u64) + } + /// pub fn update_state( &self, diff --git a/src/repositories/member_bank_account/models.rs b/src/repositories/member_bank_account/models.rs index 9234595..fdc945e 100644 --- a/src/repositories/member_bank_account/models.rs +++ b/src/repositories/member_bank_account/models.rs @@ -54,11 +54,17 @@ pub struct ModifyMemberBankAccount { /// pub account_number: String, /// - pub exchange_password: String, - /// pub memo: Option, } +/// +#[derive(AsChangeset, Debug, Clone)] +#[table_name = "member_bank_accounts"] +pub struct ModifyMemberBankAccountForExchangePassword { + /// + pub exchange_password: String, +} + /// #[derive(Debug, Clone)] pub struct FindAllSearch { diff --git a/src/repositories/member_bank_account/repository.rs b/src/repositories/member_bank_account/repository.rs index b4f74e7..71ff778 100644 --- a/src/repositories/member_bank_account/repository.rs +++ b/src/repositories/member_bank_account/repository.rs @@ -197,6 +197,21 @@ impl Repository { .map(|c| c as u64) } + /// + pub fn update_exchange_password( + &self, + conn: &diesel::PgConnection, + id: uuid::Uuid, + modify: &models::ModifyMemberBankAccountForExchangePassword, + ) -> Result { + use member_bank_accounts::dsl; + + diesel::update(dsl::member_bank_accounts.filter(dsl::id.eq(id))) + .set(modify) + .execute(conn) + .map(|c| c as u64) + } + /// pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result { use member_bank_accounts::dsl; diff --git a/src/services/bank/service.rs b/src/services/bank/service.rs index e865ea3..58772f4 100644 --- a/src/services/bank/service.rs +++ b/src/services/bank/service.rs @@ -283,12 +283,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member/service.rs b/src/services/member/service.rs index f53eff6..e58c831 100644 --- a/src/services/member/service.rs +++ b/src/services/member/service.rs @@ -70,6 +70,7 @@ impl Service<'_> { self.get_member(), self.get_member_by_username(), self.update_member(), + self.update_member_for_password(), self.update_member_for_state(), self.delete_member(), ) @@ -1153,28 +1154,9 @@ 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: password_hash, mobile_phone_number: request.mobile_phone_number, }; @@ -1216,25 +1198,11 @@ impl Service<'_> { }) })?; - let exchange_password_hash = argon2::hash_encoded( - a.exchange_password.as_bytes(), - self.password_salt.as_bytes(), - &self.argon2_config, - ) - .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 modify_member_bank_account = repositories::member_bank_account::models::ModifyMemberBankAccount { bank_id, name: a.name, account_number: a.account_number, - exchange_password: exchange_password_hash, memo: None, }; self @@ -1385,6 +1353,154 @@ impl Service<'_> { Ok(()) } + async fn update_member_for_password(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::ss::member::SUBJECT_UPDATE_MEMBER_FOR_PASSWORD, + self.queue_broker.as_str(), + ) + .await?; + + while let Some(message) = s.next().await { + if let Err(e) = async { + let req = bpr::ss::member::UpdateMemberForPasswordRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let client = match req.client { + Some(c) => c, + None => { + return Err(bcr::error::rpc::Error::InvalidParams( + bcr::error::rpc::InvalidParams { + message: "invalid client information".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "client".to_string(), + value: "".to_string(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: "".to_string(), + }, + }, + )); + } + }; + let request = match req.request { + Some(r) => r, + None => { + return Err(bcr::error::rpc::Error::InvalidParams( + bcr::error::rpc::InvalidParams { + message: "invalid request information".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "request".to_string(), + value: "".to_string(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: "".to_string(), + }, + }, + )); + } + }; + + let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| { + bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams { + message: "invalid id param".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "id".to_string(), + value: request.id.clone(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: e.to_string(), + }, + }) + })?; + + let conn = self.pool.get().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 password_hash = match argon2::hash_encoded( + request.password.as_bytes(), + self.password_salt.as_bytes(), + &self.argon2_config, + ) { + Ok(p) => 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, + })); + } + }; + + let modify_member_for_password = repositories::member::models::ModifyMemberForPassword { + password: password_hash, + }; + + let _affected = self + .member_repository + .update_password(&conn, id, &modify_member_for_password) + .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, + message: format!("server {}", e), + data: None, + }) + })?; + + message + .respond( + bpr::ss::member::UpdateMemberForPasswordResponse { + error: None, + result: Some(bpr::ss::member::update_member_for_password_response::Result {}), + } + .encode_to_vec(), + ) + .await + .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, + }) + })?; + + Ok::<(), bcr::error::rpc::Error>(()) + } + .await + { + message + .respond( + bpr::ss::member::UpdateMemberForPasswordResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + async fn update_member_for_state(&self) -> Result<(), Box> { let s = self .connection_broker diff --git a/src/services/member_bank_account/service.rs b/src/services/member_bank_account/service.rs index 3a7f3ce..3c9c3d5 100644 --- a/src/services/member_bank_account/service.rs +++ b/src/services/member_bank_account/service.rs @@ -54,6 +54,7 @@ impl Service { self.list_member_bank_accounts(), self.get_member_bank_account(), self.update_member_bank_account(), + self.update_member_bank_account_for_exchange_password(), self.delete_member_bank_account(), ) .map(|_| ()) @@ -363,12 +364,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; @@ -661,7 +662,6 @@ impl Service { bank_id, name: request.name, account_number: request.account_number, - exchange_password: request.exchange_password, memo: request.memo, }, ) @@ -725,6 +725,151 @@ impl Service { Ok(()) } + async fn update_member_bank_account_for_exchange_password( + &self, + ) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::ss::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT_FOR_EXCHANGE_PASSWORD, + self.queue_broker.as_str(), + ) + .await?; + + while let Some(message) = s.next().await { + if let Err(e) = async { + let req = + bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let client = match req.client { + Some(c) => c, + None => { + return Err(bcr::error::rpc::Error::InvalidParams( + bcr::error::rpc::InvalidParams { + message: "invalid client information".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "client".to_string(), + value: "".to_string(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: "".to_string(), + }, + }, + )); + } + }; + let request = match req.request { + Some(r) => r, + None => { + return Err(bcr::error::rpc::Error::InvalidParams( + bcr::error::rpc::InvalidParams { + message: "invalid request information".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "request".to_string(), + value: "".to_string(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: "".to_string(), + }, + }, + )); + } + }; + let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| { + bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams { + message: "invalid id param".to_string(), + detail: bcr::error::rpc::InvalidParamsDetail { + location: "request".to_string(), + param: "id".to_string(), + value: request.id.clone(), + error_type: bcr::error::rpc::InvalidParamsType::Required, + message: e.to_string(), + }, + }) + })?; + + let conn = self.pool.get().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 _affected = self + .member_bank_account_repository + .update_exchange_password( + &conn, + id, + &repositories::member_bank_account::models::ModifyMemberBankAccountForExchangePassword { + exchange_password: request.exchange_password, + }, + ) + .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 s = self + .member_bank_account_repository + .select(&conn, 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_account::UpdateMemberBankAccountForExchangePasswordResponse { + error: None, + result: Some( + bpr::ss::member_bank_account::update_member_bank_account_for_exchange_password_response::Result { + }, + ), + } + .encode_to_vec(), + ) + .await + .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, + }) + })?; + + Ok::<(), bcr::error::rpc::Error>(()) + } + .await + { + message + .respond( + bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + async fn delete_member_bank_account(&self) -> Result<(), Box> { let s = self .connection_broker diff --git a/src/services/member_bank_deposit/service.rs b/src/services/member_bank_deposit/service.rs index 2c38708..6dec91f 100644 --- a/src/services/member_bank_deposit/service.rs +++ b/src/services/member_bank_deposit/service.rs @@ -332,12 +332,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member_bank_withdraw/service.rs b/src/services/member_bank_withdraw/service.rs index c0d02bf..dc4d655 100644 --- a/src/services/member_bank_withdraw/service.rs +++ b/src/services/member_bank_withdraw/service.rs @@ -335,12 +335,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member_class/service.rs b/src/services/member_class/service.rs index deccd45..2032e78 100644 --- a/src/services/member_class/service.rs +++ b/src/services/member_class/service.rs @@ -299,12 +299,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member_game_setting/service.rs b/src/services/member_game_setting/service.rs index b333729..be4fd07 100644 --- a/src/services/member_game_setting/service.rs +++ b/src/services/member_game_setting/service.rs @@ -326,12 +326,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member_level/service.rs b/src/services/member_level/service.rs index 83617e7..0d192d4 100644 --- a/src/services/member_level/service.rs +++ b/src/services/member_level/service.rs @@ -278,12 +278,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), }; diff --git a/src/services/member_settlement_setting/service.rs b/src/services/member_settlement_setting/service.rs index 7e5c89c..4473af7 100644 --- a/src/services/member_settlement_setting/service.rs +++ b/src/services/member_settlement_setting/service.rs @@ -343,12 +343,12 @@ impl Service { pagination: request .pagination .as_ref() - .map(|d| bcr::models::pagination::Pagination::from(d)), + .map(bcr::models::pagination::Pagination::from), sorts: Some( request .sorts .iter() - .map(|d| beteran_common_rust::models::pagination::Sort::from(d)) + .map(beteran_common_rust::models::pagination::Sort::from) .collect(), ), };