refactoring

This commit is contained in:
병준 박 2022-08-14 03:13:35 +00:00
parent 3abb518c8b
commit 2e74b835e0
16 changed files with 3456 additions and 502 deletions

View File

@ -28,20 +28,18 @@
"extensions": [ "extensions": [
"donjayamanne.githistory", "donjayamanne.githistory",
"eamodio.gitlens", "eamodio.gitlens",
"matklad.rust-analyzer",
"mhutchie.git-graph", "mhutchie.git-graph",
"ms-azuretools.vscode-docker", "ms-azuretools.vscode-docker",
"mutantdino.resourcemonitor", "mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"serayuzgur.crates", "serayuzgur.crates",
"tamasfe.even-better-toml", "tamasfe.even-better-toml",
"vadimcn.vscode-lldb" "vadimcn.vscode-lldb"
] ]
} }
}, },
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [], // "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "docker --version", // "postCreateCommand": "docker --version",
"postCreateCommand": "bash ./.devcontainer/scripts/postCreateCommand.sh", "postCreateCommand": "bash ./.devcontainer/scripts/postCreateCommand.sh",

View File

@ -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.43-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.26-snapshot" } beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.32-snapshot" }
[build-dependencies] [build-dependencies]

1
src/bank/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod service;

578
src/bank/service.rs Normal file
View File

@ -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<dyn std::error::Error>> {
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<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_bank(&self) -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}
}

View File

