Compare commits

..

No commits in common. "feature/BETERAN-BACKEND-SERVER-EDGE-init" and "main" have entirely different histories.

40 changed files with 0 additions and 9207 deletions

View File

@ -1,9 +0,0 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/debian/.devcontainer/base.Dockerfile
# [Choice] Debian version (use bullseye on local arm64/Apple Silicon): bullseye, buster
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# ** [Optional] Uncomment this section to install additional packages. **
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

View File

@ -1,66 +0,0 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/ubuntu
{
"name": "beteran-backend-server-edge",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
// Use bullseye when on local on arm64/Apple Silicon.
"VARIANT": "bullseye"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Use this environment variable if you need to bind mount your local source code into a new container.
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.verboseLogging": true,
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"donjayamanne.githistory",
"eamodio.gitlens",
"mhutchie.git-graph",
"ms-azuretools.vscode-docker",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
"postCreateCommand": "bash ./.devcontainer/scripts/postCreateCommand.sh",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"git": "latest",
"rust": "latest"
}
}

View File

@ -1,5 +0,0 @@
[toolchain]
channel = "stable"
profile = "minimal"
components = ["clippy", "rustfmt"]
targets = []

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
set -e

7
.gitignore vendored
View File

@ -1,7 +0,0 @@
.DS_Store
/build
# Added by cargo
/target
Cargo.lock

View File

@ -1,75 +0,0 @@
# https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=
array_width = 60
attr_fn_like_width = 70
binop_separator = "Front" # "Front", "Back"
blank_lines_lower_bound = 0
blank_lines_upper_bound = 1
brace_style = "SameLineWhere" #"AlwaysNextLine", "PreferSameLine", "SameLineWhere"
chain_width = 60
color = "Auto" #"Auto", "Always", "Never"
combine_control_expr = true # true, false
comment_width = 80
condense_wildcard_suffixes = false # true, false
control_brace_style = "AlwaysSameLine" # "AlwaysNextLine", "AlwaysSameLine", "ClosingNextLine"
disable_all_formatting = false # true, false
edition = "2015" # "2015", "2018", "2021"
empty_item_single_line = true # true, false
enum_discrim_align_threshold = 0
error_on_line_overflow = false # true, false
error_on_unformatted = false # true, false
fn_args_layout = "Tall" # "Compressed", "Tall", "Vertical"
fn_call_width = 60
fn_single_line = false # true, false
force_explicit_abi = true # true, false
force_multiline_blocks = false # true, false
format_code_in_doc_comments = false # true, false
format_generated_files = false # true, false
format_macro_matchers = false # true, false
format_macro_bodies = true # true, false
format_strings = false # true, false
group_imports = "Preserve" # "Preserve", "StdExternalCrate"
hard_tabs = false # true, false
hex_literal_case = "Preserve" # "Upper", "Lower"
hide_parse_errors = false # true, false
ignore = []
imports_indent = "Block" # "Block", "Visual"
imports_layout = "Mixed" # "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
indent_style = "Block" # "Block", "Visual"
inline_attribute_width = 0
license_template_path = ""
match_arm_blocks = true # true, false
match_arm_leading_pipes = "Never" # "Always", "Never", "Preserve"
match_block_trailing_comma = false # true, false
max_width = 100
merge_derives = true # true, false
imports_granularity = "Preserve" # "Preserve", "Crate", "Module", "Item", "One"
merge_imports = false # true, false
newline_style = "Auto" # "Auto", "Native", "Unix", "Windows"
normalize_comments = false # true, false
normalize_doc_attributes = false # true, false
overflow_delimited_expr = false # true, false
remove_nested_parens = true # true, false
reorder_impl_items = false # true, false
reorder_imports = true # true, false
reorder_modules = true # true, false
report_fixme = "Never" # "Always", "Unnumbered", "Never"
report_todo = "Never" # "Always", "Unnumbered", "Never"
skip_children = false # true, false
single_line_if_else_max_width = 50
space_after_colon = true # true, false
space_before_colon = false # true, false
spaces_around_ranges = false # true, false
struct_field_align_threshold = 0
struct_lit_single_line = true # true, false
struct_lit_width = 18
struct_variant_width = 35
tab_spaces = 2
trailing_comma = "Vertical" # "Always", "Never", "Vertical"
trailing_semicolon = true # true, false
type_punctuation_density = "Wide" # "Compressed", "Wide"
unstable_features = false # true, false
use_field_init_shorthand = false # true, false
use_small_heuristics = "Default" # "Default", "Off", "Max"
use_try_shorthand = false # true, false
where_single_line = false # true, false
wrap_comments = false # true, false

53
.vscode/launch.json vendored
View File

