member_referrer is added
This commit is contained in:
parent
9d41ff3bc0
commit
30d9ca8334
|
@ -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.67-snapshot" }
|
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.68-snapshot" }
|
||||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.51-snapshot" }
|
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.52-snapshot" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::env;
|
||||||
mod api;
|
mod api;
|
||||||
mod bank;
|
mod bank;
|
||||||
mod identity;
|
mod identity;
|
||||||
|
mod member_referrer;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -21,6 +22,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let bank_service = bank::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 =
|
let identity_service =
|
||||||
identity::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
identity::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 api_vendor_service =
|
let api_vendor_service =
|
||||||
api::vendor::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
api::vendor::service::Service::new(connection_broker.clone(), queue_broker.clone());
|
||||||
|
@ -32,6 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
futures::try_join!(
|
futures::try_join!(
|
||||||
bank_service.subscribe(),
|
bank_service.subscribe(),
|
||||||
identity_service.subscribe(),
|
identity_service.subscribe(),
|
||||||
|
member_referrer_service.subscribe(),
|
||||||
api_vendor_service.subscribe(),
|
api_vendor_service.subscribe(),
|
||||||
api_game_service.subscribe(),
|
api_game_service.subscribe(),
|
||||||
)?;
|
)?;
|
||||||
|
|
1
src/member_referrer/mod.rs
Normal file
1
src/member_referrer/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod service;
|
173
src/member_referrer/service.rs
Normal file
173
src/member_referrer/service.rs
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
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-frontend-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.get_member_referrer_by_code(),).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 get_member_referrer_by_code(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::c2se::frontend::member_referrer::SUBJECT_GET_MEMBER_REFERRER_BY_CODE,
|
||||||
|
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::GetMemberReferrerByCodeRequest::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_by_code_req =
|
||||||
|
bpr::ss::member_referrer::GetMemberReferrerByCodeRequest {
|
||||||
|
client: Some(client),
|
||||||
|
request: Some(
|
||||||
|
bpr::ss::member_referrer::get_member_referrer_by_code_request::Request {
|
||||||
|
code: req.code,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_get_member_referrer_by_code_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member_referrer::SUBJECT_GET_MEMBER_REFERRER_BY_CODE,
|
||||||
|
ss_get_member_referrer_by_code_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_by_code_res =
|
||||||
|
bpr::ss::member_referrer::GetMemberReferrerByCodeResponse::decode(
|
||||||
|
ss_get_member_referrer_by_code_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_by_code_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_by_code_res.result {
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::c2se::member_referrer::GetMemberReferrerByCodeResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(
|
||||||
|
bpr::c2se::member_referrer::get_member_referrer_by_code_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::GetMemberReferrerByCodeResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user