@ -81,9 +81,8 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::common::identity::CheckUsernameForDuplicationRequest::decode( let req =
message.data.as_slice(), bpr::c2se::identity::CheckUsernameForDuplicationRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), message: format!("invalid request: {}", e),
@ -91,15 +90,19 @@ impl Service {
})?; })?;
let ss_check_username_for_duplication_req = let ss_check_username_for_duplication_req =
bpr::ss::member::identity::CheckUsernameForDuplicationRequest { bpr::ss::identity::CheckUsernameForDuplicationRequest {
client: Some(client), client: Some(client),
request: Some(
bpr::ss::identity::check_username_for_duplication_request::Request {
username: req.username, username: req.username,
},
),
}; };
let ss_check_username_for_duplication_res_msg = self let ss_check_username_for_duplication_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_check_username_for_duplication_req.encode_to_vec(),
) )
.await .await
@ -112,7 +115,7 @@ impl Service {
})?; })?;
let ss_check_username_for_duplication_res = 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(), ss_check_username_for_duplication_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -134,10 +137,10 @@ impl Service {
if let Some(r) = ss_check_username_for_duplication_res.result { if let Some(r) = ss_check_username_for_duplication_res.result {
message message
.respond( .respond(
bpr::c2se::common::identity::CheckUsernameForDuplicationResponse { bpr::c2se::identity::CheckUsernameForDuplicationResponse {
error: None, error: None,
result: Some( result: Some(
bpr::c2se::common::identity::check_username_for_duplication_response::Result { bpr::c2se::identity::check_username_for_duplication_response::Result {
duplicated: r.duplicated, duplicated: r.duplicated,
}, },
), ),
@ -160,7 +163,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::common::identity::CheckUsernameForDuplicationResponse { bpr::c2se::identity::CheckUsernameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -186,9 +189,8 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::common::identity::CheckNicknameForDuplicationRequest::decode( let req =
message.data.as_slice(), bpr::c2se::identity::CheckNicknameForDuplicationRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), message: format!("invalid request: {}", e),
@ -196,15 +198,19 @@ impl Service {
})?; })?;
let ss_check_nickname_for_duplication_req = let ss_check_nickname_for_duplication_req =
bpr::ss::member::identity::CheckNicknameForDuplicationRequest { bpr::ss::identity::CheckNicknameForDuplicationRequest {
client: Some(client), client: Some(client),
request: Some(
bpr::ss::identity::check_nickname_for_duplication_request::Request {
nickname: req.nickname, nickname: req.nickname,
},
),
}; };
let ss_check_nickname_for_duplication_res_msg = self let ss_check_nickname_for_duplication_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_check_nickname_for_duplication_req.encode_to_vec(),
) )
.await .await
@ -217,7 +223,7 @@ impl Service {
})?; })?;
let ss_check_nickname_for_duplication_res = 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(), ss_check_nickname_for_duplication_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -239,10 +245,10 @@ impl Service {
if let Some(r) = ss_check_nickname_for_duplication_res.result { if let Some(r) = ss_check_nickname_for_duplication_res.result {
message message
.respond( .respond(
bpr::c2se::common::identity::CheckNicknameForDuplicationResponse { bpr::c2se::identity::CheckNicknameForDuplicationResponse {
error: None, error: None,
result: Some( result: Some(
bpr::c2se::common::identity::check_nickname_for_duplication_response::Result { bpr::c2se::identity::check_nickname_for_duplication_response::Result {
duplicated: r.duplicated, duplicated: r.duplicated,
}, },
), ),
@ -265,7 +271,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::common::identity::CheckNicknameForDuplicationResponse { bpr::c2se::identity::CheckNicknameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -291,21 +297,22 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let _req = bpr::c2se::common::identity::CaptchaRequest::decode(message.data.as_slice()) let _req =
.map_err(|e| { bpr::c2se::identity::CaptchaRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::identity::captcha_request::Request {}),
}; };
let ss_captcha_res_msg = self let ss_captcha_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::identity::SUBJECT_CAPTCHA, bpr::ss::identity::SUBJECT_CAPTCHA,
ss_captcha_req.encode_to_vec(), ss_captcha_req.encode_to_vec(),
) )
.await .await
@ -317,8 +324,9 @@ impl Service {
}) })
})?; })?;
let ss_captcha_res = let ss_captcha_res = bpr::ss::identity::CaptchaResponse::decode(
bpr::ss::member::identity::CaptchaResponse::decode(ss_captcha_res_msg.data.as_slice()) ss_captcha_res_msg.data.as_slice(),
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -338,9 +346,9 @@ impl Service {
if let Some(r) = ss_captcha_res.result { if let Some(r) = ss_captcha_res.result {
message message
.respond( .respond(
bpr::c2se::common::identity::CaptchaResponse { bpr::c2se::identity::CaptchaResponse {
error: None, 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, security_code_hash: r.security_code_hash,
image: r.image, image: r.image,
}), }),
@ -363,7 +371,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::common::identity::CaptchaResponse { bpr::c2se::identity::CaptchaResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -389,25 +397,27 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::identity::SigninRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::identity::SigninRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::identity::signin_request::Request {
security_code_hash: req.security_code_hash, security_code_hash: req.security_code_hash,
security_code: req.security_code, security_code: req.security_code,
username: req.username, username: req.username,
password: req.password, password: req.password,
}),
}; };
let ss_signin_res_msg = self let ss_signin_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::identity::SUBJECT_SIGNIN, bpr::ss::identity::SUBJECT_SIGNIN,
ss_signin_req.encode_to_vec(), ss_signin_req.encode_to_vec(),
) )
.await .await
@ -419,8 +429,9 @@ impl Service {
}) })
})?; })?;
let ss_signin_res = let ss_signin_res = bpr::ss::identity::SigninResponse::decode(
bpr::ss::member::identity::SigninResponse::decode(ss_signin_res_msg.data.as_slice()) ss_signin_res_msg.data.as_slice(),
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -440,9 +451,9 @@ impl Service {
if let Some(r) = ss_signin_res.result { if let Some(r) = ss_signin_res.result {
message message
.respond( .respond(
bpr::c2se::backend::identity::SigninResponse { bpr::c2se::identity::SigninResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::identity::signin_response::Result { result: Some(bpr::c2se::identity::signin_response::Result {
access_token: r.access_token, access_token: r.access_token,
}), }),
} }
@ -464,7 +475,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::identity::SigninResponse { bpr::c2se::identity::SigninResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }

View File

@ -1,7 +1,11 @@
use std::env; use std::env;
mod bank;
mod identity; mod identity;
mod member; mod member;
mod member_bank_account;
mod member_bank_deposit;
mod member_bank_withdraw;
mod member_class; mod member_class;
mod member_level; mod member_level;
mod site; mod site;
@ -20,24 +24,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let broker_opts = nats::asynk::Options::new(); let broker_opts = nats::asynk::Options::new();
let connection_broker = broker_opts.connect(url_broker).await?; 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 = 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_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 = let member_class_service =
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_service = let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone());
member::service::Service::new(connection_broker.clone(), queue_broker.clone());
println!("Server edge[beteran-backend-server-edge] is started"); println!("Server edge[beteran-backend-server-edge] is started");
futures::try_join!( futures::try_join!(
site_service.subscribe(), bank_service.subscribe(),
identity_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_class_service.subscribe(),
member_level_service.subscribe(), member_level_service.subscribe(),
member_service.subscribe(), site_service.subscribe(),
)?; )?;
Ok(()) Ok(())

View File

@ -83,15 +83,16 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member::CreateMemberRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::member::CreateMemberRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::member::create_member_request::Request {
site_id: req.site_id, site_id: req.site_id,
member_level_id: req.member_level_id, member_level_id: req.member_level_id,
mobile_phone_number: req.mobile_phone_number, mobile_phone_number: req.mobile_phone_number,
@ -101,12 +102,13 @@ impl Service {
password: req.password, password: req.password,
nickname: req.nickname, nickname: req.nickname,
state: req.state, state: req.state,
}),
}; };
let ss_create_member_res_msg = self let ss_create_member_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::member::SUBJECT_CREATE_MEMBER, bpr::ss::member::SUBJECT_CREATE_MEMBER,
ss_create_member_req.encode_to_vec(), ss_create_member_req.encode_to_vec(),
) )
.await .await
@ -118,9 +120,8 @@ impl Service {
}) })
})?; })?;
let ss_create_member_res = bpr::ss::member::member::CreateMemberResponse::decode( let ss_create_member_res =
ss_create_member_res_msg.data.as_slice(), bpr::ss::member::CreateMemberResponse::decode(ss_create_member_res_msg.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -140,9 +141,9 @@ impl Service {
if let Some(r) = ss_create_member_res.result { if let Some(r) = ss_create_member_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member::CreateMemberResponse { bpr::c2se::member::CreateMemberResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::member::create_member_response::Result { result: Some(bpr::c2se::member::create_member_response::Result {
member: r.member, member: r.member,
}), }),
} }
@ -164,7 +165,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::CreateMemberResponse { bpr::c2se::member::CreateMemberResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -190,34 +191,40 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member::ListMembersRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::member::ListMembersRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::member::list_members_request::Request {
pagination: req.pagination, pagination: req.pagination,
searches: req.searches,
sorts: req.sorts, sorts: req.sorts,
site_id: req.site_id, search: match req.search {
member_class_id: req.member_class_id, Some(s) => Some(bpr::ss::member::list_members_request::request::Search {
member_level_id: req.member_level_id, site_id: s.site_id,
referrer_member_id: req.referrer_member_id, member_class_id: s.member_class_id,
username_like: req.username_like, member_level_id: s.member_level_id,
nickname_like: req.nickname_like, referrer_member_id: s.referrer_member_id,
mobile_phone_number_like: req.mobile_phone_number_like, username_like: s.username_like,
last_signined_ip: req.last_signined_ip, nickname_like: s.nickname_like,
state: req.state, mobile_phone_number_like: s.mobile_phone_number_like,
deleted_at: req.deleted_at, last_signined_ip: s.last_signined_ip,
state: s.state,
deleted_at: s.deleted_at,
}),
None => None,
},
}),
}; };
let ss_list_members_res_msg = self let ss_list_members_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::member::SUBJECT_LIST_MEMBERS, bpr::ss::member::SUBJECT_LIST_MEMBERS,
ss_list_members_req.encode_to_vec(), ss_list_members_req.encode_to_vec(),
) )
.await .await
@ -229,9 +236,8 @@ impl Service {
}) })
})?; })?;
let ss_list_members_res = bpr::ss::member::member::ListMembersResponse::decode( let ss_list_members_res =
ss_list_members_res_msg.data.as_slice(), bpr::ss::member::ListMembersResponse::decode(ss_list_members_res_msg.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -251,9 +257,9 @@ impl Service {
if let Some(r) = ss_list_members_res.result { if let Some(r) = ss_list_members_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member::ListMembersResponse { bpr::c2se::member::ListMembersResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::member::list_members_response::Result { result: Some(bpr::c2se::member::list_members_response::Result {
members: r.members, members: r.members,
}), }),
} }
@ -275,7 +281,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::ListMembersResponse { bpr::c2se::member::ListMembersResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -301,22 +307,22 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member::GetMemberRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::member::GetMemberRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), 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 let ss_get_member_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::member::SUBJECT_GET_MEMBER, bpr::ss::member::SUBJECT_GET_MEMBER,
ss_get_member_req.encode_to_vec(), ss_get_member_req.encode_to_vec(),
) )
.await .await
@ -329,7 +335,7 @@ impl Service {
})?; })?;
let ss_get_member_res = 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| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -349,11 +355,9 @@ impl Service {
if let Some(r) = ss_get_member_res.result { if let Some(r) = ss_get_member_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member::GetMemberResponse { bpr::c2se::member::GetMemberResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::member::get_member_response::Result { result: Some(bpr::c2se::member::get_member_response::Result { member: r.member }),
member: r.member,
}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -373,7 +377,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::GetMemberResponse { bpr::c2se::member::GetMemberResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -399,23 +403,24 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = let req = bpr::c2se::member::GetMemberByUsernameRequest::decode(message.data.as_slice())
bpr::c2se::backend::member::GetMemberByUsernameRequest::decode(message.data.as_slice())
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::member::get_member_by_username_request::Request {
username: req.username, username: req.username,
}),
}; };
let ss_get_member_by_username_res_msg = self let ss_get_member_by_username_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_get_member_by_username_req.encode_to_vec(),
) )
.await .await
@ -427,8 +432,7 @@ impl Service {
}) })
})?; })?;
let ss_get_member_by_username_res = let ss_get_member_by_username_res = bpr::ss::member::GetMemberByUsernameResponse::decode(
bpr::ss::member::member::GetMemberByUsernameResponse::decode(
ss_get_member_by_username_res_msg.data.as_slice(), ss_get_member_by_username_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -450,13 +454,11 @@ impl Service {
if let Some(r) = ss_get_member_by_username_res.result { if let Some(r) = ss_get_member_by_username_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member::GetMemberByUsernameResponse { bpr::c2se::member::GetMemberByUsernameResponse {
error: None, error: None,
result: Some( result: Some(bpr::c2se::member::get_member_by_username_response::Result {
bpr::c2se::backend::member::get_member_by_username_response::Result {
member: r.member, member: r.member,
}, }),
),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -476,7 +478,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::GetMemberByUsernameResponse { bpr::c2se::member::GetMemberByUsernameResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -502,27 +504,28 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member::UpdateMemberRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::member::UpdateMemberRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::member::update_member_request::Request {
id: req.id, id: req.id,
site_id: req.site_id, site_id: req.site_id,
member_level_id: req.member_level_id, member_level_id: req.member_level_id,
password: req.password, password: req.password,
mobile_phone_number: req.mobile_phone_number, mobile_phone_number: req.mobile_phone_number,
state: req.state, }),
}; };
let ss_update_member_res_msg = self let ss_update_member_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::member::SUBJECT_UPDATE_MEMBER, bpr::ss::member::SUBJECT_UPDATE_MEMBER,
ss_update_member_req.encode_to_vec(), ss_update_member_req.encode_to_vec(),
) )
.await .await
@ -534,9 +537,8 @@ impl Service {
}) })
})?; })?;
let ss_update_member_res = bpr::ss::member::member::UpdateMemberResponse::decode( let ss_update_member_res =
ss_update_member_res_msg.data.as_slice(), bpr::ss::member::UpdateMemberResponse::decode(ss_update_member_res_msg.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -556,9 +558,9 @@ impl Service {
if let Some(r) = ss_update_member_res.result { if let Some(r) = ss_update_member_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member::UpdateMemberResponse { bpr::c2se::member::UpdateMemberResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::member::update_member_response::Result { result: Some(bpr::c2se::member::update_member_response::Result {
member: r.member, member: r.member,
}), }),
} }
@ -580,7 +582,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::UpdateMemberResponse { bpr::c2se::member::UpdateMemberResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -606,22 +608,22 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member::DeleteMemberRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::member::DeleteMemberRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), 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 let ss_delete_member_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::member::member::SUBJECT_DELETE_MEMBER, bpr::ss::member::SUBJECT_DELETE_MEMBER,
ss_delete_member_req.encode_to_vec(), ss_delete_member_req.encode_to_vec(),
) )
.await .await
@ -633,9 +635,8 @@ impl Service {
}) })
})?; })?;
let ss_delete_member_res = bpr::ss::member::member::DeleteMemberResponse::decode( let ss_delete_member_res =
ss_delete_member_res_msg.data.as_slice(), bpr::ss::member::DeleteMemberResponse::decode(ss_delete_member_res_msg.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -655,9 +656,9 @@ 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::backend::member::DeleteMemberResponse { bpr::c2se::member::DeleteMemberResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::member::delete_member_response::Result {}), result: Some(bpr::c2se::member::delete_member_response::Result {}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -677,7 +678,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member::DeleteMemberResponse { bpr::c2se::member::DeleteMemberResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }

View File

@ -0,0 +1 @@
pub mod service;

View File

@ -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<dyn std::error::Error>> {
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<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_bank_account(&self) -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}
}

View File

@ -0,0 +1 @@
pub mod service;

View File

@ -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<dyn std::error::Error>> {
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<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_bank_deposit(&self) -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}
}

View File

@ -0,0 +1 @@
pub mod service;

View File

@ -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<dyn std::error::Error>> {
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<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_bank_withdraw(&self) -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}
}

