From e80fd5672014b93bc393a9087daaad260563f426 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Fri, 12 Aug 2022 07:14:01 +0000 Subject: [PATCH] create_member is added --- Cargo.toml | 4 +- src/member/service.rs | 108 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fea40ab..4daee98 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.35-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.18-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.40-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.23-snapshot" } [build-dependencies] diff --git a/src/member/service.rs b/src/member/service.rs index 5793cec..742927b 100644 --- a/src/member/service.rs +++ b/src/member/service.rs @@ -26,6 +26,7 @@ impl Service { pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box> { futures::try_join!( + self.create_member(), self.list_members(), self.get_member(), self.get_member_by_username(), @@ -69,6 +70,113 @@ impl Service { } } + async fn create_member(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::backend::member::SUBJECT_CREATE_MEMBER, + 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::backend::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 { + 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, + }; + + let ss_create_member_res_msg = self + .connection_broker + .request( + bpr::ss::member::member::SUBJECT_CREATE_MEMBER, + ss_create_member_req.encode_to_vec(), + ) + .await + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + + let ss_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, + }) + })?; + + if let Some(e) = ss_create_member_res.error { + return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + })); + } + + if let Some(r) = ss_create_member_res.result { + message + .respond( + bpr::c2se::backend::member::CreateMemberResponse { + error: None, + result: Some(bpr::c2se::backend::member::create_member_response::Result { + member: r.member, + }), + } + .encode_to_vec(), + ) + .await + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + } + + Ok::<(), bcr::error::rpc::Error>(()) + } + .await + { + message + .respond( + bpr::c2se::backend::member::CreateMemberResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } + async fn list_members(&self) -> Result<(), Box> { let s = self .connection_broker