member_referrer is added
This commit is contained in:
parent
6b167b37d8
commit
e272359c8c
|
@ -19,7 +19,7 @@ prost = { version = "0" }
|
||||||
nats = { version = "0" }
|
nats = { version = "0" }
|
||||||
base64 = { version = "0" }
|
base64 = { version = "0" }
|
||||||
|
|
||||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.64-snapshot" }
|
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.66-snapshot" }
|
||||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.48-snapshot" }
|
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.50-snapshot" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -8,6 +8,7 @@ mod member_bank_deposit;
|
||||||
mod member_bank_withdraw;
|
mod member_bank_withdraw;
|
||||||
mod member_class;
|
mod member_class;
|
||||||
mod member_level;
|
mod member_level;
|
||||||
|
mod member_referrer;
|
||||||
mod site;
|
mod site;
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
|
@ -41,6 +42,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
member_class::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
member_class::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
let member_level_service =
|
let member_level_service =
|
||||||
member_level::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
member_level::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
|
let member_referrer_service =
|
||||||
|
member_referrer::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
|
|
||||||
let api_service = api::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
let api_service = api::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
|
@ -56,6 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
member_bank_withdraw_service.subscribe(),
|
member_bank_withdraw_service.subscribe(),
|
||||||
member_class_service.subscribe(),
|
member_class_service.subscribe(),
|
||||||
member_level_service.subscribe(),
|
member_level_service.subscribe(),
|
||||||
|
member_referrer_service.subscribe(),
|
||||||
site_service.subscribe(),
|
site_service.subscribe(),
|
||||||
api_service.subscribe(),
|
api_service.subscribe(),
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -220,7 +220,7 @@ impl Service {
|
||||||
site_id: s.site_id,
|
site_id: s.site_id,
|
||||||
member_class_id: s.member_class_id,
|
member_class_id: s.member_class_id,
|
||||||
member_level_id: s.member_level_id,
|
member_level_id: s.member_level_id,
|
||||||
referrer_member_id: s.referrer_member_id,
|
parent_member_id: s.parent_member_id,
|
||||||
username_like: s.username_like,
|
username_like: s.username_like,
|
||||||
nickname_like: s.nickname_like,
|
nickname_like: s.nickname_like,
|
||||||
mobile_phone_number_like: s.mobile_phone_number_like,
|
mobile_phone_number_like: s.mobile_phone_number_like,
|
||||||
|
@ -679,7 +679,7 @@ impl Service {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(r) = ss_delete_member_res.result {
|
if let Some(_r) = ss_delete_member_res.result {
|
||||||
message
|
message
|
||||||
.respond(
|
.respond(
|
||||||
bpr::c2se::member::DeleteMemberResponse {
|
bpr::c2se::member::DeleteMemberResponse {
|
||||||
|
|
1
src/member_referrer/mod.rs
Normal file
1
src/member_referrer/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod service;
|
613
src/member_referrer/service.rs
Normal file
613
src/member_referrer/service.rs
Normal file
|
@ -0,0 +1,613 @@
|
||||||
|
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_referrer::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<dyn std::error::Error>> {
|
||||||
|
futures::try_join!(
|
||||||
|
self.create_member_referrer(),
|
||||||
|
self.list_member_referrers(),
|
||||||
|
self.get_member_referrer(),
|
||||||
|
self.update_member_referrer(),
|
||||||
|
self.delete_member_referrer(),
|
||||||
|
)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_client_in_header(
|
||||||
|
&self,
|
||||||
|
message: &nats::asynk::Message,
|
||||||
|
) -> Result<bpr::models::core::network::Client, bcr::error::rpc::Error> {
|
||||||
|
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_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::backend::member_referrer::SUBJECT_CREATE_MEMBER_REFERRER,
|
||||||
|
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_referrer::CreateMemberReferrerRequest::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_referrer_req = bpr::ss::member_referrer::CreateMemberReferrerRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::create_member_referrer_request::Request {
|
||||||
|
member_id: req.member_id,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_create_member_referrer_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_CREATE_MEMBER_REFERRER,
|
||||||
|
ss_create_member_referrer_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_referrer_res =
|
||||||
|
bpr::ss::member_referrer::CreateMemberReferrerResponse::decode(
|
||||||
|
ss_create_member_referrer_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_referrer_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_referrer_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::CreateMemberReferrerResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::create_member_referrer_response::Result {
|
||||||
|
member_referrer: r.member_referrer,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
.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_referrer::CreateMemberReferrerResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_member_referrers(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::backend::member_referrer::SUBJECT_LIST_MEMBER_REFERRERS,
|
||||||
|
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_referrer::ListMemberReferrersRequest::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_referrers_req = bpr::ss::member_referrer::ListMemberReferrersRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::list_member_referrers_request::Request {
|
||||||
|
pagination: req.pagination,
|
||||||
|
sorts: req.sorts,
|
||||||
|
search: match req.search {
|
||||||
|
Some(s) => Some(
|
||||||
|
bpr::ss::member_referrer::list_member_referrers_request::request::Search {
|
||||||
|
member_id: s.member_id,
|
||||||
|
can_use: s.can_use,
|
||||||
|
memo_like: s.memo_like,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_list_member_referrers_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_LIST_MEMBER_REFERRERS,
|
||||||
|
ss_list_member_referrers_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_referrers_res =
|
||||||
|
bpr::ss::member_referrer::ListMemberReferrersResponse::decode(
|
||||||
|
ss_list_member_referrers_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_referrers_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_referrers_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::ListMemberReferrersResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::list_member_referrers_response::Result {
|
||||||
|
member_referrers: r.member_referrers,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
.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_referrer::ListMemberReferrersResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::backend::member_referrer::SUBJECT_GET_MEMBER_REFERRER,
|
||||||
|
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_referrer::GetMemberReferrerRequest::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_referrer_req = bpr::ss::member_referrer::GetMemberReferrerRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::get_member_referrer_request::Request { id: req.id },
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_get_member_referrer_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_UPDATE_MEMBER_REFERRER,
|
||||||
|
ss_get_member_referrer_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_referrer_res =
|
||||||
|
bpr::ss::member_referrer::GetMemberReferrerResponse::decode(
|
||||||
|
ss_get_member_referrer_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_referrer_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_referrer_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::GetMemberReferrerResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::get_member_referrer_response::Result {
|
||||||
|
member_referrer: r.member_referrer,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
.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_referrer::GetMemberReferrerResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::backend::member_referrer::SUBJECT_UPDATE_MEMBER_REFERRER,
|
||||||
|
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_referrer::UpdateMemberReferrerRequest::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_referrer_req = bpr::ss::member_referrer::UpdateMemberReferrerRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::update_member_referrer_request::Request {
|
||||||
|
id: req.id,
|
||||||
|
can_use: req.can_use,
|
||||||
|
memo: req.memo,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_update_member_referrer_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_UPDATE_MEMBER_REFERRER,
|
||||||
|
ss_update_member_referrer_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_referrer_res =
|
||||||
|
bpr::ss::member_referrer::UpdateMemberReferrerResponse::decode(
|
||||||
|
ss_update_member_referrer_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_referrer_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_referrer_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::UpdateMemberReferrerResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::update_member_referrer_response::Result {
|
||||||
|
member_referrer: r.member_referrer,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
.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_referrer::UpdateMemberReferrerResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::backend::member_referrer::SUBJECT_DELETE_MEMBER_REFERRER,
|
||||||
|
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_referrer::DeleteMemberReferrerRequest::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_referrer_req = bpr::ss::member_referrer::DeleteMemberReferrerRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::delete_member_referrer_request::Request { id: req.id },
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_delete_member_referrer_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_DELETE_MEMBER_REFERRER,
|
||||||
|
ss_delete_member_referrer_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_referrer_res =
|
||||||
|
bpr::ss::member_referrer::DeleteMemberReferrerResponse::decode(
|
||||||
|
ss_delete_member_referrer_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_referrer_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_referrer_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::DeleteMemberReferrerResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::delete_member_referrer_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_referrer::DeleteMemberReferrerResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user