diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b04611b..a9c65f1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -28,20 +28,18 @@ "extensions": [ "donjayamanne.githistory", "eamodio.gitlens", - "matklad.rust-analyzer", "mhutchie.git-graph", "ms-azuretools.vscode-docker", "mutantdino.resourcemonitor", + "rust-lang.rust-analyzer", "serayuzgur.crates", "tamasfe.even-better-toml", "vadimcn.vscode-lldb" ] } }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "docker --version", "postCreateCommand": "bash ./.devcontainer/scripts/postCreateCommand.sh", diff --git a/Cargo.toml b/Cargo.toml index 3fb2693..badc5c2 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.43-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.26-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.49-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.32-snapshot" } [build-dependencies] diff --git a/src/bank/mod.rs b/src/bank/mod.rs new file mode 100644 index 0000000..1f278a4 --- /dev/null +++ b/src/bank/mod.rs @@ -0,0 +1 @@ +pub mod service; diff --git a/src/bank/service.rs b/src/bank/service.rs new file mode 100644 index 0000000..14a2a8d --- /dev/null +++ b/src/bank/service.rs @@ -0,0 +1,578 @@ +use beteran_common_rust as bcr; +use beteran_protobuf_rust as bpr; +use prost::Message; + +/// +pub struct Service { + connection_broker: nats::asynk::Connection, + queue_broker: String, +} + +impl std::fmt::Debug for Service { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("beteran-backend-server-edge::bank::service::Service") + .finish() + } +} + +impl Service { + /// + pub fn new(connection_broker: nats::asynk::Connection, queue_broker: String) -> Service { + Service { + connection_broker, + queue_broker, + } + } + + pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { + futures::try_join!( + self.create_bank(), + self.list_banks(), + self.get_bank(), + self.update_bank(), + self.delete_bank(), + ) + .map(|_| ()) + } + + fn get_client_in_header( + &self, + message: &nats::asynk::Message, + ) -> Result { + match &message.headers { + Some(headers) => { + let client = match headers.get(bpr::c2se::core::network::HEADER_CLIENT) { + Some(c) => { + let msg = base64::decode(c).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })?; + bpr::models::core::network::Client::decode(msg.as_slice()).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })? + } + None => { + return Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid client information".to_string(), + })); + } + }; + + Ok(client) + } + None => Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid header".to_string(), + })), + } + } + + async fn create_bank(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::bank::SUBJECT_CREATE_BANK, + 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::bank::CreateBankRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_create_bank_req = bpr::ss::bank::CreateBankRequest { + client: Some(client), + request: Some(bpr::ss::bank::create_bank_request::Request { + name: req.name, + sort_order: req.sort_order, + show: req.show, + can_use: req.can_use, + memo: req.memo, + }), + }; + + let ss_create_bank_res_msg = self + .connection_broker + .request( + bpr::ss::bank::SUBJECT_CREATE_BANK, + ss_create_bank_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_create_bank_res = + bpr::ss::bank::CreateBankResponse::decode(ss_create_bank_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_create_bank_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_create_bank_res.result { + message + .respond( + bpr::c2se::bank::CreateBankResponse { + error: None, + result: Some(bpr::c2se::bank::create_bank_response::Result { bank: r.bank }), + } + .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::bank::CreateBankResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn list_banks(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::bank::SUBJECT_LIST_BANKS, + 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::bank::ListBanksRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_list_banks_req = bpr::ss::bank::ListBanksRequest { + client: Some(client), + request: Some(bpr::ss::bank::list_banks_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::bank::list_banks_request::request::Search { + name_like: s.name_like, + show: s.show, + can_use: s.can_use, + memo_like: s.memo_like, + }), + None => None, + }, + }), + }; + + let ss_list_banks_res_msg = self + .connection_broker + .request( + bpr::ss::bank::SUBJECT_LIST_BANKS, + ss_list_banks_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_list_banks_res = bpr::ss::bank::ListBanksResponse::decode( + ss_list_banks_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_list_banks_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_list_banks_res.result { + message + .respond( + bpr::c2se::bank::ListBanksResponse { + error: None, + result: Some(bpr::c2se::bank::list_banks_response::Result { banks: r.banks }), + } + .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::bank::ListBanksResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_bank(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::bank::SUBJECT_GET_BANK, + 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::bank::GetBankRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_bank_req = bpr::ss::bank::GetBankRequest { + client: Some(client), + request: Some(bpr::ss::bank::get_bank_request::Request { id: req.id }), + }; + + let ss_get_bank_res_msg = self + .connection_broker + .request( + bpr::ss::bank::SUBJECT_GET_BANK, + ss_get_bank_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_get_bank_res = bpr::ss::bank::GetBankResponse::decode( + ss_get_bank_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_get_bank_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_get_bank_res.result { + message + .respond( + bpr::c2se::bank::GetBankResponse { + error: None, + result: Some(bpr::c2se::bank::get_bank_response::Result { bank: r.bank }), + } + .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::bank::GetBankResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_bank(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::bank::SUBJECT_UPDATE_BANK, + 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::bank::UpdateBankRequest::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_bank_req = bpr::ss::bank::UpdateBankRequest { + client: Some(client), + request: Some(bpr::ss::bank::update_bank_request::Request { + id: req.id, + name: req.name, + sort_order: req.sort_order, + show: req.show, + can_use: req.can_use, + memo: req.memo, + }), + }; + + let ss_update_bank_res_msg = self + .connection_broker + .request( + bpr::ss::bank::SUBJECT_UPDATE_BANK, + ss_update_bank_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_bank_res = + bpr::ss::bank::UpdateBankResponse::decode(ss_update_bank_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_bank_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_bank_res.result { + message + .respond( + bpr::c2se::bank::UpdateBankResponse { + error: None, + result: Some(bpr::c2se::bank::update_bank_response::Result { bank: r.bank }), + } + .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::bank::UpdateBankResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn delete_bank(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::bank::SUBJECT_DELETE_BANK, + 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::bank::DeleteBankRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_delete_bank_req = bpr::ss::bank::DeleteBankRequest { + client: Some(client), + request: Some(bpr::ss::bank::delete_bank_request::Request { id: req.id }), + }; + + let ss_delete_bank_res_msg = self + .connection_broker + .request( + bpr::ss::bank::SUBJECT_DELETE_BANK, + ss_delete_bank_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_delete_bank_res = + bpr::ss::bank::DeleteBankResponse::decode(ss_delete_bank_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_delete_bank_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_delete_bank_res.result { + message + .respond( + bpr::c2se::bank::DeleteBankResponse { + error: None, + result: Some(bpr::c2se::bank::delete_bank_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::bank::DeleteBankResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } +} diff --git a/src/identity/service.rs b/src/identity/service.rs index f690d00..af95051 100644 --- a/src/identity/service.rs +++ b/src/identity/service.rs @@ -81,25 +81,28 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::common::identity::CheckUsernameForDuplicationRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::identity::CheckUsernameForDuplicationRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; let ss_check_username_for_duplication_req = - bpr::ss::member::identity::CheckUsernameForDuplicationRequest { + bpr::ss::identity::CheckUsernameForDuplicationRequest { client: Some(client), - username: req.username, + request: Some( + bpr::ss::identity::check_username_for_duplication_request::Request { + username: req.username, + }, + ), }; let ss_check_username_for_duplication_res_msg = self .connection_broker .request( - bpr::ss::member::identity::SUBJECT_CHECK_USERNAME_FOR_DUPLICATION, + bpr::ss::identity::SUBJECT_CHECK_USERNAME_FOR_DUPLICATION, ss_check_username_for_duplication_req.encode_to_vec(), ) .await @@ -112,7 +115,7 @@ impl Service { })?; let ss_check_username_for_duplication_res = - bpr::ss::member::identity::CheckUsernameForDuplicationResponse::decode( + bpr::ss::identity::CheckUsernameForDuplicationResponse::decode( ss_check_username_for_duplication_res_msg.data.as_slice(), ) .map_err(|e| { @@ -134,10 +137,10 @@ impl Service { if let Some(r) = ss_check_username_for_duplication_res.result { message .respond( - bpr::c2se::common::identity::CheckUsernameForDuplicationResponse { + bpr::c2se::identity::CheckUsernameForDuplicationResponse { error: None, result: Some( - bpr::c2se::common::identity::check_username_for_duplication_response::Result { + bpr::c2se::identity::check_username_for_duplication_response::Result { duplicated: r.duplicated, }, ), @@ -160,7 +163,7 @@ impl Service { { message .respond( - bpr::c2se::common::identity::CheckUsernameForDuplicationResponse { + bpr::c2se::identity::CheckUsernameForDuplicationResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -186,25 +189,28 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::common::identity::CheckNicknameForDuplicationRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::identity::CheckNicknameForDuplicationRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; let ss_check_nickname_for_duplication_req = - bpr::ss::member::identity::CheckNicknameForDuplicationRequest { + bpr::ss::identity::CheckNicknameForDuplicationRequest { client: Some(client), - nickname: req.nickname, + request: Some( + bpr::ss::identity::check_nickname_for_duplication_request::Request { + nickname: req.nickname, + }, + ), }; let ss_check_nickname_for_duplication_res_msg = self .connection_broker .request( - bpr::ss::member::identity::SUBJECT_CHECK_NICKNAME_FOR_DUPLICATION, + bpr::ss::identity::SUBJECT_CHECK_NICKNAME_FOR_DUPLICATION, ss_check_nickname_for_duplication_req.encode_to_vec(), ) .await @@ -217,7 +223,7 @@ impl Service { })?; let ss_check_nickname_for_duplication_res = - bpr::ss::member::identity::CheckNicknameForDuplicationResponse::decode( + bpr::ss::identity::CheckNicknameForDuplicationResponse::decode( ss_check_nickname_for_duplication_res_msg.data.as_slice(), ) .map_err(|e| { @@ -239,10 +245,10 @@ impl Service { if let Some(r) = ss_check_nickname_for_duplication_res.result { message .respond( - bpr::c2se::common::identity::CheckNicknameForDuplicationResponse { + bpr::c2se::identity::CheckNicknameForDuplicationResponse { error: None, result: Some( - bpr::c2se::common::identity::check_nickname_for_duplication_response::Result { + bpr::c2se::identity::check_nickname_for_duplication_response::Result { duplicated: r.duplicated, }, ), @@ -265,7 +271,7 @@ impl Service { { message .respond( - bpr::c2se::common::identity::CheckNicknameForDuplicationResponse { + bpr::c2se::identity::CheckNicknameForDuplicationResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -291,21 +297,22 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let _req = bpr::c2se::common::identity::CaptchaRequest::decode(message.data.as_slice()) - .map_err(|e| { + let _req = + bpr::c2se::identity::CaptchaRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_captcha_req = bpr::ss::member::identity::CaptchaRequest { + let ss_captcha_req = bpr::ss::identity::CaptchaRequest { client: Some(client), + request: Some(bpr::ss::identity::captcha_request::Request {}), }; let ss_captcha_res_msg = self .connection_broker .request( - bpr::ss::member::identity::SUBJECT_CAPTCHA, + bpr::ss::identity::SUBJECT_CAPTCHA, ss_captcha_req.encode_to_vec(), ) .await @@ -317,15 +324,16 @@ impl Service { }) })?; - let ss_captcha_res = - bpr::ss::member::identity::CaptchaResponse::decode(ss_captcha_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, - }) - })?; + let ss_captcha_res = bpr::ss::identity::CaptchaResponse::decode( + ss_captcha_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_captcha_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -338,9 +346,9 @@ impl Service { if let Some(r) = ss_captcha_res.result { message .respond( - bpr::c2se::common::identity::CaptchaResponse { + bpr::c2se::identity::CaptchaResponse { error: None, - result: Some(bpr::c2se::common::identity::captcha_response::Result { + result: Some(bpr::c2se::identity::captcha_response::Result { security_code_hash: r.security_code_hash, image: r.image, }), @@ -363,7 +371,7 @@ impl Service { { message .respond( - bpr::c2se::common::identity::CaptchaResponse { + bpr::c2se::identity::CaptchaResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -389,25 +397,27 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::identity::SigninRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::identity::SigninRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_signin_req = bpr::ss::member::identity::SigninRequest { + let ss_signin_req = bpr::ss::identity::SigninRequest { client: Some(client), - security_code_hash: req.security_code_hash, - security_code: req.security_code, - username: req.username, - password: req.password, + request: Some(bpr::ss::identity::signin_request::Request { + security_code_hash: req.security_code_hash, + security_code: req.security_code, + username: req.username, + password: req.password, + }), }; let ss_signin_res_msg = self .connection_broker .request( - bpr::ss::member::identity::SUBJECT_SIGNIN, + bpr::ss::identity::SUBJECT_SIGNIN, ss_signin_req.encode_to_vec(), ) .await @@ -419,15 +429,16 @@ impl Service { }) })?; - let ss_signin_res = - bpr::ss::member::identity::SigninResponse::decode(ss_signin_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, - }) - })?; + let ss_signin_res = bpr::ss::identity::SigninResponse::decode( + ss_signin_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_signin_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -440,9 +451,9 @@ impl Service { if let Some(r) = ss_signin_res.result { message .respond( - bpr::c2se::backend::identity::SigninResponse { + bpr::c2se::identity::SigninResponse { error: None, - result: Some(bpr::c2se::backend::identity::signin_response::Result { + result: Some(bpr::c2se::identity::signin_response::Result { access_token: r.access_token, }), } @@ -464,7 +475,7 @@ impl Service { { message .respond( - bpr::c2se::backend::identity::SigninResponse { + bpr::c2se::identity::SigninResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } diff --git a/src/main.rs b/src/main.rs index afac4f6..e76ecf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,11 @@ use std::env; +mod bank; mod identity; mod member; +mod member_bank_account; +mod member_bank_deposit; +mod member_bank_withdraw; mod member_class; mod member_level; mod site; @@ -20,24 +24,35 @@ async fn main() -> Result<(), Box> { let broker_opts = nats::asynk::Options::new(); let connection_broker = broker_opts.connect(url_broker).await?; - let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let bank_service = bank::service::Service::new(connection_broker.clone(), queue_broker.clone()); let identity_service = identity::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let member_service = + member::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let member_bank_account_service = + member_bank_account::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let member_bank_deposit_service = + member_bank_deposit::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let member_bank_withdraw_service = + member_bank_withdraw::service::Service::new(connection_broker.clone(), queue_broker.clone()); let member_class_service = member_class::service::Service::new(connection_broker.clone(), queue_broker.clone()); let member_level_service = member_level::service::Service::new(connection_broker.clone(), queue_broker.clone()); - let member_service = - member::service::Service::new(connection_broker.clone(), queue_broker.clone()); + let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone()); println!("Server edge[beteran-backend-server-edge] is started"); futures::try_join!( - site_service.subscribe(), + bank_service.subscribe(), identity_service.subscribe(), + member_service.subscribe(), + member_bank_account_service.subscribe(), + member_bank_deposit_service.subscribe(), + member_bank_withdraw_service.subscribe(), member_class_service.subscribe(), member_level_service.subscribe(), - member_service.subscribe(), + site_service.subscribe(), )?; Ok(()) diff --git a/src/member/service.rs b/src/member/service.rs index 742927b..8154076 100644 --- a/src/member/service.rs +++ b/src/member/service.rs @@ -83,30 +83,32 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member::CreateMemberRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::member::CreateMemberRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_create_member_req = bpr::ss::member::member::CreateMemberRequest { + let ss_create_member_req = bpr::ss::member::CreateMemberRequest { client: Some(client), - site_id: req.site_id, - member_level_id: req.member_level_id, - mobile_phone_number: req.mobile_phone_number, - member_class_id: req.member_class_id, - referrer_member_username: req.referrer_member_username, - username: req.username, - password: req.password, - nickname: req.nickname, - state: req.state, + request: Some(bpr::ss::member::create_member_request::Request { + site_id: req.site_id, + member_level_id: req.member_level_id, + mobile_phone_number: req.mobile_phone_number, + member_class_id: req.member_class_id, + referrer_member_username: req.referrer_member_username, + username: req.username, + password: req.password, + nickname: req.nickname, + state: req.state, + }), }; let ss_create_member_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_CREATE_MEMBER, + bpr::ss::member::SUBJECT_CREATE_MEMBER, ss_create_member_req.encode_to_vec(), ) .await @@ -118,16 +120,15 @@ impl Service { }) })?; - let ss_create_member_res = bpr::ss::member::member::CreateMemberResponse::decode( - ss_create_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, - }) - })?; + let ss_create_member_res = + bpr::ss::member::CreateMemberResponse::decode(ss_create_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_create_member_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -140,9 +141,9 @@ impl Service { if let Some(r) = ss_create_member_res.result { message .respond( - bpr::c2se::backend::member::CreateMemberResponse { + bpr::c2se::member::CreateMemberResponse { error: None, - result: Some(bpr::c2se::backend::member::create_member_response::Result { + result: Some(bpr::c2se::member::create_member_response::Result { member: r.member, }), } @@ -164,7 +165,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::CreateMemberResponse { + bpr::c2se::member::CreateMemberResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -190,34 +191,40 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member::ListMembersRequest::decode(message.data.as_slice()) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member::ListMembersRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_list_members_req = bpr::ss::member::member::ListMembersRequest { + let ss_list_members_req = bpr::ss::member::ListMembersRequest { client: Some(client), - pagination: req.pagination, - searches: req.searches, - sorts: req.sorts, - site_id: req.site_id, - member_class_id: req.member_class_id, - member_level_id: req.member_level_id, - referrer_member_id: req.referrer_member_id, - username_like: req.username_like, - nickname_like: req.nickname_like, - mobile_phone_number_like: req.mobile_phone_number_like, - last_signined_ip: req.last_signined_ip, - state: req.state, - deleted_at: req.deleted_at, + request: Some(bpr::ss::member::list_members_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::member::list_members_request::request::Search { + site_id: s.site_id, + member_class_id: s.member_class_id, + member_level_id: s.member_level_id, + referrer_member_id: s.referrer_member_id, + username_like: s.username_like, + nickname_like: s.nickname_like, + mobile_phone_number_like: s.mobile_phone_number_like, + last_signined_ip: s.last_signined_ip, + state: s.state, + deleted_at: s.deleted_at, + }), + None => None, + }, + }), }; let ss_list_members_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_LIST_MEMBERS, + bpr::ss::member::SUBJECT_LIST_MEMBERS, ss_list_members_req.encode_to_vec(), ) .await @@ -229,16 +236,15 @@ impl Service { }) })?; - let ss_list_members_res = bpr::ss::member::member::ListMembersResponse::decode( - ss_list_members_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, - }) - })?; + let ss_list_members_res = + bpr::ss::member::ListMembersResponse::decode(ss_list_members_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_list_members_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -251,9 +257,9 @@ impl Service { if let Some(r) = ss_list_members_res.result { message .respond( - bpr::c2se::backend::member::ListMembersResponse { + bpr::c2se::member::ListMembersResponse { error: None, - result: Some(bpr::c2se::backend::member::list_members_response::Result { + result: Some(bpr::c2se::member::list_members_response::Result { members: r.members, }), } @@ -275,7 +281,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::ListMembersResponse { + bpr::c2se::member::ListMembersResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -301,22 +307,22 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member::GetMemberRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::member::GetMemberRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_get_member_req = bpr::ss::member::member::GetMemberRequest { + let ss_get_member_req = bpr::ss::member::GetMemberRequest { client: Some(client), - id: req.id, + request: Some(bpr::ss::member::get_member_request::Request { id: req.id }), }; let ss_get_member_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_GET_MEMBER, + bpr::ss::member::SUBJECT_GET_MEMBER, ss_get_member_req.encode_to_vec(), ) .await @@ -329,7 +335,7 @@ impl Service { })?; let ss_get_member_res = - bpr::ss::member::member::GetMemberResponse::decode(ss_get_member_res_msg.data.as_slice()) + bpr::ss::member::GetMemberResponse::decode(ss_get_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, @@ -349,11 +355,9 @@ impl Service { if let Some(r) = ss_get_member_res.result { message .respond( - bpr::c2se::backend::member::GetMemberResponse { + bpr::c2se::member::GetMemberResponse { error: None, - result: Some(bpr::c2se::backend::member::get_member_response::Result { - member: r.member, - }), + result: Some(bpr::c2se::member::get_member_response::Result { member: r.member }), } .encode_to_vec(), ) @@ -373,7 +377,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::GetMemberResponse { + bpr::c2se::member::GetMemberResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -399,23 +403,24 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = - bpr::c2se::backend::member::GetMemberByUsernameRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = bpr::c2se::member::GetMemberByUsernameRequest::decode(message.data.as_slice()) + .map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_get_member_by_username_req = bpr::ss::member::member::GetMemberByUsernameRequest { + let ss_get_member_by_username_req = bpr::ss::member::GetMemberByUsernameRequest { client: Some(client), - username: req.username, + request: Some(bpr::ss::member::get_member_by_username_request::Request { + username: req.username, + }), }; let ss_get_member_by_username_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_GET_MEMBER_BY_USERNAME, + bpr::ss::member::SUBJECT_GET_MEMBER_BY_USERNAME, ss_get_member_by_username_req.encode_to_vec(), ) .await @@ -427,17 +432,16 @@ impl Service { }) })?; - let ss_get_member_by_username_res = - bpr::ss::member::member::GetMemberByUsernameResponse::decode( - ss_get_member_by_username_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, - }) - })?; + let ss_get_member_by_username_res = bpr::ss::member::GetMemberByUsernameResponse::decode( + ss_get_member_by_username_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_get_member_by_username_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -450,13 +454,11 @@ impl Service { if let Some(r) = ss_get_member_by_username_res.result { message .respond( - bpr::c2se::backend::member::GetMemberByUsernameResponse { + bpr::c2se::member::GetMemberByUsernameResponse { error: None, - result: Some( - bpr::c2se::backend::member::get_member_by_username_response::Result { - member: r.member, - }, - ), + result: Some(bpr::c2se::member::get_member_by_username_response::Result { + member: r.member, + }), } .encode_to_vec(), ) @@ -476,7 +478,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::GetMemberByUsernameResponse { + bpr::c2se::member::GetMemberByUsernameResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -502,27 +504,28 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member::UpdateMemberRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::member::UpdateMemberRequest::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::member::UpdateMemberRequest { + let ss_update_member_req = bpr::ss::member::UpdateMemberRequest { client: Some(client), - 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, - state: req.state, + request: Some(bpr::ss::member::update_member_request::Request { + 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, + }), }; let ss_update_member_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_UPDATE_MEMBER, + bpr::ss::member::SUBJECT_UPDATE_MEMBER, ss_update_member_req.encode_to_vec(), ) .await @@ -534,16 +537,15 @@ impl Service { }) })?; - let ss_update_member_res = bpr::ss::member::member::UpdateMemberResponse::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, - }) - })?; + let ss_update_member_res = + bpr::ss::member::UpdateMemberResponse::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 { @@ -556,9 +558,9 @@ impl Service { if let Some(r) = ss_update_member_res.result { message .respond( - bpr::c2se::backend::member::UpdateMemberResponse { + bpr::c2se::member::UpdateMemberResponse { error: None, - result: Some(bpr::c2se::backend::member::update_member_response::Result { + result: Some(bpr::c2se::member::update_member_response::Result { member: r.member, }), } @@ -580,7 +582,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::UpdateMemberResponse { + bpr::c2se::member::UpdateMemberResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -606,22 +608,22 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member::DeleteMemberRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::member::DeleteMemberRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_delete_member_req = bpr::ss::member::member::DeleteMemberRequest { + let ss_delete_member_req = bpr::ss::member::DeleteMemberRequest { client: Some(client), - id: req.id, + request: Some(bpr::ss::member::delete_member_request::Request { id: req.id }), }; let ss_delete_member_res_msg = self .connection_broker .request( - bpr::ss::member::member::SUBJECT_DELETE_MEMBER, + bpr::ss::member::SUBJECT_DELETE_MEMBER, ss_delete_member_req.encode_to_vec(), ) .await @@ -633,16 +635,15 @@ impl Service { }) })?; - let ss_delete_member_res = bpr::ss::member::member::DeleteMemberResponse::decode( - ss_delete_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, - }) - })?; + let ss_delete_member_res = + bpr::ss::member::DeleteMemberResponse::decode(ss_delete_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_delete_member_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -655,9 +656,9 @@ impl Service { if let Some(r) = ss_delete_member_res.result { message .respond( - bpr::c2se::backend::member::DeleteMemberResponse { + bpr::c2se::member::DeleteMemberResponse { error: None, - result: Some(bpr::c2se::backend::member::delete_member_response::Result {}), + result: Some(bpr::c2se::member::delete_member_response::Result {}), } .encode_to_vec(), ) @@ -677,7 +678,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member::DeleteMemberResponse { + bpr::c2se::member::DeleteMemberResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } diff --git a/src/member_bank_account/mod.rs b/src/member_bank_account/mod.rs new file mode 100644 index 0000000..1f278a4 --- /dev/null +++ b/src/member_bank_account/mod.rs @@ -0,0 +1 @@ +pub mod service; diff --git a/src/member_bank_account/service.rs b/src/member_bank_account/service.rs new file mode 100644 index 0000000..5f590c5 --- /dev/null +++ b/src/member_bank_account/service.rs @@ -0,0 +1,601 @@ +use beteran_common_rust as bcr; +use beteran_protobuf_rust as bpr; +use prost::Message; + +/// +pub struct Service { + connection_broker: nats::asynk::Connection, + queue_broker: String, +} + +impl std::fmt::Debug for Service { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("beteran-backend-server-edge::member_bank_account::service::Service") + .finish() + } +} + +impl Service { + /// + pub fn new(connection_broker: nats::asynk::Connection, queue_broker: String) -> Service { + Service { + connection_broker, + queue_broker, + } + } + + pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { + futures::try_join!( + self.create_member_bank_account(), + self.list_member_bank_accounts(), + self.get_member_bank_account(), + self.update_member_bank_account(), + self.delete_member_bank_account(), + ) + .map(|_| ()) + } + + fn get_client_in_header( + &self, + message: &nats::asynk::Message, + ) -> Result { + match &message.headers { + Some(headers) => { + let client = match headers.get(bpr::c2se::core::network::HEADER_CLIENT) { + Some(c) => { + let msg = base64::decode(c).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })?; + bpr::models::core::network::Client::decode(msg.as_slice()).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })? + } + None => { + return Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid client information".to_string(), + })); + } + }; + + Ok(client) + } + None => Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid header".to_string(), + })), + } + } + + async fn create_member_bank_account(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_account::SUBJECT_CREATE_MEMBER_BANK_ACCOUNT, + 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::CreateMemberBankAccountRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_create_member_bank_account_req = + bpr::ss::member_bank_account::CreateMemberBankAccountRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_account::create_member_bank_account_request::Request { + member_id: req.member_id, + bank_id: req.bank_id, + name: req.name, + account_number: req.account_number, + memo: req.memo, + }, + ), + }; + + let ss_create_member_bank_account_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_CREATE_MEMBER_BANK_ACCOUNT, + ss_create_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_create_member_bank_account_res = + bpr::ss::member_bank_account::CreateMemberBankAccountResponse::decode( + ss_create_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_create_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_create_member_bank_account_res.result { + message + .respond( + bpr::c2se::member_bank_account::CreateMemberBankAccountResponse { + error: None, + result: Some( + bpr::c2se::member_bank_account::create_member_bank_account_response::Result { + member_bank_account: r.member_bank_account, + }, + ), + } + .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::CreateMemberBankAccountResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn list_member_bank_accounts(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_account::SUBJECT_LIST_MEMBER_BANK_ACCOUNTS, + 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::ListMemberBankAccountsRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_list_member_bank_accounts_req = bpr::ss::member_bank_account::ListMemberBankAccountsRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_account::list_member_bank_accounts_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::member_bank_account::list_member_bank_accounts_request::request::Search{ + member_id: s.member_id, + bank_id: s.bank_id, + name_like: s.name_like, + memo_like: s.memo_like, + account_number_like: s.account_number_like, + }), + None => None, + } + + }) + + }; + + let ss_list_member_bank_accounts_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_LIST_MEMBER_BANK_ACCOUNTS, + ss_list_member_bank_accounts_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_list_member_bank_accounts_res = + bpr::ss::member_bank_account::ListMemberBankAccountsResponse::decode(ss_list_member_bank_accounts_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_list_member_bank_accounts_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_list_member_bank_accounts_res.result { + message + .respond( + bpr::c2se::member_bank_account::ListMemberBankAccountsResponse { + error: None, + result: Some(bpr::c2se::member_bank_account::list_member_bank_accounts_response::Result { + member_bank_accounts: r.member_bank_accounts, + }), + } + .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::ListMemberBankAccountsResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_member_bank_account(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_account::SUBJECT_GET_MEMBER_BANK_ACCOUNT, + 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::GetMemberBankAccountRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_member_bank_account_req = bpr::ss::member_bank_account::GetMemberBankAccountRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_account::get_member_bank_account_request::Request{ + id: req.id, + }) + }; + + let ss_get_member_bank_account_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_GET_MEMBER_BANK_ACCOUNT, + ss_get_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_get_member_bank_account_res = + bpr::ss::member_bank_account::GetMemberBankAccountResponse::decode(ss_get_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_get_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_get_member_bank_account_res.result { + message + .respond( + bpr::c2se::member_bank_account::GetMemberBankAccountResponse { + error: None, + result: Some(bpr::c2se::member_bank_account::get_member_bank_account_response::Result { member_bank_account: r.member_bank_account }), + } + .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::GetMemberBankAccountResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_member_bank_account(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT, + 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::UpdateMemberBankAccountRequest::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::UpdateMemberBankAccountRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_account::update_member_bank_account_request::Request{ + id: req.id, + bank_id: req.bank_id, + name: req.name, + account_number: req.account_number, + memo: req.memo, + + }) + }; + + let ss_update_member_bank_account_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT, + 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::UpdateMemberBankAccountResponse::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::UpdateMemberBankAccountResponse { + error: None, + result: Some(bpr::c2se::member_bank_account::update_member_bank_account_response::Result { + member_bank_account: r.member_bank_account, + }), + } + .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::UpdateMemberBankAccountResponse { + 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 + .queue_subscribe( + bpr::c2se::backend::member_bank_account::SUBJECT_DELETE_MEMBER_BANK_ACCOUNT, + 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::DeleteMemberBankAccountRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_delete_member_bank_account_req = bpr::ss::member_bank_account::DeleteMemberBankAccountRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_account::delete_member_bank_account_request::Request { + id: req.id, + }) + + }; + + let ss_delete_member_bank_account_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_account::SUBJECT_DELETE_MEMBER_BANK_ACCOUNT, + ss_delete_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_delete_member_bank_account_res = bpr::ss::member_bank_account::DeleteMemberBankAccountResponse::decode( + ss_delete_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_delete_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_delete_member_bank_account_res.result { + message + .respond( + bpr::c2se::member_bank_account::DeleteMemberBankAccountResponse { + error: None, + result: Some(bpr::c2se::member_bank_account::delete_member_bank_account_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::DeleteMemberBankAccountResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } +} diff --git a/src/member_bank_deposit/mod.rs b/src/member_bank_deposit/mod.rs new file mode 100644 index 0000000..1f278a4 --- /dev/null +++ b/src/member_bank_deposit/mod.rs @@ -0,0 +1 @@ +pub mod service; diff --git a/src/member_bank_deposit/service.rs b/src/member_bank_deposit/service.rs new file mode 100644 index 0000000..19aafb0 --- /dev/null +++ b/src/member_bank_deposit/service.rs @@ -0,0 +1,724 @@ +use beteran_common_rust as bcr; +use beteran_protobuf_rust as bpr; +use prost::Message; + +/// +pub struct Service { + connection_broker: nats::asynk::Connection, + queue_broker: String, +} + +impl std::fmt::Debug for Service { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("beteran-backend-server-edge::member_bank_deposit::service::Service") + .finish() + } +} + +impl Service { + /// + pub fn new(connection_broker: nats::asynk::Connection, queue_broker: String) -> Service { + Service { + connection_broker, + queue_broker, + } + } + + pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { + futures::try_join!( + self.create_member_bank_deposit(), + self.list_member_bank_deposits(), + self.get_member_bank_deposit(), + self.update_member_bank_deposit(), + self.update_member_bank_deposit_for_state(), + self.delete_member_bank_deposit(), + ) + .map(|_| ()) + } + + fn get_client_in_header( + &self, + message: &nats::asynk::Message, + ) -> Result { + match &message.headers { + Some(headers) => { + let client = match headers.get(bpr::c2se::core::network::HEADER_CLIENT) { + Some(c) => { + let msg = base64::decode(c).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })?; + bpr::models::core::network::Client::decode(msg.as_slice()).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })? + } + None => { + return Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid client information".to_string(), + })); + } + }; + + Ok(client) + } + None => Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid header".to_string(), + })), + } + } + + async fn create_member_bank_deposit(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_CREATE_MEMBER_BANK_DEPOSIT, + 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_deposit::CreateMemberBankDepositRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_create_member_bank_deposit_req = + bpr::ss::member_bank_deposit::CreateMemberBankDepositRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_deposit::create_member_bank_deposit_request::Request { + name: req.name, + amount: req.amount, + memo: req.memo, + }, + ), + }; + + let ss_create_member_bank_deposit_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_CREATE_MEMBER_BANK_DEPOSIT, + ss_create_member_bank_deposit_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_create_member_bank_deposit_res = + bpr::ss::member_bank_deposit::CreateMemberBankDepositResponse::decode( + ss_create_member_bank_deposit_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_create_member_bank_deposit_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_create_member_bank_deposit_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::CreateMemberBankDepositResponse { + error: None, + result: Some( + bpr::c2se::member_bank_deposit::create_member_bank_deposit_response::Result { + member_bank_deposit: r.member_bank_deposit, + }, + ), + } + .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_deposit::CreateMemberBankDepositResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn list_member_bank_deposits(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_LIST_MEMBER_BANK_DEPOSITS, + 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_deposit::ListMemberBankDepositsRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_list_member_bank_deposits_req = bpr::ss::member_bank_deposit::ListMemberBankDepositsRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_deposit::list_member_bank_deposits_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::member_bank_deposit::list_member_bank_deposits_request::request::Search { + member_id: s.member_id, + name_like: s.name_like, + amount: s.amount, + state: s.state, + memo_like: s.memo_like, + }), + None => None, + } + }) + + }; + + let ss_list_member_bank_deposits_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_LIST_MEMBER_BANK_DEPOSITS, + ss_list_member_bank_deposits_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_list_member_bank_deposits_res = + bpr::ss::member_bank_deposit::ListMemberBankDepositsResponse::decode(ss_list_member_bank_deposits_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_list_member_bank_deposits_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_list_member_bank_deposits_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::ListMemberBankDepositsResponse { + error: None, + result: Some(bpr::c2se::member_bank_deposit::list_member_bank_deposits_response::Result { + member_bank_deposits: r.member_bank_deposits, + }), + } + .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_deposit::ListMemberBankDepositsResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_member_bank_deposit(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_GET_MEMBER_BANK_DEPOSIT, + 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_deposit::GetMemberBankDepositRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_member_bank_deposit_req = + bpr::ss::member_bank_deposit::GetMemberBankDepositRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_deposit::get_member_bank_deposit_request::Request { id: req.id }, + ), + }; + + let ss_get_member_bank_deposit_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_GET_MEMBER_BANK_DEPOSIT, + ss_get_member_bank_deposit_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_get_member_bank_deposit_res = + bpr::ss::member_bank_deposit::GetMemberBankDepositResponse::decode( + ss_get_member_bank_deposit_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_get_member_bank_deposit_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_get_member_bank_deposit_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::GetMemberBankDepositResponse { + error: None, + result: Some( + bpr::c2se::member_bank_deposit::get_member_bank_deposit_response::Result { + member_bank_deposit: r.member_bank_deposit, + }, + ), + } + .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_deposit::GetMemberBankDepositResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_member_bank_deposit(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_UPDATE_MEMBER_BANK_DEPOSIT, + 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_deposit::UpdateMemberBankDepositRequest::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_deposit_req = + bpr::ss::member_bank_deposit::UpdateMemberBankDepositRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_deposit::update_member_bank_deposit_request::Request { + id: req.id, + name: req.name, + amount: req.amount, + memo: req.memo, + }, + ), + }; + + let ss_update_member_bank_deposit_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_UPDATE_MEMBER_BANK_DEPOSIT, + ss_update_member_bank_deposit_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_deposit_res = + bpr::ss::member_bank_deposit::UpdateMemberBankDepositResponse::decode( + ss_update_member_bank_deposit_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_deposit_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_deposit_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::UpdateMemberBankDepositResponse { + error: None, + result: Some( + bpr::c2se::member_bank_deposit::update_member_bank_deposit_response::Result { + member_bank_deposit: r.member_bank_deposit, + }, + ), + } + .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_deposit::UpdateMemberBankDepositResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_member_bank_deposit_for_state(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_UPDATE_MEMBER_BANK_DEPOSIT_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_bank_deposit::UpdateMemberBankDepositForStateRequest::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_deposit_for_state_req = bpr::ss::member_bank_deposit::UpdateMemberBankDepositForStateRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_deposit::update_member_bank_deposit_for_state_request::Request { + id: req.id, + state: req.state, + + }) + }; + + let ss_update_member_bank_deposit_for_state_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_UPDATE_MEMBER_BANK_DEPOSIT_FOR_STATE, + ss_update_member_bank_deposit_for_state_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_deposit_for_state_res = bpr::ss::member_bank_deposit::UpdateMemberBankDepositForStateResponse::decode( + ss_update_member_bank_deposit_for_state_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_deposit_for_state_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_deposit_for_state_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::UpdateMemberBankDepositForStateResponse { + error: None, + result: Some(bpr::c2se::member_bank_deposit::update_member_bank_deposit_for_state_response::Result { + member_bank_deposit: r.member_bank_deposit, + }), + } + .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_deposit::UpdateMemberBankDepositForStateResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn delete_member_bank_deposit(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_deposit::SUBJECT_DELETE_MEMBER_BANK_DEPOSIT, + 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_deposit::DeleteMemberBankDepositRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_delete_member_bank_deposit_req = + bpr::ss::member_bank_deposit::DeleteMemberBankDepositRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_deposit::delete_member_bank_deposit_request::Request { + id: req.id, + }, + ), + }; + + let ss_delete_member_bank_deposit_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_deposit::SUBJECT_DELETE_MEMBER_BANK_DEPOSIT, + ss_delete_member_bank_deposit_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_delete_member_bank_deposit_res = + bpr::ss::member_bank_deposit::DeleteMemberBankDepositResponse::decode( + ss_delete_member_bank_deposit_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_delete_member_bank_deposit_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_delete_member_bank_deposit_res.result { + message + .respond( + bpr::c2se::member_bank_deposit::DeleteMemberBankDepositResponse { + error: None, + result: Some( + bpr::c2se::member_bank_deposit::delete_member_bank_deposit_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_deposit::DeleteMemberBankDepositResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } +} diff --git a/src/member_bank_withdraw/mod.rs b/src/member_bank_withdraw/mod.rs new file mode 100644 index 0000000..1f278a4 --- /dev/null +++ b/src/member_bank_withdraw/mod.rs @@ -0,0 +1 @@ +pub mod service; diff --git a/src/member_bank_withdraw/service.rs b/src/member_bank_withdraw/service.rs new file mode 100644 index 0000000..32fdb56 --- /dev/null +++ b/src/member_bank_withdraw/service.rs @@ -0,0 +1,706 @@ +use beteran_common_rust as bcr; +use beteran_protobuf_rust as bpr; +use prost::Message; + +/// +pub struct Service { + connection_broker: nats::asynk::Connection, + queue_broker: String, +} + +impl std::fmt::Debug for Service { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("beteran-backend-server-edge::member_bank_withdraw::service::Service") + .finish() + } +} + +impl Service { + /// + pub fn new(connection_broker: nats::asynk::Connection, queue_broker: String) -> Service { + Service { + connection_broker, + queue_broker, + } + } + + pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { + futures::try_join!( + self.create_member_bank_withdraw(), + self.list_member_bank_withdraws(), + self.get_member_bank_withdraw(), + self.update_member_bank_withdraw(), + self.update_member_bank_withdraw_for_state(), + self.delete_member_bank_withdraw(), + ) + .map(|_| ()) + } + + fn get_client_in_header( + &self, + message: &nats::asynk::Message, + ) -> Result { + match &message.headers { + Some(headers) => { + let client = match headers.get(bpr::c2se::core::network::HEADER_CLIENT) { + Some(c) => { + let msg = base64::decode(c).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })?; + bpr::models::core::network::Client::decode(msg.as_slice()).map_err(|e| { + bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: format!("invalid header: {}", e), + }) + })? + } + None => { + return Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid client information".to_string(), + })); + } + }; + + Ok(client) + } + None => Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse { + message: "invalid header".to_string(), + })), + } + } + + async fn create_member_bank_withdraw(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_CREATE_MEMBER_BANK_WITHDRAW, + 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_withdraw::CreateMemberBankWithdrawRequest::decode( + message.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_create_member_bank_withdraw_req = + bpr::ss::member_bank_withdraw::CreateMemberBankWithdrawRequest { + client: Some(client), + request: Some( + bpr::ss::member_bank_withdraw::create_member_bank_withdraw_request::Request { + bank_name: req.bank_name, + account_number: req.account_number, + amount: req.amount, + password: req.password, + name: req.name, + memo: req.memo, + }, + ), + }; + + let ss_create_member_bank_withdraw_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_CREATE_MEMBER_BANK_WITHDRAW, + ss_create_member_bank_withdraw_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_create_member_bank_withdraw_res = + bpr::ss::member_bank_withdraw::CreateMemberBankWithdrawResponse::decode( + ss_create_member_bank_withdraw_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_create_member_bank_withdraw_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_create_member_bank_withdraw_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::CreateMemberBankWithdrawResponse { + error: None, + result: Some( + bpr::c2se::member_bank_withdraw::create_member_bank_withdraw_response::Result { + member_bank_withdraw: r.member_bank_withdraw, + }, + ), + } + .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_withdraw::CreateMemberBankWithdrawResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn list_member_bank_withdraws(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_LIST_MEMBER_BANK_WITHDRAWS, + 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_withdraw::ListMemberBankWithdrawsRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_list_member_bank_withdraws_req = bpr::ss::member_bank_withdraw::ListMemberBankWithdrawsRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_withdraw::list_member_bank_withdraws_request::Request{ + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::member_bank_withdraw::list_member_bank_withdraws_request::request::Search { + name_like: s.name_like, + member_id: s.member_id, + bank_name_like: s.bank_name_like, + account_number_like: s.account_number_like, + amount: s.amount, + state: s.state, + memo_like: s.memo_like, + }), + None => None, + } + }) + + }; + + let ss_list_member_bank_withdraws_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_LIST_MEMBER_BANK_WITHDRAWS, + ss_list_member_bank_withdraws_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_list_member_bank_withdraws_res = + bpr::ss::member_bank_withdraw::ListMemberBankWithdrawsResponse::decode(ss_list_member_bank_withdraws_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_list_member_bank_withdraws_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_list_member_bank_withdraws_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::ListMemberBankWithdrawsResponse { + error: None, + result: Some(bpr::c2se::member_bank_withdraw::list_member_bank_withdraws_response::Result { + member_bank_withdraws: r.member_bank_withdraws, + }), + } + .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_withdraw::ListMemberBankWithdrawsResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_member_bank_withdraw(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_GET_MEMBER_BANK_WITHDRAW, + 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_withdraw::GetMemberBankWithdrawRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_member_bank_withdraw_req = bpr::ss::member_bank_withdraw::GetMemberBankWithdrawRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_withdraw::get_member_bank_withdraw_request::Request{ + id: req.id, + }) + }; + + let ss_get_member_bank_withdraw_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_GET_MEMBER_BANK_WITHDRAW, + ss_get_member_bank_withdraw_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_get_member_bank_withdraw_res = + bpr::ss::member_bank_withdraw::GetMemberBankWithdrawResponse::decode(ss_get_member_bank_withdraw_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_get_member_bank_withdraw_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_get_member_bank_withdraw_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::GetMemberBankWithdrawResponse { + error: None, + result: Some(bpr::c2se::member_bank_withdraw::get_member_bank_withdraw_response::Result { member_bank_withdraw: r.member_bank_withdraw }), + } + .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_withdraw::GetMemberBankWithdrawResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_member_bank_withdraw(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW, + 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_withdraw::UpdateMemberBankWithdrawRequest::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_withdraw_req = bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_withdraw::update_member_bank_withdraw_request::Request{ + id: req.id, + bank_name: req.bank_name, + account_number: req.account_number, +amount: req.amount, +password: req.password, + name: req.name, + memo: req.memo, + }) + }; + + let ss_update_member_bank_withdraw_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW, + ss_update_member_bank_withdraw_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_withdraw_res = bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawResponse::decode( + ss_update_member_bank_withdraw_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_withdraw_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_withdraw_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::UpdateMemberBankWithdrawResponse { + error: None, + result: Some(bpr::c2se::member_bank_withdraw::update_member_bank_withdraw_response::Result { + member_bank_withdraw: r.member_bank_withdraw, + }), + } + .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_withdraw::UpdateMemberBankWithdrawResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn update_member_bank_withdraw_for_state(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW_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_bank_withdraw::UpdateMemberBankWithdrawForStateRequest::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_withdraw_for_state_req = bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawForStateRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_withdraw::update_member_bank_withdraw_for_state_request::Request{ + id: req.id, + state: req.state, + }) + }; + + let ss_update_member_bank_withdraw_for_state_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW_FOR_STATE, + ss_update_member_bank_withdraw_for_state_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_withdraw_for_state_res = bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawForStateResponse::decode( + ss_update_member_bank_withdraw_for_state_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_withdraw_for_state_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_withdraw_for_state_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::UpdateMemberBankWithdrawForStateResponse { + error: None, + result: Some(bpr::c2se::member_bank_withdraw::update_member_bank_withdraw_for_state_response::Result { + member_bank_withdraw: r.member_bank_withdraw, + }), + } + .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_withdraw::UpdateMemberBankWithdrawForStateResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn delete_member_bank_withdraw(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_bank_withdraw::SUBJECT_DELETE_MEMBER_BANK_WITHDRAW, + 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_withdraw::DeleteMemberBankWithdrawRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_delete_member_bank_withdraw_req = bpr::ss::member_bank_withdraw::DeleteMemberBankWithdrawRequest { + client: Some(client), + request: Some(bpr::ss::member_bank_withdraw::delete_member_bank_withdraw_request::Request{ + id: req.id, + }) + }; + + let ss_delete_member_bank_withdraw_res_msg = self + .connection_broker + .request( + bpr::ss::member_bank_withdraw::SUBJECT_DELETE_MEMBER_BANK_WITHDRAW, + ss_delete_member_bank_withdraw_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_delete_member_bank_withdraw_res = bpr::ss::member_bank_withdraw::DeleteMemberBankWithdrawResponse::decode( + ss_delete_member_bank_withdraw_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_delete_member_bank_withdraw_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_delete_member_bank_withdraw_res.result { + message + .respond( + bpr::c2se::member_bank_withdraw::DeleteMemberBankWithdrawResponse { + error: None, + result: Some(bpr::c2se::member_bank_withdraw::delete_member_bank_withdraw_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_withdraw::DeleteMemberBankWithdrawResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } +} diff --git a/src/member_class/service.rs b/src/member_class/service.rs index 40deff8..9a50930 100644 --- a/src/member_class/service.rs +++ b/src/member_class/service.rs @@ -26,8 +26,9 @@ impl Service { pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { futures::try_join!( - self.list_member_classes(), self.create_member_class(), + self.list_member_classes(), + self.get_member_class(), self.update_member_class(), self.delete_member_class(), ) @@ -81,25 +82,28 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_class::CreateMemberClassRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_class::CreateMemberClassRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_create_member_class_req = bpr::ss::member::member_class::CreateMemberClassRequest { + let ss_create_member_class_req = bpr::ss::member_class::CreateMemberClassRequest { client: Some(client), - parent_id: req.parent_id, - name: req.name, + request: Some( + bpr::ss::member_class::create_member_class_request::Request { + parent_id: req.parent_id, + name: req.name, + }, + ), }; let ss_create_member_class_res_msg = self .connection_broker .request( - bpr::ss::member::member_class::SUBJECT_CREATE_MEMBER_CLASS, + bpr::ss::member_class::SUBJECT_CREATE_MEMBER_CLASS, ss_create_member_class_req.encode_to_vec(), ) .await @@ -111,17 +115,16 @@ impl Service { }) })?; - let ss_create_member_class_res = - bpr::ss::member::member_class::CreateMemberClassResponse::decode( - ss_create_member_class_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, - }) - })?; + let ss_create_member_class_res = bpr::ss::member_class::CreateMemberClassResponse::decode( + ss_create_member_class_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_create_member_class_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -134,10 +137,10 @@ impl Service { if let Some(r) = ss_create_member_class_res.result { message .respond( - bpr::c2se::backend::member_class::CreateMemberClassResponse { + bpr::c2se::member_class::CreateMemberClassResponse { error: None, result: Some( - bpr::c2se::backend::member_class::create_member_class_response::Result { + bpr::c2se::member_class::create_member_class_response::Result { member_class: r.member_class, }, ), @@ -160,7 +163,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_class::CreateMemberClassResponse { + bpr::c2se::member_class::CreateMemberClassResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -186,27 +189,36 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_class::ListMemberClassesRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_class::ListMemberClassesRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_list_member_classes_req = bpr::ss::member::member_class::ListMemberClassesRequest { + let ss_list_member_classes_req = bpr::ss::member_class::ListMemberClassesRequest { client: Some(client), - pagination: req.pagination, - searches: req.searches, - sorts: req.sorts, - name_like: req.name_like, + request: Some( + bpr::ss::member_class::list_member_classes_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some( + bpr::ss::member_class::list_member_classes_request::request::Search { + name_like: s.name_like, + }, + ), + None => None, + }, + }, + ), }; let ss_list_member_classes_res_msg = self .connection_broker .request( - bpr::ss::member::member_class::SUBJECT_LIST_MEMBER_CLASSES, + bpr::ss::member_class::SUBJECT_LIST_MEMBER_CLASSES, ss_list_member_classes_req.encode_to_vec(), ) .await @@ -218,17 +230,16 @@ impl Service { }) })?; - let ss_list_member_classes_res = - bpr::ss::member::member_class::ListMemberClassesResponse::decode( - ss_list_member_classes_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, - }) - })?; + let ss_list_member_classes_res = bpr::ss::member_class::ListMemberClassesResponse::decode( + ss_list_member_classes_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_list_member_classes_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -241,10 +252,10 @@ impl Service { if let Some(r) = ss_list_member_classes_res.result { message .respond( - bpr::c2se::backend::member_class::ListMemberClassesResponse { + bpr::c2se::member_class::ListMemberClassesResponse { error: None, result: Some( - bpr::c2se::backend::member_class::list_member_classes_response::Result { + bpr::c2se::member_class::list_member_classes_response::Result { member_classes: r.member_classes, }, ), @@ -267,7 +278,106 @@ impl Service { { message .respond( - bpr::c2se::backend::member_class::ListMemberClassesResponse { + bpr::c2se::member_class::ListMemberClassesResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_member_class(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_class::SUBJECT_GET_MEMBER_CLASS, + 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_class::GetMemberClassRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_member_class_req = bpr::ss::member_class::GetMemberClassRequest { + client: Some(client), + request: Some(bpr::ss::member_class::get_member_class_request::Request { id: req.id }), + }; + + let ss_get_member_class_res_msg = self + .connection_broker + .request( + bpr::ss::member_class::SUBJECT_GET_MEMBER_CLASS, + ss_get_member_class_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_get_member_class_res = bpr::ss::member_class::GetMemberClassResponse::decode( + ss_get_member_class_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_get_member_class_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_get_member_class_res.result { + message + .respond( + bpr::c2se::member_class::GetMemberClassResponse { + error: None, + result: Some(bpr::c2se::member_class::get_member_class_response::Result { + member_class: r.member_class, + }), + } + .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_class::GetMemberClassResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -293,26 +403,29 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_class::UpdateMemberClassRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_class::UpdateMemberClassRequest::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_class_req = bpr::ss::member::member_class::UpdateMemberClassRequest { + let ss_update_member_class_req = bpr::ss::member_class::UpdateMemberClassRequest { client: Some(client), - id: req.id, - parent_id: req.parent_id, - name: req.name, + request: Some( + bpr::ss::member_class::update_member_class_request::Request { + id: req.id, + parent_id: req.parent_id, + name: req.name, + }, + ), }; let ss_update_member_class_res_msg = self .connection_broker .request( - bpr::ss::member::member_class::SUBJECT_UPDATE_MEMBER_CLASS, + bpr::ss::member_class::SUBJECT_UPDATE_MEMBER_CLASS, ss_update_member_class_req.encode_to_vec(), ) .await @@ -324,17 +437,16 @@ impl Service { }) })?; - let ss_update_member_class_res = - bpr::ss::member::member_class::UpdateMemberClassResponse::decode( - ss_update_member_class_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, - }) - })?; + let ss_update_member_class_res = bpr::ss::member_class::UpdateMemberClassResponse::decode( + ss_update_member_class_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_class_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -347,10 +459,10 @@ impl Service { if let Some(r) = ss_update_member_class_res.result { message .respond( - bpr::c2se::backend::member_class::UpdateMemberClassResponse { + bpr::c2se::member_class::UpdateMemberClassResponse { error: None, result: Some( - bpr::c2se::backend::member_class::update_member_class_response::Result { + bpr::c2se::member_class::update_member_class_response::Result { member_class: r.member_class, }, ), @@ -373,7 +485,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_class::UpdateMemberClassResponse { + bpr::c2se::member_class::UpdateMemberClassResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -399,24 +511,23 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_class::DeleteMemberClassRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_class::DeleteMemberClassRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_delete_member_class_req = bpr::ss::member::member_class::DeleteMemberClassRequest { + let ss_delete_member_class_req = bpr::ss::member_class::DeleteMemberClassRequest { client: Some(client), - id: req.id, + request: Some(bpr::ss::member_class::delete_member_class_request::Request { id: req.id }), }; let ss_delete_member_class_res_msg = self .connection_broker .request( - bpr::ss::member::member_class::SUBJECT_DELETE_MEMBER_CLASS, + bpr::ss::member_class::SUBJECT_DELETE_MEMBER_CLASS, ss_delete_member_class_req.encode_to_vec(), ) .await @@ -428,17 +539,16 @@ impl Service { }) })?; - let ss_delete_member_class_res = - bpr::ss::member::member_class::DeleteMemberClassResponse::decode( - ss_delete_member_class_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, - }) - })?; + let ss_delete_member_class_res = bpr::ss::member_class::DeleteMemberClassResponse::decode( + ss_delete_member_class_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_delete_member_class_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -451,11 +561,9 @@ impl Service { if let Some(r) = ss_delete_member_class_res.result { message .respond( - bpr::c2se::backend::member_class::DeleteMemberClassResponse { + bpr::c2se::member_class::DeleteMemberClassResponse { error: None, - result: Some( - bpr::c2se::backend::member_class::delete_member_class_response::Result {}, - ), + result: Some(bpr::c2se::member_class::delete_member_class_response::Result {}), } .encode_to_vec(), ) @@ -475,7 +583,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_class::DeleteMemberClassResponse { + bpr::c2se::member_class::DeleteMemberClassResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } diff --git a/src/member_level/service.rs b/src/member_level/service.rs index 24d1eee..7b712b6 100644 --- a/src/member_level/service.rs +++ b/src/member_level/service.rs @@ -26,8 +26,9 @@ impl Service { pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { futures::try_join!( - self.list_member_levels(), self.create_member_level(), + self.list_member_levels(), + self.get_member_level(), self.update_member_level(), self.delete_member_level(), ) @@ -81,25 +82,28 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_level::CreateMemberLevelRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_level::CreateMemberLevelRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_create_member_level_req = bpr::ss::member::member_level::CreateMemberLevelRequest { + let ss_create_member_level_req = bpr::ss::member_level::CreateMemberLevelRequest { client: Some(client), - name: req.name, - sort_order: req.sort_order, + request: Some( + bpr::ss::member_level::create_member_level_request::Request { + name: req.name, + sort_order: req.sort_order, + }, + ), }; let ss_create_member_level_res_msg = self .connection_broker .request( - bpr::ss::member::member_level::SUBJECT_CREATE_MEMBER_LEVEL, + bpr::ss::member_level::SUBJECT_CREATE_MEMBER_LEVEL, ss_create_member_level_req.encode_to_vec(), ) .await @@ -111,17 +115,16 @@ impl Service { }) })?; - let ss_create_member_level_res = - bpr::ss::member::member_level::CreateMemberLevelResponse::decode( - ss_create_member_level_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, - }) - })?; + let ss_create_member_level_res = bpr::ss::member_level::CreateMemberLevelResponse::decode( + ss_create_member_level_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_create_member_level_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -134,10 +137,10 @@ impl Service { if let Some(r) = ss_create_member_level_res.result { message .respond( - bpr::c2se::backend::member_level::CreateMemberLevelResponse { + bpr::c2se::member_level::CreateMemberLevelResponse { error: None, result: Some( - bpr::c2se::backend::member_level::create_member_level_response::Result { + bpr::c2se::member_level::create_member_level_response::Result { member_level: r.member_level, }, ), @@ -160,7 +163,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_level::CreateMemberLevelResponse { + bpr::c2se::member_level::CreateMemberLevelResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -186,27 +189,33 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_level::ListMemberLevelsRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = bpr::c2se::member_level::ListMemberLevelsRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_list_member_levels_req = bpr::ss::member::member_level::ListMemberLevelsRequest { + let ss_list_member_levels_req = bpr::ss::member_level::ListMemberLevelsRequest { client: Some(client), - pagination: req.pagination, - searches: req.searches, - sorts: req.sorts, - name_like: req.name_like, + request: Some(bpr::ss::member_level::list_member_levels_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some( + bpr::ss::member_level::list_member_levels_request::request::Search { + name_like: s.name_like, + }, + ), + None => None, + }, + }), }; let ss_list_member_levels_res_msg = self .connection_broker .request( - bpr::ss::member::member_level::SUBJECT_LIST_MEMBER_LEVELS, + bpr::ss::member_level::SUBJECT_LIST_MEMBER_LEVELS, ss_list_member_levels_req.encode_to_vec(), ) .await @@ -218,17 +227,16 @@ impl Service { }) })?; - let ss_list_member_levels_res = - bpr::ss::member::member_level::ListMemberLevelsResponse::decode( - ss_list_member_levels_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, - }) - })?; + let ss_list_member_levels_res = bpr::ss::member_level::ListMemberLevelsResponse::decode( + ss_list_member_levels_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_list_member_levels_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -241,10 +249,10 @@ impl Service { if let Some(r) = ss_list_member_levels_res.result { message .respond( - bpr::c2se::backend::member_level::ListMemberLevelsResponse { + bpr::c2se::member_level::ListMemberLevelsResponse { error: None, result: Some( - bpr::c2se::backend::member_level::list_member_levels_response::Result { + bpr::c2se::member_level::list_member_levels_response::Result { member_levels: r.member_levels, }, ), @@ -267,7 +275,106 @@ impl Service { { message .respond( - bpr::c2se::backend::member_level::ListMemberLevelsResponse { + bpr::c2se::member_level::ListMemberLevelsResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_member_level(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member_level::SUBJECT_GET_MEMBER_LEVEL, + 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_level::GetMemberLevelRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_member_level_req = bpr::ss::member_level::GetMemberLevelRequest { + client: Some(client), + request: Some(bpr::ss::member_level::get_member_level_request::Request { id: req.id }), + }; + + let ss_get_member_level_res_msg = self + .connection_broker + .request( + bpr::ss::member_level::SUBJECT_UPDATE_MEMBER_LEVEL, + ss_get_member_level_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_get_member_level_res = bpr::ss::member_level::GetMemberLevelResponse::decode( + ss_get_member_level_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_get_member_level_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_get_member_level_res.result { + message + .respond( + bpr::c2se::member_level::GetMemberLevelResponse { + error: None, + result: Some(bpr::c2se::member_level::get_member_level_response::Result { + member_level: r.member_level, + }), + } + .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_level::GetMemberLevelResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -293,26 +400,29 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_level::UpdateMemberLevelRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_level::UpdateMemberLevelRequest::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_level_req = bpr::ss::member::member_level::UpdateMemberLevelRequest { + let ss_update_member_level_req = bpr::ss::member_level::UpdateMemberLevelRequest { client: Some(client), - id: req.id, - name: req.name, - sort_order: req.sort_order, + request: Some( + bpr::ss::member_level::update_member_level_request::Request { + id: req.id, + name: req.name, + sort_order: req.sort_order, + }, + ), }; let ss_update_member_level_res_msg = self .connection_broker .request( - bpr::ss::member::member_level::SUBJECT_UPDATE_MEMBER_LEVEL, + bpr::ss::member_level::SUBJECT_UPDATE_MEMBER_LEVEL, ss_update_member_level_req.encode_to_vec(), ) .await @@ -324,17 +434,16 @@ impl Service { }) })?; - let ss_update_member_level_res = - bpr::ss::member::member_level::UpdateMemberLevelResponse::decode( - ss_update_member_level_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, - }) - })?; + let ss_update_member_level_res = bpr::ss::member_level::UpdateMemberLevelResponse::decode( + ss_update_member_level_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_level_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -347,10 +456,10 @@ impl Service { if let Some(r) = ss_update_member_level_res.result { message .respond( - bpr::c2se::backend::member_level::UpdateMemberLevelResponse { + bpr::c2se::member_level::UpdateMemberLevelResponse { error: None, result: Some( - bpr::c2se::backend::member_level::update_member_level_response::Result { + bpr::c2se::member_level::update_member_level_response::Result { member_level: r.member_level, }, ), @@ -373,7 +482,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_level::UpdateMemberLevelResponse { + bpr::c2se::member_level::UpdateMemberLevelResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -399,24 +508,23 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::member_level::DeleteMemberLevelRequest::decode( - message.data.as_slice(), - ) - .map_err(|e| { - bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { - message: format!("invalid request: {}", e), - }) - })?; + let req = + bpr::c2se::member_level::DeleteMemberLevelRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; - let ss_delete_member_level_req = bpr::ss::member::member_level::DeleteMemberLevelRequest { + let ss_delete_member_level_req = bpr::ss::member_level::DeleteMemberLevelRequest { client: Some(client), - id: req.id, + request: Some(bpr::ss::member_level::delete_member_level_request::Request { id: req.id }), }; let ss_delete_member_level_res_msg = self .connection_broker .request( - bpr::ss::member::member_level::SUBJECT_DELETE_MEMBER_LEVEL, + bpr::ss::member_level::SUBJECT_DELETE_MEMBER_LEVEL, ss_delete_member_level_req.encode_to_vec(), ) .await @@ -428,17 +536,16 @@ impl Service { }) })?; - let ss_delete_member_level_res = - bpr::ss::member::member_level::DeleteMemberLevelResponse::decode( - ss_delete_member_level_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, - }) - })?; + let ss_delete_member_level_res = bpr::ss::member_level::DeleteMemberLevelResponse::decode( + ss_delete_member_level_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_delete_member_level_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -451,11 +558,9 @@ impl Service { if let Some(r) = ss_delete_member_level_res.result { message .respond( - bpr::c2se::backend::member_level::DeleteMemberLevelResponse { + bpr::c2se::member_level::DeleteMemberLevelResponse { error: None, - result: Some( - bpr::c2se::backend::member_level::delete_member_level_response::Result {}, - ), + result: Some(bpr::c2se::member_level::delete_member_level_response::Result {}), } .encode_to_vec(), ) @@ -475,7 +580,7 @@ impl Service { { message .respond( - bpr::c2se::backend::member_level::DeleteMemberLevelResponse { + bpr::c2se::member_level::DeleteMemberLevelResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } diff --git a/src/site/service.rs b/src/site/service.rs index 76fb65d..989b015 100644 --- a/src/site/service.rs +++ b/src/site/service.rs @@ -26,8 +26,9 @@ impl Service { pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { futures::try_join!( - self.list_sites(), self.create_site(), + self.list_sites(), + self.get_site(), self.update_site(), self.delete_site(), ) @@ -81,30 +82,36 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::site::ListSitesRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::site::ListSitesRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_list_sites_req = bpr::ss::domain::site::ListSitesRequest { + let ss_list_sites_req = bpr::ss::site::ListSitesRequest { client: Some(client), - pagination: req.pagination, - searches: req.searches, - sorts: req.sorts, - url_like: req.url_like, - name_like: req.name_like, - path_like: req.path_like, - show: req.show, - can_use: req.can_use, - memo_like: req.memo_like, + request: Some(bpr::ss::site::list_sites_request::Request { + pagination: req.pagination, + sorts: req.sorts, + search: match req.search { + Some(s) => Some(bpr::ss::site::list_sites_request::request::Search { + url_like: s.url_like, + name_like: s.name_like, + path_like: s.path_like, + show: s.show, + can_use: s.can_use, + memo_like: s.memo_like, + }), + None => None, + }, + }), }; let ss_list_sites_res_msg = self .connection_broker .request( - bpr::ss::domain::site::SUBJECT_LIST_SITES, + bpr::ss::site::SUBJECT_LIST_SITES, ss_list_sites_req.encode_to_vec(), ) .await @@ -116,15 +123,16 @@ impl Service { }) })?; - let ss_list_sites_res = - bpr::ss::domain::site::ListSitesResponse::decode(ss_list_sites_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, - }) - })?; + let ss_list_sites_res = bpr::ss::site::ListSitesResponse::decode( + ss_list_sites_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_list_sites_res.error { return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -137,11 +145,9 @@ impl Service { if let Some(r) = ss_list_sites_res.result { message .respond( - bpr::c2se::backend::site::ListSitesResponse { + bpr::c2se::site::ListSitesResponse { error: None, - result: Some(bpr::c2se::backend::site::list_sites_response::Result { - sites: r.sites, - }), + result: Some(bpr::c2se::site::list_sites_response::Result { sites: r.sites }), } .encode_to_vec(), ) @@ -161,7 +167,7 @@ impl Service { { message .respond( - bpr::c2se::backend::site::ListSitesResponse { + bpr::c2se::site::ListSitesResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -187,28 +193,30 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::site::CreateSiteRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::site::CreateSiteRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_create_site_req = bpr::ss::domain::site::CreateSiteRequest { + let ss_create_site_req = bpr::ss::site::CreateSiteRequest { client: Some(client), - url: req.url, - name: req.name, - path: req.path, - show: req.show, - can_use: req.can_use, - memo: req.memo, - expires_at: req.expires_at, + request: Some(bpr::ss::site::create_site_request::Request { + url: req.url, + name: req.name, + path: req.path, + show: req.show, + can_use: req.can_use, + memo: req.memo, + expires_at: req.expires_at, + }), }; let ss_create_site_res_msg = self .connection_broker .request( - bpr::ss::domain::site::SUBJECT_CREATE_SITE, + bpr::ss::site::SUBJECT_CREATE_SITE, ss_create_site_req.encode_to_vec(), ) .await @@ -221,7 +229,7 @@ impl Service { })?; let ss_create_site_res = - bpr::ss::domain::site::CreateSiteResponse::decode(ss_create_site_res_msg.data.as_slice()) + bpr::ss::site::CreateSiteResponse::decode(ss_create_site_res_msg.data.as_slice()) .map_err(|e| { bcr::error::rpc::Error::Server(bcr::error::rpc::Server { code: bpr::protobuf::rpc::Error::SERVER_00, @@ -241,11 +249,9 @@ impl Service { if let Some(r) = ss_create_site_res.result { message .respond( - bpr::c2se::backend::site::CreateSiteResponse { + bpr::c2se::site::CreateSiteResponse { error: None, - result: Some(bpr::c2se::backend::site::create_site_response::Result { - site: r.site, - }), + result: Some(bpr::c2se::site::create_site_response::Result { site: r.site }), } .encode_to_vec(), ) @@ -265,7 +271,104 @@ impl Service { { message .respond( - bpr::c2se::backend::site::CreateSiteResponse { + bpr::c2se::site::CreateSiteResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + + async fn get_site(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::site::SUBJECT_GET_SITE, + 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::site::GetSiteRequest::decode(message.data.as_slice()).map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_get_site_req = bpr::ss::site::GetSiteRequest { + client: Some(client), + request: Some(bpr::ss::site::get_site_request::Request { id: req.id }), + }; + + let ss_get_site_res_msg = self + .connection_broker + .request( + bpr::ss::site::SUBJECT_GET_SITE, + ss_get_site_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_get_site_res = bpr::ss::site::GetSiteResponse::decode( + ss_get_site_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_get_site_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_get_site_res.result { + message + .respond( + bpr::c2se::site::GetSiteResponse { + error: None, + result: Some(bpr::c2se::site::get_site_response::Result { site: r.site }), + } + .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::site::GetSiteResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -291,29 +394,31 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::site::UpdateSiteRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::site::UpdateSiteRequest::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_site_req = bpr::ss::domain::site::UpdateSiteRequest { + let ss_update_site_req = bpr::ss::site::UpdateSiteRequest { client: Some(client), - id: req.id, - url: req.url, - name: req.name, - path: req.path, - show: req.show, - can_use: req.can_use, - memo: req.memo, - expires_at: req.expires_at, + request: Some(bpr::ss::site::update_site_request::Request { + id: req.id, + url: req.url, + name: req.name, + path: req.path, + show: req.show, + can_use: req.can_use, + memo: req.memo, + expires_at: req.expires_at, + }), }; let ss_update_site_res_msg = self .connection_broker .request( - bpr::ss::domain::site::SUBJECT_UPDATE_SITE, + bpr::ss::site::SUBJECT_UPDATE_SITE, ss_update_site_req.encode_to_vec(), ) .await @@ -326,7 +431,7 @@ impl Service { })?; let ss_update_site_res = - bpr::ss::domain::site::UpdateSiteResponse::decode(ss_update_site_res_msg.data.as_slice()) + bpr::ss::site::UpdateSiteResponse::decode(ss_update_site_res_msg.data.as_slice()) .map_err(|e| { bcr::error::rpc::Error::Server(bcr::error::rpc::Server { code: bpr::protobuf::rpc::Error::SERVER_00, @@ -346,11 +451,9 @@ impl Service { if let Some(r) = ss_update_site_res.result { message .respond( - bpr::c2se::backend::site::UpdateSiteResponse { + bpr::c2se::site::UpdateSiteResponse { error: None, - result: Some(bpr::c2se::backend::site::update_site_response::Result { - site: r.site, - }), + result: Some(bpr::c2se::site::update_site_response::Result { site: r.site }), } .encode_to_vec(), ) @@ -370,7 +473,7 @@ impl Service { { message .respond( - bpr::c2se::backend::site::UpdateSiteResponse { + bpr::c2se::site::UpdateSiteResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, } @@ -396,22 +499,22 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - let req = bpr::c2se::backend::site::DeleteSiteRequest::decode(message.data.as_slice()) - .map_err(|e| { + let req = + bpr::c2se::site::DeleteSiteRequest::decode(message.data.as_slice()).map_err(|e| { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { message: format!("invalid request: {}", e), }) })?; - let ss_delete_site_req = bpr::ss::domain::site::DeleteSiteRequest { + let ss_delete_site_req = bpr::ss::site::DeleteSiteRequest { client: Some(client), - id: req.id, + request: Some(bpr::ss::site::delete_site_request::Request { id: req.id }), }; let ss_delete_site_res_msg = self .connection_broker .request( - bpr::ss::domain::site::SUBJECT_DELETE_SITE, + bpr::ss::site::SUBJECT_DELETE_SITE, ss_delete_site_req.encode_to_vec(), ) .await @@ -424,7 +527,7 @@ impl Service { })?; let ss_delete_site_res = - bpr::ss::domain::site::DeleteSiteResponse::decode(ss_delete_site_res_msg.data.as_slice()) + bpr::ss::site::DeleteSiteResponse::decode(ss_delete_site_res_msg.data.as_slice()) .map_err(|e| { bcr::error::rpc::Error::Server(bcr::error::rpc::Server { code: bpr::protobuf::rpc::Error::SERVER_00, @@ -444,9 +547,9 @@ impl Service { if let Some(r) = ss_delete_site_res.result { message .respond( - bpr::c2se::backend::site::DeleteSiteResponse { + bpr::c2se::site::DeleteSiteResponse { error: None, - result: Some(bpr::c2se::backend::site::delete_site_response::Result {}), + result: Some(bpr::c2se::site::delete_site_response::Result {}), } .encode_to_vec(), ) @@ -466,7 +569,7 @@ impl Service { { message .respond( - bpr::c2se::backend::site::DeleteSiteResponse { + bpr::c2se::site::DeleteSiteResponse { error: Some(bpr::protobuf::rpc::Error::from(e)), result: None, }