@ -1,53 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'beteran-backend-server-edge'",
"cargo": {
"args": [
"build",
"--bin=beteran-backend-server-edge",
"--package=beteran-backend-server-edge"
],
"filter": {
"name": "beteran-backend-server-edge",
"kind": "bin"
}
},
"env": {
"URL_BROKER": "nats://192.168.50.205:4222",
"QUEUE_BROKER": "bet.beteran",
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'beteran-backend-server-edge'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=beteran-backend-server-edge",
"--package=beteran-backend-server-edge"
],
"filter": {
"name": "beteran-backend-server-edge",
"kind": "bin"
}
},
"env": {
"URL_BROKER": "nats://192.168.50.205:4222",
"QUEUE_BROKER": "bet.beteran",
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

View File

@ -1,25 +0,0 @@
[package]
name = "beteran-backend-server-edge"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "beteran-backend-server-edge"
path = "./src/main.rs"
[dependencies]
futures = { version = "0", default-features = false, features = [
"async-await",
] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
prost = { version = "0" }
nats = { version = "0" }
base64 = { version = "0" }
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.99-snapshot" }
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.85-snapshot" }
[build-dependencies]

View File

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

View File

@ -1,321 +0,0 @@
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::betting::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.list_betting_history(),).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 list_betting_history(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::api::betting::SUBJECT_LIST_BETTING_HISTORY,
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::api::betting::ListBettingHistoryRequest::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_betting_history_req = bpr::ss::api::betting::ListBettingHistoryRequest {
client: Some(client.clone()),
request: Some(
bpr::ss::api::betting::list_betting_history_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(
bpr::ss::api::betting::list_betting_history_request::request::Search {
member_id: s.member_id,
vendor_id: s.vendor_id,
vendor_ids: s.vendor_ids,
vendor_name: s.vendor_name,
vendor_name_like: s.vendor_name_like,
game_id: s.game_id,
game_ids: s.game_ids,
game_name: s.game_name,
game_name_like: s.game_name_like,
game_category: s.game_category,
game_category_like: s.game_category_like,
game_type: s.game_type,
game_type_like: s.game_type_like,
currency: s.currency,
currency_like: s.currency_like,
key: s.key,
key_like: s.key_like,
ref_id: s.ref_id,
ref_id_like: s.ref_id_like,
o_ref_id: s.o_ref_id,
o_ref_id_like: s.o_ref_id_like,
group_key: s.group_key,
group_key_like: s.group_key_like,
is_bonus: s.is_bonus,
is_promo: s.is_promo,
is_jackpot: s.is_jackpot,
site_username: s.site_username,
site_username_like: s.site_username_like,
betting_type: s.betting_type,
betting_type_like: s.betting_type_like,
category: s.category,
category_like: s.category_like,
},
),
None => None,
},
},
),
};
let ss_list_betting_history_res_msg = self
.connection_broker
.request(
bpr::ss::api::betting::SUBJECT_LIST_BETTING_HISTORY,
ss_list_betting_history_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_betting_history_res =
bpr::ss::api::betting::ListBettingHistoryResponse::decode(
ss_list_betting_history_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_betting_history_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_betting_history_res.result {
let mut usernames: Vec<String> = vec![];
for b in &r.betting_history {
let username = b.site_username.clone();
if !usernames.contains(&username) {
usernames.push(username);
}
}
let members = if !usernames.is_empty() {
let ss_list_members_req = bpr::ss::member::ListMembersRequest {
client: Some(client.clone()),
request: Some(bpr::ss::member::list_members_request::Request {
pagination: None,
sorts: vec![],
search: Some(bpr::ss::member::list_members_request::request::Search {
site_id: None,
member_class_id: None,
member_level_id: None,
parent_member_id: None,
username: None,
usernames,
username_like: None,
nickname: None,
nicknames: vec![],
nickname_like: None,
mobile_phone_number_like: None,
last_signined_ip: None,
state: None,
deleted_at: None,
}),
}),
};
let ss_list_members_res_msg = self
.connection_broker
.request(
bpr::ss::member::SUBJECT_LIST_MEMBERS,
ss_list_members_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_members_res =
bpr::ss::member::ListMembersResponse::decode(ss_list_members_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_members_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,
}));
}
match ss_list_members_res.result {
Some(rr) => rr.members,
None => vec![],
}
} else {
vec![]
};
let mut betting_history: Vec<bpr::models::api::betting::BettingHistoryModel> = vec![];
for b in r.betting_history {
let member = members
.iter()
.find(|v| v.username.eq(&b.site_username))
.cloned();
betting_history.push(bpr::models::api::betting::BettingHistoryModel {
id: b.id,
vendor_id: b.vendor_id,
vendor_name: b.vendor_name,
game_id: b.game_id,
game_name: b.game_name,
game_category: b.game_category,
game_type: b.game_type,
currency: b.currency,
cash: b.cash,
before_cash: b.before_cash,
after_cash: b.after_cash,
group_key: b.group_key,
detail: b.detail,
is_bonus: b.is_bonus,
is_promo: b.is_promo,
is_jackpot: b.is_jackpot,
site_username: b.site_username,
key: b.key,
ref_id: b.ref_id,
o_ref_id: b.o_ref_id,
betting_type: b.betting_type,
category: b.category,
created_at: b.created_at,
utc_created_at: b.utc_created_at,
member,
});
}
message
.respond(
bpr::c2se::api::betting::ListBettingHistoryResponse {
error: None,
result: Some(
bpr::c2se::api::betting::list_betting_history_response::Result {
total_count: r.total_count,
betting_history,
},
),
}
.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::api::betting::ListBettingHistoryResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,176 +0,0 @@
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::game::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.list_games(),).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 list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::api::game::SUBJECT_LIST_GAMES,
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::api::game::ListGamesRequest::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_games_req = bpr::ss::api::game::ListGamesRequest {
client: Some(client),
request: Some(bpr::ss::api::game::list_games_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(bpr::ss::api::game::list_games_request::request::Search {
parent_id: s.parent_id,
key_like: s.key_like,
category_like: s.category_like,
platform_like: s.platform_like,
game_type_like: s.game_type_like,
}),
None => None,
},
}),
};
let ss_list_games_res_msg = self
.connection_broker
.request(
bpr::ss::api::game::SUBJECT_LIST_GAMES,
ss_list_games_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_games_res =
bpr::ss::api::game::ListGamesResponse::decode(ss_list_games_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_games_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_games_res.result {
message
.respond(
bpr::c2se::api::game::ListGamesResponse {
error: None,
result: Some(bpr::c2se::api::game::list_games_response::Result {
total_count: r.total_count,
games: r.games,
}),
}
.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::api::game::ListGamesResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

@ -1,3 +0,0 @@
pub mod game;
pub mod vendor;
pub mod betting;

View File

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

View File

@ -1,180 +0,0 @@
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::vendor::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.list_vendors(),).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 list_vendors(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::api::vendor::SUBJECT_LIST_VENDORS,
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::api::vendor::ListVendorsRequest::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_vendors_req = bpr::ss::api::vendor::ListVendorsRequest {
client: Some(client),
request: Some(bpr::ss::api::vendor::list_vendors_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(
bpr::ss::api::vendor::list_vendors_request::request::Search {
name_like: s.name_like,
company_id: s.company_id,
vendor_id: s.vendor_id,
key_like: s.key_like,
category_like: s.category_like,
is_enable: s.is_enable,
},
),
None => None,
},
}),
};
let ss_list_vendors_res_msg = self
.connection_broker
.request(
bpr::ss::api::vendor::SUBJECT_LIST_VENDORS,
ss_list_vendors_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_vendors_res = bpr::ss::api::vendor::ListVendorsResponse::decode(
ss_list_vendors_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_vendors_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_vendors_res.result {
message
.respond(
bpr::c2se::api::vendor::ListVendorsResponse {
error: None,
result: Some(bpr::c2se::api::vendor::list_vendors_response::Result {
total_count: r.total_count,
vendors: r.vendors,
}),
}
.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::api::vendor::ListVendorsResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,581 +0,0 @@
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 {
total_count: r.total_count,
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

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

View File

@ -1,490 +0,0 @@
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::identity::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.check_username_for_duplication(),
self.check_nickname_for_duplication(),
self.captcha(),
self.signin(),
)
.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 check_username_for_duplication(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::identity::SUBJECT_CHECK_USERNAME_FOR_DUPLICATION,
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::identity::CheckUsernameForDuplicationRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_check_username_for_duplication_req =
bpr::ss::identity::CheckUsernameForDuplicationRequest {
client: Some(client),
request: Some(
bpr::ss::identity::check_username_for_duplication_request::Request {
username: req.username,
},
),
};
let ss_check_username_for_duplication_res_msg = self
.connection_broker
.request(
bpr::ss::identity::SUBJECT_CHECK_USERNAME_FOR_DUPLICATION,
ss_check_username_for_duplication_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_check_username_for_duplication_res =
bpr::ss::identity::CheckUsernameForDuplicationResponse::decode(
ss_check_username_for_duplication_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_check_username_for_duplication_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_check_username_for_duplication_res.result {
message
.respond(
bpr::c2se::identity::CheckUsernameForDuplicationResponse {
error: None,
result: Some(
bpr::c2se::identity::check_username_for_duplication_response::Result {
duplicated: r.duplicated,
},
),
}
.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::identity::CheckUsernameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn check_nickname_for_duplication(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::identity::SUBJECT_CHECK_NICKNAME_FOR_DUPLICATION,
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::identity::CheckNicknameForDuplicationRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_check_nickname_for_duplication_req =
bpr::ss::identity::CheckNicknameForDuplicationRequest {
client: Some(client),
request: Some(
bpr::ss::identity::check_nickname_for_duplication_request::Request {
nickname: req.nickname,
},
),
};
let ss_check_nickname_for_duplication_res_msg = self
.connection_broker
.request(
bpr::ss::identity::SUBJECT_CHECK_NICKNAME_FOR_DUPLICATION,
ss_check_nickname_for_duplication_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_check_nickname_for_duplication_res =
bpr::ss::identity::CheckNicknameForDuplicationResponse::decode(
ss_check_nickname_for_duplication_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_check_nickname_for_duplication_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_check_nickname_for_duplication_res.result {
message
.respond(
bpr::c2se::identity::CheckNicknameForDuplicationResponse {
error: None,
result: Some(
bpr::c2se::identity::check_nickname_for_duplication_response::Result {
duplicated: r.duplicated,
},
),
}
.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::identity::CheckNicknameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn captcha(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::identity::SUBJECT_CAPTCHA,
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::identity::CaptchaRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_captcha_req = bpr::ss::identity::CaptchaRequest {
client: Some(client),
request: Some(bpr::ss::identity::captcha_request::Request {}),
};
let ss_captcha_res_msg = self
.connection_broker
.request(
bpr::ss::identity::SUBJECT_CAPTCHA,
ss_captcha_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_captcha_res = bpr::ss::identity::CaptchaResponse::decode(
ss_captcha_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_captcha_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_captcha_res.result {
message
.respond(
bpr::c2se::identity::CaptchaResponse {
error: None,
result: Some(bpr::c2se::identity::captcha_response::Result {
security_code_hash: r.security_code_hash,
image: r.image,
}),
}
.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::identity::CaptchaResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn signin(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::identity::SUBJECT_SIGNIN,
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::identity::SigninRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_signin_req = bpr::ss::identity::SigninRequest {
client: Some(client),
request: Some(bpr::ss::identity::signin_request::Request {
security_code_hash: req.security_code_hash,
security_code: req.security_code,
username: req.username,
password: req.password,
}),
};
let ss_signin_res_msg = self
.connection_broker
.request(
bpr::ss::identity::SUBJECT_SIGNIN,
ss_signin_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_signin_res = bpr::ss::identity::SigninResponse::decode(
ss_signin_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_signin_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_signin_res.result {
message
.respond(
bpr::c2se::identity::SigninResponse {
error: None,
result: Some(bpr::c2se::identity::signin_response::Result {
access_token: r.access_token,
}),
}
.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::identity::SigninResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

@ -1,85 +0,0 @@
use std::env;
mod bank;
mod identity;
mod member;
mod member_bank_account;
mod member_bank_deposit;
mod member_bank_withdraw;
mod member_class;
mod member_game_setting;
mod member_level;
mod member_referrer;
mod member_settlement_setting;
mod site;
mod api;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url_broker = match env::var_os("URL_BROKER") {
Some(v) => v.into_string().unwrap(),
None => "".to_string(),
};
let queue_broker = match env::var_os("QUEUE_BROKER") {
Some(v) => v.into_string().unwrap(),
None => "".to_string(),
};
let broker_opts = nats::asynk::Options::new();
let connection_broker = broker_opts.connect(url_broker).await?;
let bank_service = bank::service::Service::new(connection_broker.clone(), queue_broker.clone());
let identity_service =
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 =
member_class::service::Service::new(connection_broker.clone(), queue_broker.clone());
let member_game_setting_service =
member_game_setting::service::Service::new(connection_broker.clone(), queue_broker.clone());
let member_level_service =
member_level::service::Service::new(connection_broker.clone(), queue_broker.clone());
let member_referrer_service =
member_referrer::service::Service::new(connection_broker.clone(), queue_broker.clone());
let member_settlement_setting_service = member_settlement_setting::service::Service::new(
connection_broker.clone(),
queue_broker.clone(),
);
let site_service = site::service::Service::new(connection_broker.clone(), queue_broker.clone());
let api_vendor_service =
api::vendor::service::Service::new(connection_broker.clone(), queue_broker.clone());
let api_game_service =
api::game::service::Service::new(connection_broker.clone(), queue_broker.clone());
let api_betting_service =
api::betting::service::Service::new(connection_broker.clone(), queue_broker.clone());
println!("Server edge[beteran-backend-server-edge] is started");
futures::try_join!(
bank_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_game_setting_service.subscribe(),
member_level_service.subscribe(),
member_referrer_service.subscribe(),
member_settlement_setting_service.subscribe(),
site_service.subscribe(),
api_vendor_service.subscribe(),
api_game_service.subscribe(),
api_betting_service.subscribe(),
)?;
Ok(())
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,706 +0,0 @@
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.update_member_bank_account_for_exchange_password(),
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,
exchange_password: req.exchange_password,
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 {
total_count: r.total_count,
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 update_member_bank_account_for_exchange_password(&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_FOR_EXCHANGE_PASSWORD,
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::UpdateMemberBankAccountForExchangePasswordRequest::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::UpdateMemberBankAccountForExchangePasswordRequest {
client: Some(client),
request: Some(bpr::ss::member_bank_account::update_member_bank_account_for_exchange_password_request::Request{
id: req.id,
exchange_password: req.exchange_password,
})
};
let ss_update_member_bank_account_res_msg = self
.connection_broker
.request(
bpr::ss::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT_FOR_EXCHANGE_PASSWORD,
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::UpdateMemberBankAccountForExchangePasswordResponse::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::UpdateMemberBankAccountForExchangePasswordResponse {
error: None,
result: Some(bpr::c2se::member_bank_account::update_member_bank_account_for_exchange_password_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::UpdateMemberBankAccountForExchangePasswordResponse {
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

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

View File

@ -1,726 +0,0 @@
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 {
member_id: "".to_string(),
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 {
total_count: r.total_count,
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

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

View File

@ -1,708 +0,0 @@
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 {
member_id: "".to_string(),
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 {
total_count: r.total_count,
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

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

View File

@ -1,602 +0,0 @@
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_class::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_class(),
self.list_member_classes(),
self.get_member_class(),
self.update_member_class(),
self.delete_member_class(),
)
.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_class(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_class::SUBJECT_CREATE_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::CreateMemberClassRequest::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_class_req = bpr::ss::member_class::CreateMemberClassRequest {
client: Some(client),
request: Some(
bpr::ss::member_class::create_member_class_request::Request {
parent_id: req.parent_id,
name: req.name,
show: req.show,
},
),
};
let ss_create_member_class_res_msg = self
.connection_broker
.request(
bpr::ss::member_class::SUBJECT_CREATE_MEMBER_CLASS,
ss_create_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_create_member_class_res = bpr::ss::member_class::CreateMemberClassResponse::decode(
ss_create_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_create_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_create_member_class_res.result {
message
.respond(
bpr::c2se::member_class::CreateMemberClassResponse {
error: None,
result: Some(
bpr::c2se::member_class::create_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::CreateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn list_member_classes(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_class::SUBJECT_LIST_MEMBER_CLASSES,
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::ListMemberClassesRequest::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_classes_req = bpr::ss::member_class::ListMemberClassesRequest {
client: Some(client),
request: Some(
bpr::ss::member_class::list_member_classes_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(
bpr::ss::member_class::list_member_classes_request::request::Search {
name_like: s.name_like,
show: s.show,
},
),
None => None,
},
},
),
};
let ss_list_member_classes_res_msg = self
.connection_broker
.request(
bpr::ss::member_class::SUBJECT_LIST_MEMBER_CLASSES,
ss_list_member_classes_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_classes_res = bpr::ss::member_class::ListMemberClassesResponse::decode(
ss_list_member_classes_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_classes_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_classes_res.result {
message
.respond(
bpr::c2se::member_class::ListMemberClassesResponse {
error: None,
result: Some(
bpr::c2se::member_class::list_member_classes_response::Result {
total_count: r.total_count,
member_classes: r.member_classes,
},
),
}
.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::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)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_member_class(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_class::SUBJECT_UPDATE_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::UpdateMemberClassRequest::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_class_req = bpr::ss::member_class::UpdateMemberClassRequest {
client: Some(client),
request: Some(
bpr::ss::member_class::update_member_class_request::Request {
id: req.id,
parent_id: req.parent_id,
name: req.name,
show: req.show,
},
),
};
let ss_update_member_class_res_msg = self
.connection_broker
.request(
bpr::ss::member_class::SUBJECT_UPDATE_MEMBER_CLASS,
ss_update_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_update_member_class_res = bpr::ss::member_class::UpdateMemberClassResponse::decode(
ss_update_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_update_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_update_member_class_res.result {
message
.respond(
bpr::c2se::member_class::UpdateMemberClassResponse {
error: None,
result: Some(
bpr::c2se::member_class::update_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::UpdateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_class(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_class::SUBJECT_DELETE_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::DeleteMemberClassRequest::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_class_req = bpr::ss::member_class::DeleteMemberClassRequest {
client: Some(client),
request: Some(bpr::ss::member_class::delete_member_class_request::Request { id: req.id }),
};
let ss_delete_member_class_res_msg = self
.connection_broker
.request(
bpr::ss::member_class::SUBJECT_DELETE_MEMBER_CLASS,
ss_delete_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_delete_member_class_res = bpr::ss::member_class::DeleteMemberClassResponse::decode(
ss_delete_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_delete_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_delete_member_class_res.result {
message
.respond(
bpr::c2se::member_class::DeleteMemberClassResponse {
error: None,
result: Some(bpr::c2se::member_class::delete_member_class_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_class::DeleteMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,601 +0,0 @@
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_game_setting::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_game_setting(),
self.list_member_game_settings(),
self.get_member_game_setting(),
self.update_member_game_setting(),
self.delete_member_game_setting(),
)
.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_game_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_game_setting::SUBJECT_CREATE_MEMBER_GAME_SETTING,
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_game_setting::CreateMemberGameSettingRequest::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_game_setting_req =
bpr::ss::member_game_setting::CreateMemberGameSettingRequest {
client: Some(client),
request: Some(
bpr::ss::member_game_setting::create_member_game_setting_request::Request {
member_id: req.member_id,
can_bet_casino: req.can_bet_casino,
can_bet_slot: req.can_bet_slot,
can_bet_powerball: req.can_bet_powerball,
can_bet_powerladder: req.can_bet_powerladder,
can_bet_eos: req.can_bet_eos,
can_bet_bogglepowerball: req.can_bet_bogglepowerball,
},
),
};
let ss_create_member_game_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_game_setting::SUBJECT_CREATE_MEMBER_GAME_SETTING,
ss_create_member_game_setting_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_game_setting_res =
bpr::ss::member_game_setting::CreateMemberGameSettingResponse::decode(
ss_create_member_game_setting_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_game_setting_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_game_setting_res.result {
message
.respond(
bpr::c2se::member_game_setting::CreateMemberGameSettingResponse {
error: None,
result: Some(
bpr::c2se::member_game_setting::create_member_game_setting_response::Result {
member_game_setting: r.member_game_setting,
},
),
}
.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_game_setting::CreateMemberGameSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn list_member_game_settings(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_game_setting::SUBJECT_LIST_MEMBER_GAME_SETTINGS,
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_game_setting::ListMemberGameSettingsRequest::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_game_settings_req = bpr::ss::member_game_setting::ListMemberGameSettingsRequest {
client: Some(client),
request: Some(bpr::ss::member_game_setting::list_member_game_settings_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(bpr::ss::member_game_setting::list_member_game_settings_request::request::Search{
member_id: s.member_id,
}),
None => None,
}
})
};
let ss_list_member_game_settings_res_msg = self
.connection_broker
.request(
bpr::ss::member_game_setting::SUBJECT_LIST_MEMBER_GAME_SETTINGS,
ss_list_member_game_settings_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_game_settings_res =
bpr::ss::member_game_setting::ListMemberGameSettingsResponse::decode(ss_list_member_game_settings_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_game_settings_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_game_settings_res.result {
message
.respond(
bpr::c2se::member_game_setting::ListMemberGameSettingsResponse {
error: None,
result: Some(bpr::c2se::member_game_setting::list_member_game_settings_response::Result {
total_count: r.total_count,
member_game_settings: r.member_game_settings,
}),
}
.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_game_setting::ListMemberGameSettingsResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn get_member_game_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_game_setting::SUBJECT_GET_MEMBER_GAME_SETTING,
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_game_setting::GetMemberGameSettingRequest::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_game_setting_req = bpr::ss::member_game_setting::GetMemberGameSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_game_setting::get_member_game_setting_request::Request{
id: req.id,
})
};
let ss_get_member_game_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_game_setting::SUBJECT_GET_MEMBER_GAME_SETTING,
ss_get_member_game_setting_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_game_setting_res =
bpr::ss::member_game_setting::GetMemberGameSettingResponse::decode(ss_get_member_game_setting_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_game_setting_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_game_setting_res.result {
message
.respond(
bpr::c2se::member_game_setting::GetMemberGameSettingResponse {
error: None,
result: Some(bpr::c2se::member_game_setting::get_member_game_setting_response::Result { member_game_setting: r.member_game_setting }),
}
.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_game_setting::GetMemberGameSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_member_game_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_game_setting::SUBJECT_UPDATE_MEMBER_GAME_SETTING,
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_game_setting::UpdateMemberGameSettingRequest::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_game_setting_req = bpr::ss::member_game_setting::UpdateMemberGameSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_game_setting::update_member_game_setting_request::Request{
id: req.id,
can_bet_casino: req.can_bet_casino,
can_bet_slot: req.can_bet_slot,
can_bet_powerball: req.can_bet_powerball,
can_bet_powerladder: req.can_bet_powerladder,
can_bet_eos: req.can_bet_eos,
can_bet_bogglepowerball: req.can_bet_bogglepowerball,
})
};
let ss_update_member_game_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_game_setting::SUBJECT_UPDATE_MEMBER_GAME_SETTING,
ss_update_member_game_setting_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_game_setting_res = bpr::ss::member_game_setting::UpdateMemberGameSettingResponse::decode(
ss_update_member_game_setting_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_game_setting_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_game_setting_res.result {
message
.respond(
bpr::c2se::member_game_setting::UpdateMemberGameSettingResponse {
error: None,
result: Some(bpr::c2se::member_game_setting::update_member_game_setting_response::Result {
member_game_setting: r.member_game_setting,
}),
}
.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_game_setting::UpdateMemberGameSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_game_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_game_setting::SUBJECT_DELETE_MEMBER_GAME_SETTING,
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_game_setting::DeleteMemberGameSettingRequest::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_game_setting_req = bpr::ss::member_game_setting::DeleteMemberGameSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_game_setting::delete_member_game_setting_request::Request {
id: req.id,
})
};
let ss_delete_member_game_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_game_setting::SUBJECT_DELETE_MEMBER_GAME_SETTING,
ss_delete_member_game_setting_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_game_setting_res = bpr::ss::member_game_setting::DeleteMemberGameSettingResponse::decode(
ss_delete_member_game_setting_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_game_setting_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_game_setting_res.result {
message
.respond(
bpr::c2se::member_game_setting::DeleteMemberGameSettingResponse {
error: None,
result: Some(bpr::c2se::member_game_setting::delete_member_game_setting_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_game_setting::DeleteMemberGameSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,599 +0,0 @@
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_level::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_level(),
self.list_member_levels(),
self.get_member_level(),
self.update_member_level(),
self.delete_member_level(),
)
.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_level(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_level::SUBJECT_CREATE_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::CreateMemberLevelRequest::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_level_req = bpr::ss::member_level::CreateMemberLevelRequest {
client: Some(client),
request: Some(
bpr::ss::member_level::create_member_level_request::Request {
name: req.name,
sort_order: req.sort_order,
show: req.show,
},
),
};
let ss_create_member_level_res_msg = self
.connection_broker
.request(
bpr::ss::member_level::SUBJECT_CREATE_MEMBER_LEVEL,
ss_create_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_create_member_level_res = bpr::ss::member_level::CreateMemberLevelResponse::decode(
ss_create_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_create_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_create_member_level_res.result {
message
.respond(
bpr::c2se::member_level::CreateMemberLevelResponse {
error: None,
result: Some(
bpr::c2se::member_level::create_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::CreateMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn list_member_levels(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_level::SUBJECT_LIST_MEMBER_LEVELS,
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::ListMemberLevelsRequest::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_levels_req = bpr::ss::member_level::ListMemberLevelsRequest {
client: Some(client),
request: Some(bpr::ss::member_level::list_member_levels_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(
bpr::ss::member_level::list_member_levels_request::request::Search {
name_like: s.name_like,
show: s.show,
},
),
None => None,
},
}),
};
let ss_list_member_levels_res_msg = self
.connection_broker
.request(
bpr::ss::member_level::SUBJECT_LIST_MEMBER_LEVELS,
ss_list_member_levels_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_levels_res = bpr::ss::member_level::ListMemberLevelsResponse::decode(
ss_list_member_levels_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_levels_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_levels_res.result {
message
.respond(
bpr::c2se::member_level::ListMemberLevelsResponse {
error: None,
result: Some(
bpr::c2se::member_level::list_member_levels_response::Result {
total_count: r.total_count,
member_levels: r.member_levels,
},
),
}
.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::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)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_member_level(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_level::SUBJECT_UPDATE_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::UpdateMemberLevelRequest::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_level_req = bpr::ss::member_level::UpdateMemberLevelRequest {
client: Some(client),
request: Some(
bpr::ss::member_level::update_member_level_request::Request {
id: req.id,
name: req.name,
sort_order: req.sort_order,
show: req.show,
},
),
};
let ss_update_member_level_res_msg = self
.connection_broker
.request(
bpr::ss::member_level::SUBJECT_UPDATE_MEMBER_LEVEL,
ss_update_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_update_member_level_res = bpr::ss::member_level::UpdateMemberLevelResponse::decode(
ss_update_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_update_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_update_member_level_res.result {
message
.respond(
bpr::c2se::member_level::UpdateMemberLevelResponse {
error: None,
result: Some(
bpr::c2se::member_level::update_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::UpdateMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_level(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_level::SUBJECT_DELETE_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::DeleteMemberLevelRequest::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_level_req = bpr::ss::member_level::DeleteMemberLevelRequest {
client: Some(client),
request: Some(bpr::ss::member_level::delete_member_level_request::Request { id: req.id }),
};
let ss_delete_member_level_res_msg = self
.connection_broker
.request(
bpr::ss::member_level::SUBJECT_DELETE_MEMBER_LEVEL,
ss_delete_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_delete_member_level_res = bpr::ss::member_level::DeleteMemberLevelResponse::decode(
ss_delete_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_delete_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_delete_member_level_res.result {
message
.respond(
bpr::c2se::member_level::DeleteMemberLevelResponse {
error: None,
result: Some(bpr::c2se::member_level::delete_member_level_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_level::DeleteMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,938 +0,0 @@
use beteran_common_rust as bcr;
use beteran_protobuf_rust as bpr;
use prost::Message;
///
pub struct Service {
connection_broker: nats::asynk::Connection,
queue_broker: String,
}
impl std::fmt::Debug for Service {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("beteran-backend-server-edge::member_referrer::service::Service")
.finish()
}
}
impl Service {
///
pub fn new(connection_broker: nats::asynk::Connection, queue_broker: String) -> Service {
Service {
connection_broker,
queue_broker,
}
}
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.create_member_referrer(),
self.create_member_referrers(),
self.list_member_referrers(),
self.get_member_referrer(),
self.get_member_referrer_by_code(),
self.update_member_referrer(),
self.delete_member_referrer(),
self.delete_member_referrers(),
)
.map(|_| ())
}
fn get_client_in_header(
&self,
message: &nats::asynk::Message,
) -> Result<bpr::models::core::network::Client, bcr::error::rpc::Error> {
match &message.headers {
Some(headers) => {
let client = match headers.get(bpr::c2se::core::network::HEADER_CLIENT) {
Some(c) => {
let msg = base64::decode(c).map_err(|e| {
bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse {
message: format!("invalid header: {}", e),
})
})?;
bpr::models::core::network::Client::decode(msg.as_slice()).map_err(|e| {
bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse {
message: format!("invalid header: {}", e),
})
})?
}
None => {
return Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse {
message: "invalid client information".to_string(),
}));
}
};
Ok(client)
}
None => Err(bcr::error::rpc::Error::Parse(bcr::error::rpc::Parse {
message: "invalid header".to_string(),
})),
}
}
async fn create_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_CREATE_MEMBER_REFERRER,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::CreateMemberReferrerRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_create_member_referrer_req = bpr::ss::member_referrer::CreateMemberReferrerRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::create_member_referrer_request::Request {
member_id: req.member_id,
},
),
};
let ss_create_member_referrer_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_CREATE_MEMBER_REFERRER,
ss_create_member_referrer_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_create_member_referrer_res =
bpr::ss::member_referrer::CreateMemberReferrerResponse::decode(
ss_create_member_referrer_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_create_member_referrer_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_create_member_referrer_res.result {
message
.respond(
bpr::c2se::member_referrer::CreateMemberReferrerResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::create_member_referrer_response::Result {
member_referrer: r.member_referrer,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::CreateMemberReferrerResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn create_member_referrers(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_CREATE_MEMBER_REFERRERS,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::CreateMemberReferrersRequest::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_referrers_req =
bpr::ss::member_referrer::CreateMemberReferrersRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::create_member_referrers_request::Request {
member_ids: req.member_ids,
},
),
};
let ss_create_member_referrers_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_CREATE_MEMBER_REFERRERS,
ss_create_member_referrers_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_create_member_referrers_res =
bpr::ss::member_referrer::CreateMemberReferrersResponse::decode(
ss_create_member_referrers_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_create_member_referrers_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_create_member_referrers_res.result {
message
.respond(
bpr::c2se::member_referrer::CreateMemberReferrersResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::create_member_referrers_response::Result {
member_referrers: r.member_referrers,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::CreateMemberReferrersResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn list_member_referrers(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_LIST_MEMBER_REFERRERS,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::ListMemberReferrersRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_list_member_referrers_req = bpr::ss::member_referrer::ListMemberReferrersRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::list_member_referrers_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(
bpr::ss::member_referrer::list_member_referrers_request::request::Search {
member_id: s.member_id,
can_use: s.can_use,
memo_like: s.memo_like,
},
),
None => None,
},
},
),
};
let ss_list_member_referrers_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_LIST_MEMBER_REFERRERS,
ss_list_member_referrers_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_list_member_referrers_res =
bpr::ss::member_referrer::ListMemberReferrersResponse::decode(
ss_list_member_referrers_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_list_member_referrers_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_list_member_referrers_res.result {
message
.respond(
bpr::c2se::member_referrer::ListMemberReferrersResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::list_member_referrers_response::Result {
total_count: r.total_count,
member_referrers: r.member_referrers,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::ListMemberReferrersResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn get_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_GET_MEMBER_REFERRER,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::GetMemberReferrerRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_get_member_referrer_req = bpr::ss::member_referrer::GetMemberReferrerRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::get_member_referrer_request::Request { id: req.id },
),
};
let ss_get_member_referrer_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_GET_MEMBER_REFERRER,
ss_get_member_referrer_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_get_member_referrer_res =
bpr::ss::member_referrer::GetMemberReferrerResponse::decode(
ss_get_member_referrer_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_get_member_referrer_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_get_member_referrer_res.result {
message
.respond(
bpr::c2se::member_referrer::GetMemberReferrerResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::get_member_referrer_response::Result {
member_referrer: r.member_referrer,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::GetMemberReferrerResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn get_member_referrer_by_code(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_GET_MEMBER_REFERRER_BY_CODE,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req = bpr::c2se::member_referrer::GetMemberReferrerByCodeRequest::decode(
message.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_get_member_referrer_by_code_req =
bpr::ss::member_referrer::GetMemberReferrerByCodeRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::get_member_referrer_by_code_request::Request {
code: req.code,
},
),
};
let ss_get_member_referrer_by_code_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_GET_MEMBER_REFERRER_BY_CODE,
ss_get_member_referrer_by_code_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_get_member_referrer_by_code_res =
bpr::ss::member_referrer::GetMemberReferrerByCodeResponse::decode(
ss_get_member_referrer_by_code_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_get_member_referrer_by_code_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_get_member_referrer_by_code_res.result {
message
.respond(
bpr::c2se::member_referrer::GetMemberReferrerByCodeResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::get_member_referrer_by_code_response::Result {
member_referrer: r.member_referrer,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::GetMemberReferrerByCodeResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_UPDATE_MEMBER_REFERRER,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::UpdateMemberReferrerRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_update_member_referrer_req = bpr::ss::member_referrer::UpdateMemberReferrerRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::update_member_referrer_request::Request {
id: req.id,
can_use: req.can_use,
memo: req.memo,
},
),
};
let ss_update_member_referrer_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_UPDATE_MEMBER_REFERRER,
ss_update_member_referrer_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_update_member_referrer_res =
bpr::ss::member_referrer::UpdateMemberReferrerResponse::decode(
ss_update_member_referrer_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_update_member_referrer_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_update_member_referrer_res.result {
message
.respond(
bpr::c2se::member_referrer::UpdateMemberReferrerResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::update_member_referrer_response::Result {
member_referrer: r.member_referrer,
},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::UpdateMemberReferrerResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_referrer(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_DELETE_MEMBER_REFERRER,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::DeleteMemberReferrerRequest::decode(message.data.as_slice())
.map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
})?;
let ss_delete_member_referrer_req = bpr::ss::member_referrer::DeleteMemberReferrerRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::delete_member_referrer_request::Request { id: req.id },
),
};
let ss_delete_member_referrer_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_DELETE_MEMBER_REFERRER,
ss_delete_member_referrer_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_delete_member_referrer_res =
bpr::ss::member_referrer::DeleteMemberReferrerResponse::decode(
ss_delete_member_referrer_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_delete_member_referrer_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_delete_member_referrer_res.result {
message
.respond(
bpr::c2se::member_referrer::DeleteMemberReferrerResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::delete_member_referrer_response::Result {},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::DeleteMemberReferrerResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_referrers(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_referrer::SUBJECT_DELETE_MEMBER_REFERRERS,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let client = self.get_client_in_header(&message)?;
let req =
bpr::c2se::member_referrer::DeleteMemberReferrersRequest::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_referrers_req =
bpr::ss::member_referrer::DeleteMemberReferrersRequest {
client: Some(client),
request: Some(
bpr::ss::member_referrer::delete_member_referrers_request::Request { ids: req.ids },
),
};
let ss_delete_member_referrers_res_msg = self
.connection_broker
.request(
bpr::ss::member_referrer::SUBJECT_DELETE_MEMBER_REFERRERS,
ss_delete_member_referrers_req.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
let ss_delete_member_referrers_res =
bpr::ss::member_referrer::DeleteMemberReferrersResponse::decode(
ss_delete_member_referrers_res_msg.data.as_slice(),
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
if let Some(e) = ss_delete_member_referrers_res.error {
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
}));
}
if let Some(r) = ss_delete_member_referrers_res.result {
message
.respond(
bpr::c2se::member_referrer::DeleteMemberReferrersResponse {
error: None,
result: Some(
bpr::c2se::member_referrer::delete_member_referrers_response::Result {},
),
}
.encode_to_vec(),
)
.await
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
}
Ok::<(), bcr::error::rpc::Error>(())
}
.await
{
message
.respond(
bpr::c2se::member_referrer::DeleteMemberReferrersResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,629 +0,0 @@
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_settlement_setting::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_settlement_setting(),
self.list_member_settlement_settings(),
self.get_member_settlement_setting(),
self.update_member_settlement_setting(),
self.delete_member_settlement_setting(),
)
.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_settlement_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_settlement_setting::SUBJECT_CREATE_MEMBER_SETTLEMENT_SETTING,
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_settlement_setting::CreateMemberSettlementSettingRequest::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_settlement_setting_req =
bpr::ss::member_settlement_setting::CreateMemberSettlementSettingRequest {
client: Some(client),
request: Some(
bpr::ss::member_settlement_setting::create_member_settlement_setting_request::Request {
member_id: req.member_id,
can_exchange: req.can_exchange,
can_first_charge_comp: req.can_first_charge_comp,
can_per_charge_comp: req.can_per_charge_comp,
manual_payment_type_for_partner: req.manual_payment_type_for_partner,
settlement_type: req.settlement_type,
rate_casino: req.rate_casino,
rate_casino_loosing: req.rate_casino_loosing,
rate_casino_bacara: req.rate_casino_bacara,
rate_casino_roulette: req.rate_casino_roulette,
rate_casino_dragon_tiger: req.rate_casino_dragon_tiger,
rate_slot: req.rate_slot,
rate_slot_loosing: req.rate_slot_loosing,
rate_powerball_single: req.rate_powerball_single,
rate_powerball_combo: req.rate_powerball_combo,
rate_powerladder_single: req.rate_powerladder_single,
rate_powerladder_combo: req.rate_powerladder_combo,
rate_eos_single: req.rate_eos_single,
rate_eos_combo: req.rate_eos_combo,
rate_bogglepowerball_single: req.rate_bogglepowerball_single,
rate_bogglepowerball_combo: req.rate_bogglepowerball_combo,
},
),
};
let ss_create_member_settlement_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_settlement_setting::SUBJECT_CREATE_MEMBER_SETTLEMENT_SETTING,
ss_create_member_settlement_setting_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_settlement_setting_res =
bpr::ss::member_settlement_setting::CreateMemberSettlementSettingResponse::decode(
ss_create_member_settlement_setting_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_settlement_setting_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_settlement_setting_res.result {
message
.respond(
bpr::c2se::member_settlement_setting::CreateMemberSettlementSettingResponse {
error: None,
result: Some(
bpr::c2se::member_settlement_setting::create_member_settlement_setting_response::Result {
member_settlement_setting: r.member_settlement_setting,
},
),
}
.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_settlement_setting::CreateMemberSettlementSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn list_member_settlement_settings(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_settlement_setting::SUBJECT_LIST_MEMBER_SETTLEMENT_SETTINGS,
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_settlement_setting::ListMemberSettlementSettingsRequest::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_settlement_settings_req = bpr::ss::member_settlement_setting::ListMemberSettlementSettingsRequest {
client: Some(client),
request: Some(bpr::ss::member_settlement_setting::list_member_settlement_settings_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(bpr::ss::member_settlement_setting::list_member_settlement_settings_request::request::Search{
member_id: s.member_id,
}),
None => None,
}
})
};
let ss_list_member_settlement_settings_res_msg = self
.connection_broker
.request(
bpr::ss::member_settlement_setting::SUBJECT_LIST_MEMBER_SETTLEMENT_SETTINGS,
ss_list_member_settlement_settings_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_settlement_settings_res =
bpr::ss::member_settlement_setting::ListMemberSettlementSettingsResponse::decode(ss_list_member_settlement_settings_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_settlement_settings_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_settlement_settings_res.result {
message
.respond(
bpr::c2se::member_settlement_setting::ListMemberSettlementSettingsResponse {
error: None,
result: Some(bpr::c2se::member_settlement_setting::list_member_settlement_settings_response::Result {
total_count: r.total_count,
member_settlement_settings: r.member_settlement_settings,
}),
}
.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_settlement_setting::ListMemberSettlementSettingsResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn get_member_settlement_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_settlement_setting::SUBJECT_GET_MEMBER_SETTLEMENT_SETTING,
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_settlement_setting::GetMemberSettlementSettingRequest::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_settlement_setting_req = bpr::ss::member_settlement_setting::GetMemberSettlementSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_settlement_setting::get_member_settlement_setting_request::Request{
id: req.id,
})
};
let ss_get_member_settlement_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_settlement_setting::SUBJECT_GET_MEMBER_SETTLEMENT_SETTING,
ss_get_member_settlement_setting_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_settlement_setting_res =
bpr::ss::member_settlement_setting::GetMemberSettlementSettingResponse::decode(ss_get_member_settlement_setting_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_settlement_setting_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_settlement_setting_res.result {
message
.respond(
bpr::c2se::member_settlement_setting::GetMemberSettlementSettingResponse {
error: None,
result: Some(bpr::c2se::member_settlement_setting::get_member_settlement_setting_response::Result { member_settlement_setting: r.member_settlement_setting }),
}
.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_settlement_setting::GetMemberSettlementSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_member_settlement_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_settlement_setting::SUBJECT_UPDATE_MEMBER_SETTLEMENT_SETTING,
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_settlement_setting::UpdateMemberSettlementSettingRequest::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_settlement_setting_req = bpr::ss::member_settlement_setting::UpdateMemberSettlementSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_settlement_setting::update_member_settlement_setting_request::Request{
id: req.id,
can_exchange: req.can_exchange,
can_first_charge_comp: req.can_first_charge_comp,
can_per_charge_comp: req.can_per_charge_comp,
manual_payment_type_for_partner: req.manual_payment_type_for_partner,
settlement_type: req.settlement_type,
rate_casino: req.rate_casino,
rate_casino_loosing: req.rate_casino_loosing,
rate_casino_bacara: req.rate_casino_bacara,
rate_casino_roulette: req.rate_casino_roulette,
rate_casino_dragon_tiger: req.rate_casino_dragon_tiger,
rate_slot: req.rate_slot,
rate_slot_loosing: req.rate_slot_loosing,
rate_powerball_single: req.rate_powerball_single,
rate_powerball_combo: req.rate_powerball_combo,
rate_powerladder_single: req.rate_powerladder_single,
rate_powerladder_combo: req.rate_powerladder_combo,
rate_eos_single: req.rate_eos_single,
rate_eos_combo: req.rate_eos_combo,
rate_bogglepowerball_single: req.rate_bogglepowerball_single,
rate_bogglepowerball_combo: req.rate_bogglepowerball_combo,
})
};
let ss_update_member_settlement_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_settlement_setting::SUBJECT_UPDATE_MEMBER_SETTLEMENT_SETTING,
ss_update_member_settlement_setting_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_settlement_setting_res = bpr::ss::member_settlement_setting::UpdateMemberSettlementSettingResponse::decode(
ss_update_member_settlement_setting_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_settlement_setting_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_settlement_setting_res.result {
message
.respond(
bpr::c2se::member_settlement_setting::UpdateMemberSettlementSettingResponse {
error: None,
result: Some(bpr::c2se::member_settlement_setting::update_member_settlement_setting_response::Result {
member_settlement_setting: r.member_settlement_setting,
}),
}
.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_settlement_setting::UpdateMemberSettlementSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_settlement_setting(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::member_settlement_setting::SUBJECT_DELETE_MEMBER_SETTLEMENT_SETTING,
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_settlement_setting::DeleteMemberSettlementSettingRequest::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_settlement_setting_req = bpr::ss::member_settlement_setting::DeleteMemberSettlementSettingRequest {
client: Some(client),
request: Some(bpr::ss::member_settlement_setting::delete_member_settlement_setting_request::Request {
id: req.id,
})
};
let ss_delete_member_settlement_setting_res_msg = self
.connection_broker
.request(
bpr::ss::member_settlement_setting::SUBJECT_DELETE_MEMBER_SETTLEMENT_SETTING,
ss_delete_member_settlement_setting_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_settlement_setting_res = bpr::ss::member_settlement_setting::DeleteMemberSettlementSettingResponse::decode(
ss_delete_member_settlement_setting_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_settlement_setting_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_settlement_setting_res.result {
message
.respond(
bpr::c2se::member_settlement_setting::DeleteMemberSettlementSettingResponse {
error: None,
result: Some(bpr::c2se::member_settlement_setting::delete_member_settlement_setting_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_settlement_setting::DeleteMemberSettlementSettingResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -1,587 +0,0 @@
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::site::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_site(),
self.list_sites(),
self.get_site(),
self.update_site(),
self.delete_site(),
)
.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 list_sites(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::site::SUBJECT_LIST_SITES,
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::ListSitesRequest::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_sites_req = bpr::ss::site::ListSitesRequest {
client: Some(client),
request: Some(bpr::ss::site::list_sites_request::Request {
pagination: req.pagination,
sorts: req.sorts,
search: match req.search {
Some(s) => Some(bpr::ss::site::list_sites_request::request::Search {
url_like: s.url_like,
name_like: s.name_like,
path_like: s.path_like,
show: s.show,
can_use: s.can_use,
memo_like: s.memo_like,
}),
None => None,
},
}),
};
let ss_list_sites_res_msg = self
.connection_broker
.request(
bpr::ss::site::SUBJECT_LIST_SITES,
ss_list_sites_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_sites_res = bpr::ss::site::ListSitesResponse::decode(
ss_list_sites_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_sites_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_sites_res.result {
message
.respond(
bpr::c2se::site::ListSitesResponse {
error: None,
result: Some(bpr::c2se::site::list_sites_response::Result {
total_count: r.total_count,
sites: r.sites,
}),
}
.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::ListSitesResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn create_site(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::site::SUBJECT_CREATE_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::CreateSiteRequest::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_site_req = bpr::ss::site::CreateSiteRequest {
client: Some(client),
request: Some(bpr::ss::site::create_site_request::Request {
url: req.url,
name: req.name,
path: req.path,
show: req.show,
can_use: req.can_use,
memo: req.memo,
expires_at: req.expires_at,
}),
};
let ss_create_site_res_msg = self
.connection_broker
.request(
bpr::ss::site::SUBJECT_CREATE_SITE,
ss_create_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_create_site_res =
bpr::ss::site::CreateSiteResponse::decode(ss_create_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_create_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_create_site_res.result {
message
.respond(
bpr::c2se::site::CreateSiteResponse {
error: None,
result: Some(bpr::c2se::site::create_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::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)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn update_site(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::site::SUBJECT_UPDATE_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::UpdateSiteRequest::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_site_req = bpr::ss::site::UpdateSiteRequest {
client: Some(client),
request: Some(bpr::ss::site::update_site_request::Request {
id: req.id,
url: req.url,
name: req.name,
path: req.path,
show: req.show,
can_use: req.can_use,
memo: req.memo,
expires_at: req.expires_at,
}),
};
let ss_update_site_res_msg = self
.connection_broker
.request(
bpr::ss::site::SUBJECT_UPDATE_SITE,
ss_update_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_update_site_res =
bpr::ss::site::UpdateSiteResponse::decode(ss_update_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_update_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_update_site_res.result {
message
.respond(
bpr::c2se::site::UpdateSiteResponse {
error: None,
result: Some(bpr::c2se::site::update_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::UpdateSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_site(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::c2se::backend::site::SUBJECT_DELETE_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::DeleteSiteRequest::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_site_req = bpr::ss::site::DeleteSiteRequest {
client: Some(client),
request: Some(bpr::ss::site::delete_site_request::Request { id: req.id }),
};
let ss_delete_site_res_msg = self
.connection_broker
.request(
bpr::ss::site::SUBJECT_DELETE_SITE,
ss_delete_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_delete_site_res =
bpr::ss::site::DeleteSiteResponse::decode(ss_delete_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_delete_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_delete_site_res.result {
message
.respond(
bpr::c2se::site::DeleteSiteResponse {
error: None,
result: Some(bpr::c2se::site::delete_site_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::site::DeleteSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}