From d098634d947a9092235fcdb868d8e4ad190ded21 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Wed, 24 Aug 2022 07:15:08 +0000 Subject: [PATCH] member, member_bank_account are modified --- Cargo.toml | 4 +- src/member/service.rs | 211 ++++++++++++++++++++++++++++- src/member_bank_account/service.rs | 104 +++++++++++++- 3 files changed, 314 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c74c39..2aa28ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ prost = { version = "0" } nats = { version = "0" } base64 = { version = "0" } -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.74-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.58-snapshot" } [build-dependencies] diff --git a/src/member/service.rs b/src/member/service.rs index e7232b9..f351f62 100644 --- a/src/member/service.rs +++ b/src/member/service.rs @@ -31,6 +31,8 @@ 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(), ) .map(|_| ()) @@ -150,6 +152,7 @@ impl Service { username: req.username, password: req.password, nickname: req.nickname, + state: bpr::models::member::MemberState::Normal as i32, bank_account, game_setting, settlement_setting, @@ -569,7 +572,7 @@ impl Service { bank_id: a.bank_id, name: a.name, account_number: a.account_number, - exchange_password: a.exchange_password, + memo: a.memo, }, ), None => None, @@ -625,7 +628,6 @@ impl Service { id: req.id, site_id: req.site_id, member_level_id: req.member_level_id, - password: req.password, mobile_phone_number: req.mobile_phone_number, bank_account, game_setting, @@ -706,6 +708,211 @@ impl Service { Ok(()) } + async fn update_member_for_password(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::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 client = self.get_client_in_header(&message)?; + + let req = + bpr::c2se::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 ss_update_member_req = bpr::ss::member::UpdateMemberForPasswordRequest { + client: Some(client), + request: Some( + bpr::ss::member::update_member_for_password_request::Request { + id: req.id, + password: req.password, + }, + ), + }; + + let ss_update_member_res_msg = self + .connection_broker + .request( + bpr::ss::member::SUBJECT_UPDATE_MEMBER_FOR_PASSWORD, + ss_update_member_req.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, + }) + })?; + + let ss_update_member_res = bpr::ss::member::UpdateMemberForPasswordResponse::decode( + ss_update_member_res_msg.data.as_slice(), + ) + .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, + }) + })?; + + if let Some(e) = ss_update_member_res.error { + return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + })); + } + + if let Some(r) = ss_update_member_res.result { + message + .respond( + bpr::c2se::member::UpdateMemberForPasswordResponse { + error: None, + result: Some(bpr::c2se::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::c2se::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 + .queue_subscribe( + bpr::c2se::backend::member::SUBJECT_UPDATE_MEMBER_FOR_STATE, + self.queue_broker.as_str(), + ) + .await?; + + while let Some(message) = s.next().await { + if let Err(e) = async { + let client = self.get_client_in_header(&message)?; + + let req = bpr::c2se::member::UpdateMemberForStateRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_update_member_req = bpr::ss::member::UpdateMemberForStateRequest { + client: Some(client), + request: Some(bpr::ss::member::update_member_for_state_request::Request { + id: req.id, + state: req.state, + }), + }; + + let ss_update_member_res_msg = self + .connection_broker + .request( + bpr::ss::member::SUBJECT_UPDATE_MEMBER_FOR_STATE, + ss_update_member_req.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, + }) + })?; + + let ss_update_member_res = bpr::ss::member::UpdateMemberForStateResponse::decode( + ss_update_member_res_msg.data.as_slice(), + ) + .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, + }) + })?; + + if let Some(e) = ss_update_member_res.error { + return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + })); + } + + if let Some(r) = ss_update_member_res.result { + message + .respond( + bpr::c2se::member::UpdateMemberForStateResponse { + error: None, + result: Some( + bpr::c2se::member::update_member_for_state_response::Result { member: r.member }, + ), + } + .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::c2se::member::UpdateMemberForStateResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + async fn delete_member(&self) -> Result<(), Box> { let s = self .connection_broker diff --git a/src/member_bank_account/service.rs b/src/member_bank_account/service.rs index 3d8982a..8fa9240 100644 --- a/src/member_bank_account/service.rs +++ b/src/member_bank_account/service.rs @@ -30,6 +30,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(|_| ()) @@ -421,7 +422,6 @@ impl Service { bank_id: req.bank_id, name: req.name, account_number: req.account_number, - exchange_password: req.exchange_password, memo: req.memo, }) @@ -501,6 +501,108 @@ impl Service { Ok(()) } + async fn update_member_bank_account_for_exchange_password(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::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 client = self.get_client_in_header(&message)?; + + let req = bpr::c2se::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 ss_update_member_bank_account_req = bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_account::update_member_bank_account_for_exchange_password_request::Request{ + id: req.id, + exchange_password: req.exchange_password, + + }) + }; + + let ss_update_member_bank_account_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT_FOR_EXCHANGE_PASSWORD, + ss_update_member_bank_account_req.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, + }) + })?; + + let ss_update_member_bank_account_res = bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordResponse::decode( + ss_update_member_bank_account_res_msg.data.as_slice(), + ) + .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, + }) + })?; + + if let Some(e) = ss_update_member_bank_account_res.error { + return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + })); + } + + if let Some(r) = ss_update_member_bank_account_res.result { + message + .respond( + bpr::c2se::member_bank_account::UpdateMemberBankAccountForExchangePasswordResponse { + error: None, + result: Some(bpr::c2se::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::c2se::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