View File

@ -26,8 +26,9 @@ 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.list_member_classes(),
self.create_member_class(), self.create_member_class(),
self.list_member_classes(),
self.get_member_class(),
self.update_member_class(), self.update_member_class(),
self.delete_member_class(), self.delete_member_class(),
) )
@ -81,25 +82,28 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_class::CreateMemberClassRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_class::CreateMemberClassRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(
bpr::ss::member_class::create_member_class_request::Request {
parent_id: req.parent_id, parent_id: req.parent_id,
name: req.name, name: req.name,
},
),
}; };
let ss_create_member_class_res_msg = self let ss_create_member_class_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_create_member_class_req.encode_to_vec(),
) )
.await .await
@ -111,8 +115,7 @@ impl Service {
}) })
})?; })?;
let ss_create_member_class_res = let ss_create_member_class_res = bpr::ss::member_class::CreateMemberClassResponse::decode(
bpr::ss::member::member_class::CreateMemberClassResponse::decode(
ss_create_member_class_res_msg.data.as_slice(), ss_create_member_class_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -134,10 +137,10 @@ impl Service {
if let Some(r) = ss_create_member_class_res.result { if let Some(r) = ss_create_member_class_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_class::CreateMemberClassResponse { bpr::c2se::member_class::CreateMemberClassResponse {
error: None, error: None,
result: Some( 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, member_class: r.member_class,
}, },
), ),
@ -160,7 +163,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_class::CreateMemberClassResponse { bpr::c2se::member_class::CreateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -186,27 +189,36 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_class::ListMemberClassesRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_class::ListMemberClassesRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(
bpr::ss::member_class::list_member_classes_request::Request {
pagination: req.pagination, pagination: req.pagination,
searches: req.searches,
sorts: req.sorts, sorts: req.sorts,
name_like: req.name_like, 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 let ss_list_member_classes_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_list_member_classes_req.encode_to_vec(),
) )
.await .await
@ -218,8 +230,7 @@ impl Service {
}) })
})?; })?;
let ss_list_member_classes_res = let ss_list_member_classes_res = bpr::ss::member_class::ListMemberClassesResponse::decode(
bpr::ss::member::member_class::ListMemberClassesResponse::decode(
ss_list_member_classes_res_msg.data.as_slice(), ss_list_member_classes_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -241,10 +252,10 @@ impl Service {
if let Some(r) = ss_list_member_classes_res.result { if let Some(r) = ss_list_member_classes_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_class::ListMemberClassesResponse { bpr::c2se::member_class::ListMemberClassesResponse {
error: None, error: None,
result: Some( 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, member_classes: r.member_classes,
}, },
), ),
@ -267,7 +278,106 @@ impl Service {
{ {
message message
.respond( .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<dyn std::error::Error>> {
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)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -293,26 +403,29 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_class::UpdateMemberClassRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_class::UpdateMemberClassRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(
bpr::ss::member_class::update_member_class_request::Request {
id: req.id, id: req.id,
parent_id: req.parent_id, parent_id: req.parent_id,
name: req.name, name: req.name,
},
),
}; };
let ss_update_member_class_res_msg = self let ss_update_member_class_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_update_member_class_req.encode_to_vec(),
) )
.await .await
@ -324,8 +437,7 @@ impl Service {
}) })
})?; })?;
let ss_update_member_class_res = let ss_update_member_class_res = bpr::ss::member_class::UpdateMemberClassResponse::decode(
bpr::ss::member::member_class::UpdateMemberClassResponse::decode(
ss_update_member_class_res_msg.data.as_slice(), ss_update_member_class_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -347,10 +459,10 @@ impl Service {
if let Some(r) = ss_update_member_class_res.result { if let Some(r) = ss_update_member_class_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_class::UpdateMemberClassResponse { bpr::c2se::member_class::UpdateMemberClassResponse {
error: None, error: None,
result: Some( 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, member_class: r.member_class,
}, },
), ),
@ -373,7 +485,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_class::UpdateMemberClassResponse { bpr::c2se::member_class::UpdateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -399,24 +511,23 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_class::DeleteMemberClassRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_class::DeleteMemberClassRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), 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 let ss_delete_member_class_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_delete_member_class_req.encode_to_vec(),
) )
.await .await
@ -428,8 +539,7 @@ impl Service {
}) })
})?; })?;
let ss_delete_member_class_res = let ss_delete_member_class_res = bpr::ss::member_class::DeleteMemberClassResponse::decode(
bpr::ss::member::member_class::DeleteMemberClassResponse::decode(
ss_delete_member_class_res_msg.data.as_slice(), ss_delete_member_class_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -451,11 +561,9 @@ impl Service {
if let Some(r) = ss_delete_member_class_res.result { if let Some(r) = ss_delete_member_class_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_class::DeleteMemberClassResponse { bpr::c2se::member_class::DeleteMemberClassResponse {
error: None, error: None,
result: Some( result: Some(bpr::c2se::member_class::delete_member_class_response::Result {}),
bpr::c2se::backend::member_class::delete_member_class_response::Result {},
),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -475,7 +583,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_class::DeleteMemberClassResponse { bpr::c2se::member_class::DeleteMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }

View File

@ -26,8 +26,9 @@ 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.list_member_levels(),
self.create_member_level(), self.create_member_level(),
self.list_member_levels(),
self.get_member_level(),
self.update_member_level(), self.update_member_level(),
self.delete_member_level(), self.delete_member_level(),
) )
@ -81,25 +82,28 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_level::CreateMemberLevelRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_level::CreateMemberLevelRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(
bpr::ss::member_level::create_member_level_request::Request {
name: req.name, name: req.name,
sort_order: req.sort_order, sort_order: req.sort_order,
},
),
}; };
let ss_create_member_level_res_msg = self let ss_create_member_level_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_create_member_level_req.encode_to_vec(),
) )
.await .await
@ -111,8 +115,7 @@ impl Service {
}) })
})?; })?;
let ss_create_member_level_res = let ss_create_member_level_res = bpr::ss::member_level::CreateMemberLevelResponse::decode(
bpr::ss::member::member_level::CreateMemberLevelResponse::decode(
ss_create_member_level_res_msg.data.as_slice(), ss_create_member_level_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -134,10 +137,10 @@ impl Service {
if let Some(r) = ss_create_member_level_res.result { if let Some(r) = ss_create_member_level_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_level::CreateMemberLevelResponse { bpr::c2se::member_level::CreateMemberLevelResponse {
error: None, error: None,
result: Some( 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, member_level: r.member_level,
}, },
), ),
@ -160,7 +163,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_level::CreateMemberLevelResponse { bpr::c2se::member_level::CreateMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -186,27 +189,33 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_level::ListMemberLevelsRequest::decode( let req = bpr::c2se::member_level::ListMemberLevelsRequest::decode(message.data.as_slice())
message.data.as_slice(),
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::member_level::list_member_levels_request::Request {
pagination: req.pagination, pagination: req.pagination,
searches: req.searches,
sorts: req.sorts, sorts: req.sorts,
name_like: req.name_like, 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 let ss_list_member_levels_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_list_member_levels_req.encode_to_vec(),
) )
.await .await
@ -218,8 +227,7 @@ impl Service {
}) })
})?; })?;
let ss_list_member_levels_res = let ss_list_member_levels_res = bpr::ss::member_level::ListMemberLevelsResponse::decode(
bpr::ss::member::member_level::ListMemberLevelsResponse::decode(
ss_list_member_levels_res_msg.data.as_slice(), ss_list_member_levels_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -241,10 +249,10 @@ impl Service {
if let Some(r) = ss_list_member_levels_res.result { if let Some(r) = ss_list_member_levels_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_level::ListMemberLevelsResponse { bpr::c2se::member_level::ListMemberLevelsResponse {
error: None, error: None,
result: Some( 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, member_levels: r.member_levels,
}, },
), ),
@ -267,7 +275,106 @@ impl Service {
{ {
message message
.respond( .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<dyn std::error::Error>> {
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)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -293,26 +400,29 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_level::UpdateMemberLevelRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_level::UpdateMemberLevelRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(
bpr::ss::member_level::update_member_level_request::Request {
id: req.id, id: req.id,
name: req.name, name: req.name,
sort_order: req.sort_order, sort_order: req.sort_order,
},
),
}; };
let ss_update_member_level_res_msg = self let ss_update_member_level_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_update_member_level_req.encode_to_vec(),
) )
.await .await
@ -324,8 +434,7 @@ impl Service {
}) })
})?; })?;
let ss_update_member_level_res = let ss_update_member_level_res = bpr::ss::member_level::UpdateMemberLevelResponse::decode(
bpr::ss::member::member_level::UpdateMemberLevelResponse::decode(
ss_update_member_level_res_msg.data.as_slice(), ss_update_member_level_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -347,10 +456,10 @@ impl Service {
if let Some(r) = ss_update_member_level_res.result { if let Some(r) = ss_update_member_level_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_level::UpdateMemberLevelResponse { bpr::c2se::member_level::UpdateMemberLevelResponse {
error: None, error: None,
result: Some( 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, member_level: r.member_level,
}, },
), ),
@ -373,7 +482,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_level::UpdateMemberLevelResponse { bpr::c2se::member_level::UpdateMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -399,24 +508,23 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::member_level::DeleteMemberLevelRequest::decode( let req =
message.data.as_slice(), bpr::c2se::member_level::DeleteMemberLevelRequest::decode(message.data.as_slice())
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), 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 let ss_delete_member_level_res_msg = self
.connection_broker .connection_broker
.request( .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(), ss_delete_member_level_req.encode_to_vec(),
) )
.await .await
@ -428,8 +536,7 @@ impl Service {
}) })
})?; })?;
let ss_delete_member_level_res = let ss_delete_member_level_res = bpr::ss::member_level::DeleteMemberLevelResponse::decode(
bpr::ss::member::member_level::DeleteMemberLevelResponse::decode(
ss_delete_member_level_res_msg.data.as_slice(), ss_delete_member_level_res_msg.data.as_slice(),
) )
.map_err(|e| { .map_err(|e| {
@ -451,11 +558,9 @@ impl Service {
if let Some(r) = ss_delete_member_level_res.result { if let Some(r) = ss_delete_member_level_res.result {
message message
.respond( .respond(
bpr::c2se::backend::member_level::DeleteMemberLevelResponse { bpr::c2se::member_level::DeleteMemberLevelResponse {
error: None, error: None,
result: Some( result: Some(bpr::c2se::member_level::delete_member_level_response::Result {}),
bpr::c2se::backend::member_level::delete_member_level_response::Result {},
),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -475,7 +580,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::member_level::DeleteMemberLevelResponse { bpr::c2se::member_level::DeleteMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }

View File

@ -26,8 +26,9 @@ 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.list_sites(),
self.create_site(), self.create_site(),
self.list_sites(),
self.get_site(),
self.update_site(), self.update_site(),
self.delete_site(), self.delete_site(),
) )
@ -81,30 +82,36 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::site::ListSitesRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::site::ListSitesRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::site::list_sites_request::Request {
pagination: req.pagination, pagination: req.pagination,
searches: req.searches,
sorts: req.sorts, sorts: req.sorts,
url_like: req.url_like, search: match req.search {
name_like: req.name_like, Some(s) => Some(bpr::ss::site::list_sites_request::request::Search {
path_like: req.path_like, url_like: s.url_like,
show: req.show, name_like: s.name_like,
can_use: req.can_use, path_like: s.path_like,
memo_like: req.memo_like, show: s.show,
can_use: s.can_use,
memo_like: s.memo_like,
}),
None => None,
},
}),
}; };
let ss_list_sites_res_msg = self let ss_list_sites_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::domain::site::SUBJECT_LIST_SITES, bpr::ss::site::SUBJECT_LIST_SITES,
ss_list_sites_req.encode_to_vec(), ss_list_sites_req.encode_to_vec(),
) )
.await .await
@ -116,8 +123,9 @@ impl Service {
}) })
})?; })?;
let ss_list_sites_res = let ss_list_sites_res = bpr::ss::site::ListSitesResponse::decode(
bpr::ss::domain::site::ListSitesResponse::decode(ss_list_sites_res_msg.data.as_slice()) ss_list_sites_res_msg.data.as_slice(),
)
.map_err(|e| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -137,11 +145,9 @@ impl Service {
if let Some(r) = ss_list_sites_res.result { if let Some(r) = ss_list_sites_res.result {
message message
.respond( .respond(
bpr::c2se::backend::site::ListSitesResponse { bpr::c2se::site::ListSitesResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::site::list_sites_response::Result { result: Some(bpr::c2se::site::list_sites_response::Result { sites: r.sites }),
sites: r.sites,
}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -161,7 +167,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::site::ListSitesResponse { bpr::c2se::site::ListSitesResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -187,15 +193,16 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::site::CreateSiteRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::site::CreateSiteRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::site::create_site_request::Request {
url: req.url, url: req.url,
name: req.name, name: req.name,
path: req.path, path: req.path,
@ -203,12 +210,13 @@ impl Service {
can_use: req.can_use, can_use: req.can_use,
memo: req.memo, memo: req.memo,
expires_at: req.expires_at, expires_at: req.expires_at,
}),
}; };
let ss_create_site_res_msg = self let ss_create_site_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::domain::site::SUBJECT_CREATE_SITE, bpr::ss::site::SUBJECT_CREATE_SITE,
ss_create_site_req.encode_to_vec(), ss_create_site_req.encode_to_vec(),
) )
.await .await
@ -221,7 +229,7 @@ impl Service {
})?; })?;
let ss_create_site_res = 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| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -241,11 +249,9 @@ impl Service {
if let Some(r) = ss_create_site_res.result { if let Some(r) = ss_create_site_res.result {
message message
.respond( .respond(
bpr::c2se::backend::site::CreateSiteResponse { bpr::c2se::site::CreateSiteResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::site::create_site_response::Result { result: Some(bpr::c2se::site::create_site_response::Result { site: r.site }),
site: r.site,
}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -265,7 +271,104 @@ impl Service {
{ {
message message
.respond( .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<dyn std::error::Error>> {
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)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -291,15 +394,16 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::site::UpdateSiteRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::site::UpdateSiteRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), client: Some(client),
request: Some(bpr::ss::site::update_site_request::Request {
id: req.id, id: req.id,
url: req.url, url: req.url,
name: req.name, name: req.name,
@ -308,12 +412,13 @@ impl Service {
can_use: req.can_use, can_use: req.can_use,
memo: req.memo, memo: req.memo,
expires_at: req.expires_at, expires_at: req.expires_at,
}),
}; };
let ss_update_site_res_msg = self let ss_update_site_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::domain::site::SUBJECT_UPDATE_SITE, bpr::ss::site::SUBJECT_UPDATE_SITE,
ss_update_site_req.encode_to_vec(), ss_update_site_req.encode_to_vec(),
) )
.await .await
@ -326,7 +431,7 @@ impl Service {
})?; })?;
let ss_update_site_res = 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| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -346,11 +451,9 @@ impl Service {
if let Some(r) = ss_update_site_res.result { if let Some(r) = ss_update_site_res.result {
message message
.respond( .respond(
bpr::c2se::backend::site::UpdateSiteResponse { bpr::c2se::site::UpdateSiteResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::site::update_site_response::Result { result: Some(bpr::c2se::site::update_site_response::Result { site: r.site }),
site: r.site,
}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -370,7 +473,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::site::UpdateSiteResponse { bpr::c2se::site::UpdateSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }
@ -396,22 +499,22 @@ impl Service {
if let Err(e) = async { if let Err(e) = async {
let client = self.get_client_in_header(&message)?; let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::backend::site::DeleteSiteRequest::decode(message.data.as_slice()) let req =
.map_err(|e| { bpr::c2se::site::DeleteSiteRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e), 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), 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 let ss_delete_site_res_msg = self
.connection_broker .connection_broker
.request( .request(
bpr::ss::domain::site::SUBJECT_DELETE_SITE, bpr::ss::site::SUBJECT_DELETE_SITE,
ss_delete_site_req.encode_to_vec(), ss_delete_site_req.encode_to_vec(),
) )
.await .await
@ -424,7 +527,7 @@ impl Service {
})?; })?;
let ss_delete_site_res = 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| { .map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server { bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00, code: bpr::protobuf::rpc::Error::SERVER_00,
@ -444,9 +547,9 @@ impl Service {
if let Some(r) = ss_delete_site_res.result { if let Some(r) = ss_delete_site_res.result {
message message
.respond( .respond(
bpr::c2se::backend::site::DeleteSiteResponse { bpr::c2se::site::DeleteSiteResponse {
error: None, error: None,
result: Some(bpr::c2se::backend::site::delete_site_response::Result {}), result: Some(bpr::c2se::site::delete_site_response::Result {}),
} }
.encode_to_vec(), .encode_to_vec(),
) )
@ -466,7 +569,7 @@ impl Service {
{ {
message message
.respond( .respond(
bpr::c2se::backend::site::DeleteSiteResponse { bpr::c2se::site::DeleteSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)), error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None, result: None,
} }