create_member is added
This commit is contained in:
parent
5e85a12a01
commit
e80fd56720
|
@ -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.35-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.18-snapshot" }
|
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.23-snapshot" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl Service {
|
||||||
|
|
||||||
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
||||||
futures::try_join!(
|
futures::try_join!(
|
||||||
|
self.create_member(),
|
||||||
self.list_members(),
|
self.list_members(),
|
||||||
self.get_member(),
|
self.get_member(),
|
||||||
self.get_member_by_username(),
|
self.get_member_by_username(),
|
||||||
|
@ -69,6 +70,113 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn create_member(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
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<dyn std::error::Error>> {
|
async fn list_members(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let s = self
|
let s = self
|
||||||
.connection_broker
|
.connection_broker
|
||||||
|
|
Loading…
Reference in New Issue
Block a user