refactoring

This commit is contained in:
병준 박 2022-08-14 08:39:17 +00:00
parent 734597739a
commit 0b216aae55
63 changed files with 5695 additions and 1336 deletions

View File

@ -28,10 +28,10 @@
"extensions": [
"donjayamanne.githistory",
"eamodio.gitlens",
"matklad.rust-analyzer",
"mhutchie.git-graph",
"ms-azuretools.vscode-docker",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb"

View File

@ -11,6 +11,7 @@ path = "./src/main.rs"
[dependencies]
anyhow = { version = "=1.0.59" }
captcha = { version = "0" }
chrono = { version = "0" }
diesel = { version = "1", features = ["chrono", "r2d2", "uuidv07", "postgres"] }
@ -30,7 +31,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tokio-cron-scheduler = { version = "0" }
uuid = { version = "0", features = ["serde", "v4", "v5"] }
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.43-snapshot" }
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.26-snapshot" }
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.56-snapshot" }
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.40-snapshot" }
[build-dependencies]

View File

@ -12,10 +12,10 @@ CREATE TABLE IF NOT EXISTS members (
mobile_phone_number TEXT,
state MEMBER_STATE DEFAULT 'normal',
state_changed_at BIGINT,
last_signined_ip TEXT,
last_signined_at BIGINT,
referrer_member_id UUID,
referred_count BIGINT NOT NULL DEFAULT 0,
last_signined_ip TEXT,
last_signined_at BIGINT,
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
deleted_at BIGINT,

View File

@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS member_bank_deposits (
amount INTEGER NOT NULL,
memo TEXT,
state MEMBER_BANK_DEPOSIT_STATE DEFAULT 'application',
state_changed_at BIGINT,
state_changed_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
PRIMARY KEY (id),

View File

@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS member_bank_withdraws (
password TEXT NOT NULL,
memo TEXT,
state MEMBER_BANK_WITHDRAW_STATE DEFAULT 'application',
state_changed_at BIGINT,
state_changed_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
PRIMARY KEY (id),

View File

@ -39,11 +39,13 @@ SELECT
mc.id as mc_id,
mc.parent_id as mc_parent_id,
mc.name as mc_name,
mc.show as mc_show,
mc.created_at as mc_created_at,
mc.updated_at as mc_updated_at,
ml.id as ml_id,
ml.name as ml_name,
ml.show as ml_show,
ml.sort_order as ml_sort_order,
ml.created_at as ml_created_at,
ml.updated_at as ml_updated_at,
@ -187,81 +189,83 @@ impl Composition {
let mut query_where = String::new();
if let Some(sp) = find_all.site_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(s) = &find_all.search {
if let Some(sp) = s.site_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.site_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.site_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = find_all.member_class_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = s.member_class_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.member_class_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.member_class_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = find_all.member_level_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = s.member_level_id {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.member_level_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.member_level_id = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = &find_all.username_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = &s.username_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.username like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.username like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = &find_all.nickname_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = &s.nickname_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.nickname like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.nickname like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = &find_all.mobile_phone_number_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = &s.mobile_phone_number_like {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.mobile_phone_number like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.mobile_phone_number like '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = &find_all.last_signined_ip {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = &s.last_signined_ip {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.last_signined_ip = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.last_signined_ip = '{}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if let Some(sp) = find_all.state {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
if let Some(sp) = s.state {
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.state = '{:?}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
write!(&mut query_where, "m.state = '{:?}'", sp)
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if find_all.deleted_at.is_some() {
write!(&mut query_where, "m.deleted_at IS NOT NULL")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
} else {
write!(&mut query_where, "m.deleted_at IS NULL")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
if !query_where.is_empty() {
write!(&mut query_where, " AND ")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
if s.deleted_at.is_some() {
write!(&mut query_where, "m.deleted_at IS NOT NULL")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
} else {
write!(&mut query_where, "m.deleted_at IS NULL")
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
}
}
if !query_where.is_empty() {

View File

@ -124,12 +124,14 @@ impl QueryableByName<diesel::pg::Pg> for MemberModel {
id: row.get("mc_id")?,
parent_id: row.get("mc_parent_id")?,
name: row.get("mc_name")?,
show: row.get("mc_show")?,
created_at: row.get("mc_created_at")?,
updated_at: row.get("mc_updated_at")?,
},
member_level: _MemberLevel {
id: row.get("ml_id")?,
name: row.get("ml_name")?,
show: row.get("ml_show")?,
sort_order: row.get("ml_sort_order")?,
created_at: row.get("ml_created_at")?,
updated_at: row.get("ml_updated_at")?,

View File

@ -59,7 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server_broker_opts = nats::asynk::Options::new();
let connection_server_broker = server_broker_opts.connect(url_server_broker).await?;
let site_service = services::site::service::Service::new(
let bank_service = services::bank::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
@ -76,15 +76,52 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
password_salt,
password_salt.clone(),
);
let member_bank_account_service = services::member_bank_account::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
let member_bank_deposit_service = services::member_bank_deposit::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
let member_bank_withdraw_service = services::member_bank_withdraw::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
let member_class_service = services::member_class::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
let member_level_service = services::member_level::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
let site_service = services::site::service::Service::new(
connection_server_broker.clone(),
queue_server_broker.clone(),
pool.clone(),
);
println!("Server service [beteran-server-service] is started");
futures::try_join!(
site_service.subscribe(),
bank_service.subscribe(),
identity_service.subscribe(),
member_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_level_service.subscribe(),
site_service.subscribe(),
)?;
Ok(())

View File

@ -57,7 +57,7 @@ pub struct ModifyBank {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub name_like: Option<String>,
///
@ -66,6 +66,11 @@ pub struct FindAll {
pub can_use: Option<bool>,
///
pub memo_like: Option<String>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -62,17 +62,19 @@ impl Repository {
) -> Result<i64, Error> {
let mut q = banks::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(banks::dsl::name.like(sp));
}
if let Some(sp) = find_all.show {
q = q.filter(banks::dsl::show.eq(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(banks::dsl::can_use.eq(sp));
}
if let Some(sp) = &find_all.memo_like {
q = q.filter(banks::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(banks::dsl::name.like(sp));
}
if let Some(sp) = s.show {
q = q.filter(banks::dsl::show.eq(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(banks::dsl::can_use.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(banks::dsl::memo.like(sp));
}
}
q.count().get_result(conn)
@ -86,17 +88,19 @@ impl Repository {
) -> Result<Vec<models::Bank>, Error> {
let mut q = banks::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(banks::dsl::name.like(sp));
}
if let Some(sp) = find_all.show {
q = q.filter(banks::dsl::show.eq(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(banks::dsl::can_use.eq(sp));
}
if let Some(sp) = &find_all.memo_like {
q = q.filter(banks::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(banks::dsl::name.like(sp));
}
if let Some(sp) = s.show {
q = q.filter(banks::dsl::show.eq(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(banks::dsl::can_use.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(banks::dsl::memo.like(sp));
}
}
if let Some(p) = &find_all.pagination {

View File

@ -75,8 +75,14 @@ pub struct ModifyMember {
pub password: Option<String>,
///
pub mobile_phone_number: Option<String>,
}
///
#[derive(AsChangeset, Debug, Clone)]
#[table_name = "members"]
pub struct ModifyMemberForState {
///
pub state: Option<MemberState>,
pub state: MemberState,
}
///
@ -99,7 +105,7 @@ pub struct ModifyMember4DeletedAt {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub site_id: Option<uuid::Uuid>,
///
@ -120,6 +126,13 @@ pub struct FindAll {
pub state: Option<MemberState>,
///
pub deleted_at: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -105,34 +105,36 @@ impl Repository {
let mut q = members::table.into_boxed();
if let Some(sp) = find_all.site_id {
q = q.filter(dsl::site_id.eq(sp));
}
if let Some(sp) = find_all.member_class_id {
q = q.filter(dsl::member_class_id.eq(sp));
}
if let Some(sp) = find_all.member_level_id {
q = q.filter(dsl::member_level_id.eq(sp));
}
if let Some(sp) = &find_all.username_like {
q = q.filter(dsl::username.like(sp));
}
if let Some(sp) = &find_all.nickname_like {
q = q.filter(dsl::nickname.like(sp));
}
if let Some(sp) = &find_all.mobile_phone_number_like {
q = q.filter(dsl::mobile_phone_number.like(sp));
}
if let Some(sp) = &find_all.last_signined_ip {
q = q.filter(dsl::last_signined_ip.eq(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(dsl::state.eq(sp));
}
if find_all.deleted_at.is_some() {
q = q.filter(dsl::deleted_at.is_not_null());
} else {
q = q.filter(dsl::deleted_at.is_null());
if let Some(s) = &find_all.search {
if let Some(sp) = s.site_id {
q = q.filter(dsl::site_id.eq(sp));
}
if let Some(sp) = s.member_class_id {
q = q.filter(dsl::member_class_id.eq(sp));
}
if let Some(sp) = s.member_level_id {
q = q.filter(dsl::member_level_id.eq(sp));
}
if let Some(sp) = &s.username_like {
q = q.filter(dsl::username.like(sp));
}
if let Some(sp) = &s.nickname_like {
q = q.filter(dsl::nickname.like(sp));
}
if let Some(sp) = &s.mobile_phone_number_like {
q = q.filter(dsl::mobile_phone_number.like(sp));
}
if let Some(sp) = &s.last_signined_ip {
q = q.filter(dsl::last_signined_ip.eq(sp));
}
if let Some(sp) = s.state {
q = q.filter(dsl::state.eq(sp));
}
if s.deleted_at.is_some() {
q = q.filter(dsl::deleted_at.is_not_null());
} else {
q = q.filter(dsl::deleted_at.is_null());
}
}
q.count().get_result(conn)
@ -148,34 +150,36 @@ impl Repository {
let mut q = members::table.into_boxed();
if let Some(sp) = find_all.site_id {
q = q.filter(dsl::site_id.eq(sp));
}
if let Some(sp) = find_all.member_class_id {
q = q.filter(dsl::member_class_id.eq(sp));
}
if let Some(sp) = find_all.member_level_id {
q = q.filter(dsl::member_level_id.eq(sp));
}
if let Some(sp) = &find_all.username_like {
q = q.filter(dsl::username.like(sp));
}
if let Some(sp) = &find_all.nickname_like {
q = q.filter(dsl::nickname.like(sp));
}
if let Some(sp) = &find_all.mobile_phone_number_like {
q = q.filter(dsl::mobile_phone_number.like(sp));
}
if let Some(sp) = &find_all.last_signined_ip {
q = q.filter(dsl::last_signined_ip.eq(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(dsl::state.eq(sp));
}
if find_all.deleted_at.is_some() {
q = q.filter(dsl::deleted_at.is_not_null());
} else {
q = q.filter(dsl::deleted_at.is_null());
if let Some(s) = &find_all.search {
if let Some(sp) = s.site_id {
q = q.filter(dsl::site_id.eq(sp));
}
if let Some(sp) = s.member_class_id {
q = q.filter(dsl::member_class_id.eq(sp));
}
if let Some(sp) = s.member_level_id {
q = q.filter(dsl::member_level_id.eq(sp));
}
if let Some(sp) = &s.username_like {
q = q.filter(dsl::username.like(sp));
}
if let Some(sp) = &s.nickname_like {
q = q.filter(dsl::nickname.like(sp));
}
if let Some(sp) = &s.mobile_phone_number_like {
q = q.filter(dsl::mobile_phone_number.like(sp));
}
if let Some(sp) = &s.last_signined_ip {
q = q.filter(dsl::last_signined_ip.eq(sp));
}
if let Some(sp) = s.state {
q = q.filter(dsl::state.eq(sp));
}
if s.deleted_at.is_some() {
q = q.filter(dsl::deleted_at.is_not_null());
} else {
q = q.filter(dsl::deleted_at.is_null());
}
}
if let Some(p) = &find_all.pagination {
@ -271,6 +275,21 @@ impl Repository {
.map(|c| c as u64)
}
///
pub fn update_state(
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
modify: &models::ModifyMemberForState,
) -> Result<u64, Error> {
use members::dsl;
diesel::update(dsl::members.filter(dsl::id.eq(id)))
.set(modify)
.execute(conn)
.map(|c| c as u64)
}
///
pub fn update_increase_referred_count(
&self,

View File

@ -55,7 +55,7 @@ pub struct ModifyMemberBankAccount {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub member_id: Option<uuid::Uuid>,
///
@ -66,6 +66,13 @@ pub struct FindAll {
pub account_number_like: Option<String>,
///
pub memo_like: Option<String>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -45,34 +45,43 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::MemberBankAccount, Error> {
member_bank_accounts::table
) -> Result<Option<models::MemberBankAccount>, Error> {
match member_bank_accounts::table
.find(id as uuid::Uuid)
.first::<models::MemberBankAccount>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_bank_accounts::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_accounts::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.bank_id {
q = q.filter(member_bank_accounts::dsl::bank_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_accounts::dsl::name.like(sp));
}
if let Some(sp) = find_all.account_number_like {
q = q.filter(member_bank_accounts::dsl::account_number.like(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_accounts::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_accounts::dsl::member_id.eq(sp));
}
if let Some(sp) = s.bank_id {
q = q.filter(member_bank_accounts::dsl::bank_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_accounts::dsl::name.like(sp));
}
if let Some(sp) = &s.account_number_like {
q = q.filter(member_bank_accounts::dsl::account_number.like(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_accounts::dsl::memo.like(sp));
}
}
q.count().get_result(conn)
@ -82,27 +91,29 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberBankAccount>, Error> {
let mut q = member_bank_accounts::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_accounts::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.bank_id {
q = q.filter(member_bank_accounts::dsl::bank_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_accounts::dsl::name.like(sp));
}
if let Some(sp) = find_all.account_number_like {
q = q.filter(member_bank_accounts::dsl::account_number.like(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_accounts::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_accounts::dsl::member_id.eq(sp));
}
if let Some(sp) = s.bank_id {
q = q.filter(member_bank_accounts::dsl::bank_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_accounts::dsl::name.like(sp));
}
if let Some(sp) = &s.account_number_like {
q = q.filter(member_bank_accounts::dsl::account_number.like(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_accounts::dsl::memo.like(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -110,7 +121,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -165,4 +176,13 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use member_bank_accounts::dsl;
diesel::delete(member_bank_accounts::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -14,11 +14,11 @@ pub struct MemberBankDeposit {
///
pub amount: i32,
///
pub memo: Option<String>,
///
pub state: MemberBankDepositState,
///
pub state_changed_at: Option<i64>,
///
pub memo: Option<String>,
pub state_changed_at: i64,
///
pub created_at: i64,
///
@ -49,13 +49,19 @@ pub struct ModifyMemberBankDeposit {
pub amount: i32,
///
pub memo: Option<String>,
}
///
#[derive(AsChangeset, Debug, Clone)]
#[table_name = "member_bank_deposits"]
pub struct ModifyMemberBankDepositForState {
///
pub state: Option<MemberBankDepositState>,
pub state: MemberBankDepositState,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub member_id: Option<uuid::Uuid>,
///
@ -66,6 +72,13 @@ pub struct FindAll {
pub memo_like: Option<String>,
///
pub state: Option<MemberBankDepositState>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -45,34 +45,43 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::MemberBankDeposit, Error> {
member_bank_deposits::table
) -> Result<Option<models::MemberBankDeposit>, Error> {
match member_bank_deposits::table
.find(id as uuid::Uuid)
.first::<models::MemberBankDeposit>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_bank_deposits::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_deposits::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_deposits::dsl::name.like(sp));
}
if let Some(sp) = find_all.amount {
q = q.filter(member_bank_deposits::dsl::amount.eq(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_deposits::dsl::memo.like(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(member_bank_deposits::dsl::state.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_deposits::dsl::member_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_deposits::dsl::name.like(sp));
}
if let Some(sp) = s.amount {
q = q.filter(member_bank_deposits::dsl::amount.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_deposits::dsl::memo.like(sp));
}
if let Some(sp) = s.state {
q = q.filter(member_bank_deposits::dsl::state.eq(sp));
}
}
q.count().get_result(conn)
@ -82,27 +91,29 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberBankDeposit>, Error> {
let mut q = member_bank_deposits::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_deposits::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_deposits::dsl::name.like(sp));
}
if let Some(sp) = find_all.amount {
q = q.filter(member_bank_deposits::dsl::amount.eq(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_deposits::dsl::memo.like(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(member_bank_deposits::dsl::state.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_deposits::dsl::member_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_deposits::dsl::name.like(sp));
}
if let Some(sp) = s.amount {
q = q.filter(member_bank_deposits::dsl::amount.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_deposits::dsl::memo.like(sp));
}
if let Some(sp) = s.state {
q = q.filter(member_bank_deposits::dsl::state.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -110,7 +121,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -171,4 +182,28 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn update_state(
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
modify: &models::ModifyMemberBankDepositForState,
) -> Result<u64, Error> {
use member_bank_deposits::dsl;
diesel::update(dsl::member_bank_deposits.filter(dsl::id.eq(id)))
.set(modify)
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use member_bank_deposits::dsl;
diesel::delete(member_bank_deposits::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -23,11 +23,11 @@ table! {
///
amount -> Integer,
///
memo -> Nullable<Text>,
///
state -> MemberBankDepositStateMapping,
///
state_changed_at -> Nullable<BigInt>,
///
memo -> Nullable<Text>,
state_changed_at -> BigInt,
///
created_at -> BigInt,
///

View File

@ -20,11 +20,11 @@ pub struct MemberBankWithdraw {
///
pub password: String,
///
pub memo: Option<String>,
///
pub state: MemberBankWithdrawState,
///
pub state_changed_at: Option<i64>,
///
pub memo: Option<String>,
pub state_changed_at: i64,
///
pub created_at: i64,
///
@ -67,13 +67,19 @@ pub struct ModifyMemberBankWithdraw {
pub password: String,
///
pub memo: Option<String>,
}
///
#[derive(AsChangeset, Debug, Clone)]
#[table_name = "member_bank_withdraws"]
pub struct ModifyMemberBankWithdrawForState {
///
pub state: Option<MemberBankWithdrawState>,
pub state: MemberBankWithdrawState,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub member_id: Option<uuid::Uuid>,
///
@ -88,6 +94,13 @@ pub struct FindAll {
pub memo_like: Option<String>,
///
pub state: Option<MemberBankWithdrawState>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -45,40 +45,49 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::MemberBankWithdraw, Error> {
member_bank_withdraws::table
) -> Result<Option<models::MemberBankWithdraw>, Error> {
match member_bank_withdraws::table
.find(id as uuid::Uuid)
.first::<models::MemberBankWithdraw>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_bank_withdraws::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_withdraws::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.bank_name_like {
q = q.filter(member_bank_withdraws::dsl::bank_name.like(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_withdraws::dsl::name.like(sp));
}
if let Some(sp) = find_all.account_number_like {
q = q.filter(member_bank_withdraws::dsl::account_number.like(sp));
}
if let Some(sp) = find_all.amount {
q = q.filter(member_bank_withdraws::dsl::amount.eq(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_withdraws::dsl::memo.like(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(member_bank_withdraws::dsl::state.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_withdraws::dsl::member_id.eq(sp));
}
if let Some(sp) = &s.bank_name_like {
q = q.filter(member_bank_withdraws::dsl::bank_name.like(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_withdraws::dsl::name.like(sp));
}
if let Some(sp) = &s.account_number_like {
q = q.filter(member_bank_withdraws::dsl::account_number.like(sp));
}
if let Some(sp) = s.amount {
q = q.filter(member_bank_withdraws::dsl::amount.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_withdraws::dsl::memo.like(sp));
}
if let Some(sp) = s.state {
q = q.filter(member_bank_withdraws::dsl::state.eq(sp));
}
}
q.count().get_result(conn)
@ -88,33 +97,35 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberBankWithdraw>, Error> {
let mut q = member_bank_withdraws::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_bank_withdraws::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.bank_name_like {
q = q.filter(member_bank_withdraws::dsl::bank_name.like(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(member_bank_withdraws::dsl::name.like(sp));
}
if let Some(sp) = find_all.account_number_like {
q = q.filter(member_bank_withdraws::dsl::account_number.like(sp));
}
if let Some(sp) = find_all.amount {
q = q.filter(member_bank_withdraws::dsl::amount.eq(sp));
}
if let Some(sp) = find_all.memo_like {
q = q.filter(member_bank_withdraws::dsl::memo.like(sp));
}
if let Some(sp) = find_all.state {
q = q.filter(member_bank_withdraws::dsl::state.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_bank_withdraws::dsl::member_id.eq(sp));
}
if let Some(sp) = &s.bank_name_like {
q = q.filter(member_bank_withdraws::dsl::bank_name.like(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(member_bank_withdraws::dsl::name.like(sp));
}
if let Some(sp) = &s.account_number_like {
q = q.filter(member_bank_withdraws::dsl::account_number.like(sp));
}
if let Some(sp) = s.amount {
q = q.filter(member_bank_withdraws::dsl::amount.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(member_bank_withdraws::dsl::memo.like(sp));
}
if let Some(sp) = s.state {
q = q.filter(member_bank_withdraws::dsl::state.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -122,7 +133,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -201,4 +212,28 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn update_state(
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
modify: &models::ModifyMemberBankWithdrawForState,
) -> Result<u64, Error> {
use member_bank_withdraws::dsl;
diesel::update(dsl::member_bank_withdraws.filter(dsl::id.eq(id)))
.set(modify)
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use member_bank_withdraws::dsl;
diesel::delete(member_bank_withdraws::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -29,11 +29,11 @@ table! {
///
password -> Text,
///
memo -> Nullable<Text>,
///
state -> MemberBankWithdrawStateMapping,
///
state_changed_at -> Nullable<BigInt>,
///
memo -> Nullable<Text>,
state_changed_at -> BigInt,
///
created_at -> BigInt,
///

View File

@ -12,6 +12,8 @@ pub struct MemberClass {
///
pub name: String,
///
pub show: bool,
///
pub created_at: i64,
///
pub updated_at: i64,
@ -25,6 +27,8 @@ pub struct NewMemberClass {
pub parent_id: Option<uuid::Uuid>,
///
pub name: String,
///
pub show: bool,
}
///
@ -35,13 +39,24 @@ pub struct ModifyMemberClass {
pub parent_id: Option<uuid::Uuid>,
///
pub name: String,
///
pub show: bool,
}
///
#[derive(Debug, Clone)]
pub struct FindAllSearch {
///
pub name_like: Option<String>,
///
pub show: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub name_like: Option<String>,
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -44,10 +44,17 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::MemberClass, Error> {
member_classes::table
) -> Result<Option<models::MemberClass>, Error> {
match member_classes::table
.find(id as uuid::Uuid)
.first::<models::MemberClass>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
@ -58,8 +65,10 @@ impl Repository {
) -> Result<i64, Error> {
let mut q = member_classes::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(member_classes::dsl::name.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(member_classes::dsl::name.like(sp));
}
}
q.count().get_result(conn)
@ -73,8 +82,10 @@ impl Repository {
) -> Result<Vec<models::MemberClass>, Error> {
let mut q = member_classes::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(member_classes::dsl::name.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(member_classes::dsl::name.like(sp));
}
}
if let Some(p) = &find_all.pagination {

View File

@ -11,6 +11,8 @@ table! {
///
name -> Text,
///
show -> Bool,
///
created_at -> BigInt,
///
updated_at -> BigInt,

View File

@ -10,6 +10,8 @@ pub struct MemberLevel {
///
pub name: String,
///
pub show: bool,
///
pub sort_order: i32,
///
pub created_at: i64,
@ -24,6 +26,8 @@ pub struct NewMemberLevel {
///
pub name: String,
///
pub show: bool,
///
pub sort_order: i32,
}
@ -34,14 +38,25 @@ pub struct ModifyMemberLevel {
///
pub name: String,
///
pub show: bool,
///
pub sort_order: i32,
}
///
#[derive(Debug, Clone)]
pub struct FindAllSearch {
///
pub name_like: Option<String>,
///
pub show: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub name_like: Option<String>,
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -44,10 +44,17 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::MemberLevel, Error> {
member_levels::table
) -> Result<Option<models::MemberLevel>, Error> {
match member_levels::table
.find(id as uuid::Uuid)
.first::<models::MemberLevel>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
@ -58,8 +65,10 @@ impl Repository {
) -> Result<i64, Error> {
let mut q = member_levels::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(member_levels::dsl::name.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(member_levels::dsl::name.like(sp));
}
}
q.count().get_result(conn)
@ -73,8 +82,10 @@ impl Repository {
) -> Result<Vec<models::MemberLevel>, Error> {
let mut q = member_levels::table.into_boxed();
if let Some(sp) = &find_all.name_like {
q = q.filter(member_levels::dsl::name.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.name_like {
q = q.filter(member_levels::dsl::name.like(sp));
}
}
if let Some(p) = &find_all.pagination {

View File

@ -9,6 +9,8 @@ table! {
///
name -> Text,
///
show -> Bool,
///
sort_order -> Integer,
///
created_at -> BigInt,

View File

@ -26,11 +26,18 @@ pub struct NewMemberPermission {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub role_resource_action_id: Option<uuid::Uuid>,
///
pub member_id: Option<uuid::Uuid>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -58,31 +58,40 @@ impl Repository {
conn: &diesel::PgConnection,
member_id: uuid::Uuid,
role_resource_action_id: uuid::Uuid,
) -> Result<models::MemberPermission, Error> {
) -> Result<Option<models::MemberPermission>, Error> {
use member_permissions::dsl;
member_permissions::table
match member_permissions::table
.filter(
dsl::member_id
.eq(member_id)
.and(dsl::role_resource_action_id.eq(role_resource_action_id)),
)
.first::<models::MemberPermission>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_permissions::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_permissions::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.role_resource_action_id {
q = q.filter(member_permissions::dsl::role_resource_action_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_permissions::dsl::member_id.eq(sp));
}
if let Some(sp) = s.role_resource_action_id {
q = q.filter(member_permissions::dsl::role_resource_action_id.eq(sp));
}
}
q.count().get_result(conn)
@ -92,18 +101,20 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberPermission>, Error> {
let mut q = member_permissions::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_permissions::dsl::member_id.eq(sp));
}
if let Some(sp) = find_all.role_resource_action_id {
q = q.filter(member_permissions::dsl::role_resource_action_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_permissions::dsl::member_id.eq(sp));
}
if let Some(sp) = s.role_resource_action_id {
q = q.filter(member_permissions::dsl::role_resource_action_id.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -111,7 +122,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {

View File

@ -26,11 +26,18 @@ pub struct NewMemberRole {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub role_id: Option<uuid::Uuid>,
///
pub member_id: Option<uuid::Uuid>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -58,27 +58,36 @@ impl Repository {
conn: &diesel::PgConnection,
member_id: uuid::Uuid,
role_id: uuid::Uuid,
) -> Result<models::MemberRole, Error> {
) -> Result<Option<models::MemberRole>, Error> {
use member_roles::dsl;
member_roles::table
match member_roles::table
.filter(dsl::member_id.eq(member_id).and(dsl::role_id.eq(role_id)))
.first::<models::MemberRole>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_roles::table.into_boxed();
if let Some(sp) = find_all.role_id {
q = q.filter(member_roles::dsl::role_id.eq(sp));
}
if let Some(sp) = find_all.member_id {
q = q.filter(member_roles::dsl::member_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.role_id {
q = q.filter(member_roles::dsl::role_id.eq(sp));
}
if let Some(sp) = s.member_id {
q = q.filter(member_roles::dsl::member_id.eq(sp));
}
}
q.count().get_result(conn)
@ -88,18 +97,20 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberRole>, Error> {
let mut q = member_roles::table.into_boxed();
if let Some(sp) = find_all.role_id {
q = q.filter(member_roles::dsl::role_id.eq(sp));
}
if let Some(sp) = find_all.member_id {
q = q.filter(member_roles::dsl::member_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.role_id {
q = q.filter(member_roles::dsl::role_id.eq(sp));
}
if let Some(sp) = s.member_id {
q = q.filter(member_roles::dsl::member_id.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -107,7 +118,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {

View File

@ -43,9 +43,16 @@ pub struct ModifyMemberSessionForLastAccess {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub member_id: Option<uuid::Uuid>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -81,12 +81,14 @@ impl Repository {
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = member_sessions::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_sessions::dsl::member_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_sessions::dsl::member_id.eq(sp));
}
}
q.count().get_result(conn)
@ -96,15 +98,17 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::MemberSession>, Error> {
let mut q = member_sessions::table.into_boxed();
if let Some(sp) = find_all.member_id {
q = q.filter(member_sessions::dsl::member_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.member_id {
q = q.filter(member_sessions::dsl::member_id.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -112,7 +116,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -167,6 +171,15 @@ impl Repository {
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use member_sessions::dsl;
diesel::delete(member_sessions::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete_expired(&self, conn: &diesel::PgConnection) -> Result<u64, Error> {
use member_sessions::dsl;

View File

@ -65,7 +65,7 @@ pub struct ModifyResource4CanUse {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub parent_id: Option<uuid::Uuid>,
///
@ -76,6 +76,13 @@ pub struct FindAll {
pub description_like: Option<String>,
///
pub can_use: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -44,34 +44,43 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::Resource, Error> {
resources::table
) -> Result<Option<models::Resource>, Error> {
match resources::table
.find(id as uuid::Uuid)
.first::<models::Resource>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = resources::table.into_boxed();
if let Some(sp) = find_all.parent_id {
q = q.filter(resources::dsl::parent_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(resources::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(resources::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(resources::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(resources::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.parent_id {
q = q.filter(resources::dsl::parent_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(resources::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(resources::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(resources::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(resources::dsl::can_use.eq(sp));
}
}
q.count().get_result(conn)
@ -81,27 +90,29 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::Resource>, Error> {
let mut q = resources::table.into_boxed();
if let Some(sp) = find_all.parent_id {
q = q.filter(resources::dsl::parent_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(resources::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(resources::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(resources::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(resources::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.parent_id {
q = q.filter(resources::dsl::parent_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(resources::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(resources::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(resources::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(resources::dsl::can_use.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -109,7 +120,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -185,4 +196,13 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use resources::dsl;
diesel::delete(resources::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -65,7 +65,7 @@ pub struct ModifyResourceAction4CanUse {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub resource_id: Option<uuid::Uuid>,
///
@ -76,6 +76,13 @@ pub struct FindAll {
pub description_like: Option<String>,
///
pub can_use: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -44,34 +44,43 @@ impl Repository {
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<models::ResourceAction, Error> {
resource_actions::table
) -> Result<Option<models::ResourceAction>, Error> {
match resource_actions::table
.find(id as uuid::Uuid)
.first::<models::ResourceAction>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = resource_actions::table.into_boxed();
if let Some(sp) = find_all.resource_id {
q = q.filter(resource_actions::dsl::resource_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(resource_actions::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(resource_actions::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(resource_actions::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(resource_actions::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.resource_id {
q = q.filter(resource_actions::dsl::resource_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(resource_actions::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(resource_actions::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(resource_actions::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(resource_actions::dsl::can_use.eq(sp));
}
}
q.count().get_result(conn)
@ -81,27 +90,29 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::ResourceAction>, Error> {
let mut q = resource_actions::table.into_boxed();
if let Some(sp) = find_all.resource_id {
q = q.filter(resource_actions::dsl::resource_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(resource_actions::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(resource_actions::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(resource_actions::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(resource_actions::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.resource_id {
q = q.filter(resource_actions::dsl::resource_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(resource_actions::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(resource_actions::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(resource_actions::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(resource_actions::dsl::can_use.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -109,7 +120,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -185,4 +196,13 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use resource_actions::dsl;
diesel::delete(resource_actions::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -65,7 +65,7 @@ pub struct ModifyRole4CanUse {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub parent_id: Option<uuid::Uuid>,
///
@ -76,6 +76,13 @@ pub struct FindAll {
pub description_like: Option<String>,
///
pub can_use: Option<bool>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -40,34 +40,47 @@ impl Repository {
}
///
pub fn select(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<models::Role, Error> {
roles::table
pub fn select(
&self,
conn: &diesel::PgConnection,
id: uuid::Uuid,
) -> Result<Option<models::Role>, Error> {
match roles::table
.find(id as uuid::Uuid)
.first::<models::Role>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = roles::table.into_boxed();
if let Some(sp) = find_all.parent_id {
q = q.filter(roles::dsl::parent_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(roles::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(roles::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(roles::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(roles::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.parent_id {
q = q.filter(roles::dsl::parent_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(roles::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(roles::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(roles::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(roles::dsl::can_use.eq(sp));
}
}
q.count().get_result(conn)
@ -81,23 +94,25 @@ impl Repository {
) -> Result<Vec<models::Role>, Error> {
let mut q = roles::table.into_boxed();
if let Some(sp) = find_all.parent_id {
q = q.filter(roles::dsl::parent_id.eq(sp));
}
if let Some(sp) = find_all.name_like {
q = q.filter(roles::dsl::name.like(sp));
}
if let Some(sp) = find_all.key_like {
q = q.filter(roles::dsl::key.like(sp));
}
if let Some(sp) = find_all.description_like {
q = q.filter(roles::dsl::description.like(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(roles::dsl::can_use.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.parent_id {
q = q.filter(roles::dsl::parent_id.eq(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(roles::dsl::name.like(sp));
}
if let Some(sp) = &s.key_like {
q = q.filter(roles::dsl::key.like(sp));
}
if let Some(sp) = &s.description_like {
q = q.filter(roles::dsl::description.like(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(roles::dsl::can_use.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -105,7 +120,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
@ -181,4 +196,13 @@ impl Repository {
.execute(conn)
.map(|c| c as u64)
}
///
pub fn delete(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result<u64, Error> {
use roles::dsl;
diesel::delete(roles::table.filter(dsl::id.eq(id)))
.execute(conn)
.map(|c| c as u64)
}
}

View File

@ -26,11 +26,18 @@ pub struct NewRoleResourceAction {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub role_id: Option<uuid::Uuid>,
///
pub resource_action_id: Option<uuid::Uuid>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -59,31 +59,40 @@ impl Repository {
conn: &diesel::PgConnection,
role_id: uuid::Uuid,
resource_action_id: uuid::Uuid,
) -> Result<models::RoleResourceAction, Error> {
) -> Result<Option<models::RoleResourceAction>, Error> {
use role_resource_actions::dsl;
role_resource_actions::table
match role_resource_actions::table
.filter(
dsl::role_id
.eq(role_id)
.and(dsl::resource_action_id.eq(resource_action_id)),
)
.first::<models::RoleResourceAction>(conn)
{
Ok(m) => Ok(Some(m)),
Err(e) => match e {
diesel::result::Error::NotFound => Ok(None),
_ => Err(e),
},
}
}
///
pub fn select_all_count(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<i64, Error> {
let mut q = role_resource_actions::table.into_boxed();
if let Some(sp) = find_all.role_id {
q = q.filter(role_resource_actions::dsl::role_id.eq(sp));
}
if let Some(sp) = find_all.resource_action_id {
q = q.filter(role_resource_actions::dsl::resource_action_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.role_id {
q = q.filter(role_resource_actions::dsl::role_id.eq(sp));
}
if let Some(sp) = s.resource_action_id {
q = q.filter(role_resource_actions::dsl::resource_action_id.eq(sp));
}
}
q.count().get_result(conn)
@ -93,18 +102,20 @@ impl Repository {
pub fn select_all(
&self,
conn: &diesel::PgConnection,
find_all: models::FindAll,
find_all: &models::FindAll,
) -> Result<Vec<models::RoleResourceAction>, Error> {
let mut q = role_resource_actions::table.into_boxed();
if let Some(sp) = find_all.role_id {
q = q.filter(role_resource_actions::dsl::role_id.eq(sp));
}
if let Some(sp) = find_all.resource_action_id {
q = q.filter(role_resource_actions::dsl::resource_action_id.eq(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = s.role_id {
q = q.filter(role_resource_actions::dsl::role_id.eq(sp));
}
if let Some(sp) = s.resource_action_id {
q = q.filter(role_resource_actions::dsl::resource_action_id.eq(sp));
}
}
if let Some(p) = find_all.pagination {
if let Some(p) = &find_all.pagination {
let page = p.page.unwrap_or(1);
if let Some(page_size) = p.page_size {
@ -112,7 +123,7 @@ impl Repository {
q = q.limit(page_size as i64);
}
}
if let Some(orderbys) = find_all.sorts {
if let Some(orderbys) = &find_all.sorts {
for s in orderbys {
match s {
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {

View File

@ -69,7 +69,7 @@ pub struct ModifySite {
///
#[derive(Debug, Clone)]
pub struct FindAll {
pub struct FindAllSearch {
///
pub url_like: Option<String>,
///
@ -82,6 +82,13 @@ pub struct FindAll {
pub can_use: Option<bool>,
///
pub memo_like: Option<String>,
}
///
#[derive(Debug, Clone)]
pub struct FindAll {
///
pub search: Option<FindAllSearch>,
///
pub pagination: Option<bcr::models::pagination::Pagination>,
///

View File

@ -82,23 +82,25 @@ impl Repository {
) -> Result<i64, Error> {
let mut q = sites::table.into_boxed();
if let Some(sp) = &find_all.url_like {
q = q.filter(sites::dsl::url.like(sp));
}
if let Some(sp) = &find_all.name_like {
q = q.filter(sites::dsl::name.like(sp));
}
if let Some(sp) = &find_all.path_like {
q = q.filter(sites::dsl::path.like(sp));
}
if let Some(sp) = find_all.show {
q = q.filter(sites::dsl::show.eq(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(sites::dsl::can_use.eq(sp));
}
if let Some(sp) = &find_all.memo_like {
q = q.filter(sites::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.url_like {
q = q.filter(sites::dsl::url.like(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(sites::dsl::name.like(sp));
}
if let Some(sp) = &s.path_like {
q = q.filter(sites::dsl::path.like(sp));
}
if let Some(sp) = s.show {
q = q.filter(sites::dsl::show.eq(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(sites::dsl::can_use.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(sites::dsl::memo.like(sp));
}
}
q.count().get_result(conn)
@ -112,23 +114,25 @@ impl Repository {
) -> Result<Vec<models::Site>, Error> {
let mut q = sites::table.into_boxed();
if let Some(sp) = &find_all.url_like {
q = q.filter(sites::dsl::url.like(sp));
}
if let Some(sp) = &find_all.name_like {
q = q.filter(sites::dsl::name.like(sp));
}
if let Some(sp) = &find_all.path_like {
q = q.filter(sites::dsl::path.like(sp));
}
if let Some(sp) = find_all.show {
q = q.filter(sites::dsl::show.eq(sp));
}
if let Some(sp) = find_all.can_use {
q = q.filter(sites::dsl::can_use.eq(sp));
}
if let Some(sp) = &find_all.memo_like {
q = q.filter(sites::dsl::memo.like(sp));
if let Some(s) = &find_all.search {
if let Some(sp) = &s.url_like {
q = q.filter(sites::dsl::url.like(sp));
}
if let Some(sp) = &s.name_like {
q = q.filter(sites::dsl::name.like(sp));
}
if let Some(sp) = &s.path_like {
q = q.filter(sites::dsl::path.like(sp));
}
if let Some(sp) = s.show {
q = q.filter(sites::dsl::show.eq(sp));
}
if let Some(sp) = s.can_use {
q = q.filter(sites::dsl::can_use.eq(sp));
}
if let Some(sp) = &s.memo_like {
q = q.filter(sites::dsl::memo.like(sp));
}
}
if let Some(p) = &find_all.pagination {

View File

@ -1,17 +1,15 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::site::models::Site> for bpr::models::domain::Site {
fn from(d: &repositories::site::models::Site) -> Self {
bpr::models::domain::Site {
impl From<&repositories::bank::models::Bank> for bpr::models::bank::Bank {
fn from(d: &repositories::bank::models::Bank) -> Self {
bpr::models::bank::Bank {
id: d.id.to_string(),
url: d.url.clone(),
name: d.name.clone(),
path: d.path.clone(),
show: d.show,
can_use: d.can_use,
memo: d.memo.clone(),
expires_at: d.expires_at.map(|d| d as u64),
sort_order: d.sort_order as u32,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}

View File

@ -21,6 +21,7 @@ pub struct Service {
pool: Pool<ConnectionManager<PgConnection>>,
site_repository: repositories::site::repository::Repository,
site_composition: compositions::site::composition::Composition,
bank_repository: repositories::bank::repository::Repository,
}
impl std::fmt::Debug for Service {
@ -43,19 +44,20 @@ impl Service {
pool,
site_repository: repositories::site::repository::Repository::new(),
site_composition: compositions::site::composition::Composition::new(),
bank_repository: repositories::bank::repository::Repository::new(),
}
}
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.list_sites(),
self.create_site(),
self.update_site(),
self.delete_site(),
self.create_bank(),
self.list_banks(),
self.get_bank(),
self.update_bank(),
self.delete_bank(),
)
.map(|_| ())
}
fn check_site(
&self,
conn: &diesel::PgConnection,
@ -88,19 +90,19 @@ impl Service {
}
}
async fn list_sites(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn create_bank(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_LIST_SITES,
bpr::ss::bank::SUBJECT_CREATE_BANK,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::ListSitesRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::bank::CreateBankRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
@ -123,6 +125,23 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -132,19 +151,141 @@ impl Service {
})
})?;
let find_all = repositories::site::models::FindAll {
url_like: None,
name_like: None,
path_like: None,
memo_like: None,
show: None,
can_use: None,
pagination: req
let s = self
.bank_repository
.insert(
&conn,
&repositories::bank::models::NewBank {
name: request.name,
sort_order: request.sort_order as i32,
show: request.show,
can_use: request.can_use,
memo: request.memo,
},
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::bank::CreateBankResponse {
error: None,
result: Some(bpr::ss::bank::create_bank_response::Result {
bank: Some(bpr::models::bank::Bank::from(&s)),
}),
}
.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::ss::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::ss::bank::SUBJECT_LIST_BANKS,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req =
bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_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 find_all = repositories::bank::models::FindAll {
search: match request.search {
Some(s) => Some(repositories::bank::models::FindAllSearch {
name_like: s.name_like,
memo_like: s.memo_like,
show: s.show,
can_use: s.can_use,
}),
None => None,
},
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
req
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
@ -153,7 +294,7 @@ impl Service {
};
let count = self
.site_repository
.bank_repository
.select_all_count(&conn, &find_all)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -164,7 +305,7 @@ impl Service {
})?;
let list = self
.site_repository
.bank_repository
.select_all(&conn, &find_all)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -176,12 +317,12 @@ impl Service {
message
.respond(
bpr::ss::domain::site::ListSitesResponse {
bpr::ss::bank::ListBanksResponse {
error: None,
result: Some(bpr::ss::domain::site::list_sites_response::Result {
sites: list
result: Some(bpr::ss::bank::list_banks_response::Result {
banks: list
.iter()
.map(|d| bpr::models::domain::Site::from(d))
.map(|d| bpr::models::bank::Bank::from(d))
.collect(),
}),
}
@ -202,7 +343,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::ListSitesResponse {
bpr::ss::bank::ListBanksResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -215,23 +356,19 @@ impl Service {
Ok(())
}
async fn create_site(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn get_bank(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_CREATE_SITE,
self.queue_broker.as_str(),
)
.queue_subscribe(bpr::ss::bank::SUBJECT_GET_BANK, self.queue_broker.as_str())
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
@ -250,6 +387,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -259,34 +425,20 @@ impl Service {
})
})?;
let s = self
.site_repository
.insert(
&conn,
&repositories::site::models::NewSite {
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.map(|d| d as i64),
},
)
.map_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 s = self.bank_repository.select(&conn, id).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::domain::site::CreateSiteResponse {
bpr::ss::bank::GetBankResponse {
error: None,
result: Some(bpr::ss::domain::site::create_site_response::Result {
site: Some(bpr::models::domain::Site::from(&s)),
result: Some(bpr::ss::bank::get_bank_response::Result {
bank: s.map(|d| bpr::models::bank::Bank::from(&d)),
}),
}
.encode_to_vec(),
@ -306,7 +458,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::CreateSiteResponse {
bpr::ss::bank::GetBankResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -319,37 +471,24 @@ impl Service {
Ok(())
}
async fn update_site(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn update_bank(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_UPDATE_SITE,
bpr::ss::bank::SUBJECT_UPDATE_BANK,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::UpdateSiteRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let client = match req.client {
Some(c) => c,
None => {
@ -367,7 +506,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -377,18 +544,16 @@ impl Service {
})?;
let _affected = self
.site_repository
.bank_repository
.update(
&conn,
id,
&repositories::site::models::ModifySite {
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.map(|d| d as i64),
&repositories::bank::models::ModifyBank {
name: request.name,
sort_order: request.sort_order as i32,
show: request.show,
can_use: request.can_use,
memo: request.memo,
},
)
.map_err(|e| {
@ -399,7 +564,7 @@ impl Service {
})
})?;
let s = self.site_repository.select(&conn, id).map_err(|e| {
let s = self.bank_repository.select(&conn, id).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
@ -409,10 +574,10 @@ impl Service {
message
.respond(
bpr::ss::domain::site::UpdateSiteResponse {
bpr::ss::bank::UpdateBankResponse {
error: None,
result: Some(bpr::ss::domain::site::update_site_response::Result {
site: s.map(|d| bpr::models::domain::Site::from(&d)),
result: Some(bpr::ss::bank::update_bank_response::Result {
bank: s.map(|d| bpr::models::bank::Bank::from(&d)),
}),
}
.encode_to_vec(),
@ -432,7 +597,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::UpdateSiteResponse {
bpr::ss::bank::UpdateBankResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -445,37 +610,24 @@ impl Service {
Ok(())
}
async fn delete_site(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn delete_bank(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_DELETE_SITE,
bpr::ss::bank::SUBJECT_DELETE_BANK,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::DeleteSiteRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let client = match req.client {
Some(c) => c,
None => {
@ -493,6 +645,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -502,7 +683,7 @@ impl Service {
})
})?;
let _affected = self.site_repository.delete(&conn, id).map_err(|e| {
let _affected = self.bank_repository.delete(&conn, id).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
@ -512,9 +693,9 @@ impl Service {
message
.respond(
bpr::ss::domain::site::DeleteSiteResponse {
bpr::ss::bank::DeleteBankResponse {
error: None,
result: Some(bpr::ss::domain::site::delete_site_response::Result {}),
result: Some(bpr::ss::bank::delete_bank_response::Result {}),
}
.encode_to_vec(),
)
@ -533,7 +714,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::DeleteSiteResponse {
bpr::ss::bank::DeleteBankResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}

View File

@ -104,21 +104,20 @@ impl Service<'_> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::identity::SUBJECT_CHECK_USERNAME_FOR_DUPLICATION,
bpr::ss::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 req = bpr::ss::member::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 req =
bpr::ss::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 client = match req.client {
Some(c) => c,
@ -137,7 +136,23 @@ impl Service<'_> {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -148,7 +163,7 @@ impl Service<'_> {
let m = self
.member_repository
.select_by_username(&conn, &req.username)
.select_by_username(&conn, &request.username)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -159,10 +174,10 @@ impl Service<'_> {
message
.respond(
bpr::ss::member::identity::CheckUsernameForDuplicationResponse {
bpr::ss::identity::CheckUsernameForDuplicationResponse {
error: None,
result: Some(
bpr::ss::member::identity::check_username_for_duplication_response::Result {
bpr::ss::identity::check_username_for_duplication_response::Result {
duplicated: m.is_some(),
},
),
@ -184,7 +199,7 @@ impl Service<'_> {
{
message
.respond(
bpr::ss::member::identity::CheckUsernameForDuplicationResponse {
bpr::ss::identity::CheckUsernameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -201,21 +216,20 @@ impl Service<'_> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::identity::SUBJECT_CHECK_NICKNAME_FOR_DUPLICATION,
bpr::ss::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 req = bpr::ss::member::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 req =
bpr::ss::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 client = match req.client {
Some(c) => c,
@ -234,7 +248,23 @@ impl Service<'_> {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -245,7 +275,7 @@ impl Service<'_> {
let m = self
.member_repository
.select_by_nickname(&conn, &req.nickname)
.select_by_nickname(&conn, &request.nickname)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -256,10 +286,10 @@ impl Service<'_> {
message
.respond(
bpr::ss::member::identity::CheckNicknameForDuplicationResponse {
bpr::ss::identity::CheckNicknameForDuplicationResponse {
error: None,
result: Some(
bpr::ss::member::identity::check_nickname_for_duplication_response::Result {
bpr::ss::identity::check_nickname_for_duplication_response::Result {
duplicated: m.is_some(),
},
),
@ -281,7 +311,7 @@ impl Service<'_> {
{
message
.respond(
bpr::ss::member::identity::CheckNicknameForDuplicationResponse {
bpr::ss::identity::CheckNicknameForDuplicationResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -298,15 +328,15 @@ impl Service<'_> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::identity::SUBJECT_CAPTCHA,
bpr::ss::identity::SUBJECT_CAPTCHA,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::member::identity::CaptchaRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::identity::CaptchaRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
@ -329,7 +359,23 @@ impl Service<'_> {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let mut c = captcha::Captcha::new();
let c = c
@ -358,9 +404,9 @@ impl Service<'_> {
message
.respond(
bpr::ss::member::identity::CaptchaResponse {
bpr::ss::identity::CaptchaResponse {
error: None,
result: Some(bpr::ss::member::identity::captcha_response::Result {
result: Some(bpr::ss::identity::captcha_response::Result {
security_code_hash,
image: image_as_base64,
}),
@ -382,7 +428,7 @@ impl Service<'_> {
{
message
.respond(
bpr::ss::member::identity::CaptchaResponse {
bpr::ss::identity::CaptchaResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -399,15 +445,15 @@ impl Service<'_> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::identity::SUBJECT_SIGNIN,
bpr::ss::identity::SUBJECT_SIGNIN,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::member::identity::SigninRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::identity::SigninRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
@ -430,7 +476,23 @@ impl Service<'_> {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -439,10 +501,10 @@ impl Service<'_> {
})
})?;
let security_code_hash = req.security_code_hash;
let security_code = req.security_code;
let username = req.username;
let password = req.password;
let security_code_hash = request.security_code_hash;
let security_code = request.security_code;
let username = request.username;
let password = request.password;
let security_code_matches =
argon2::verify_encoded(security_code_hash.as_str(), security_code.as_bytes()).map_err(
@ -563,10 +625,12 @@ impl Service<'_> {
self
.connection_broker
.publish(
bpr::ss::member::identity::EVENT_SUBJECT_AFTER_SIGNIN,
bpr::ss::member::identity::AfterSigninEvent {
bpr::ss::identity::EVENT_SUBJECT_AFTER_SIGNIN,
bpr::ss::identity::AfterSigninEvent {
client: Some(client),
member: Some(bpr::models::member::Member::from(&m)),
event: Some(bpr::ss::identity::after_signin_event::Event {
member: Some(bpr::models::member::Member::from(&m)),
}),
}
.encode_to_vec(),
)
@ -581,9 +645,9 @@ impl Service<'_> {
message
.respond(
bpr::ss::member::identity::SigninResponse {
bpr::ss::identity::SigninResponse {
error: None,
result: Some(bpr::ss::member::identity::signin_response::Result { access_token }),
result: Some(bpr::ss::identity::signin_response::Result { access_token }),
}
.encode_to_vec(),
)
@ -602,7 +666,7 @@ impl Service<'_> {
{
message
.respond(
bpr::ss::member::identity::SigninResponse {
bpr::ss::identity::SigninResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}

View File

@ -28,30 +28,6 @@ impl From<i32> for repositories::member::schema::MemberState {
}
}
impl From<&repositories::member_class::models::MemberClass> for bpr::models::member::MemberClass {
fn from(d: &repositories::member_class::models::MemberClass) -> Self {
bpr::models::member::MemberClass {
id: d.id.to_string(),
parent_id: d.parent_id.map(|d| d.to_string()),
name: d.name.clone(),
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}
impl From<&repositories::member_level::models::MemberLevel> for bpr::models::member::MemberLevel {
fn from(d: &repositories::member_level::models::MemberLevel) -> Self {
bpr::models::member::MemberLevel {
id: d.id.to_string(),
name: d.name.clone(),
sort_order: d.sort_order as u32,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}
impl From<&repositories::member::models::Member> for bpr::models::member::Member {
fn from(d: &repositories::member::models::Member) -> Self {
bpr::models::member::Member {
@ -79,9 +55,13 @@ impl From<&compositions::member::models::MemberModel> for bpr::models::member::M
fn from(d: &compositions::member::models::MemberModel) -> Self {
bpr::models::member::MemberModel {
id: d.id.to_string(),
site: Some(bpr::models::domain::Site::from(&d.site)),
member_class: Some(bpr::models::member::MemberClass::from(&d.member_class)),
member_level: Some(bpr::models::member::MemberLevel::from(&d.member_level)),
site: Some(bpr::models::site::Site::from(&d.site)),
member_class: Some(bpr::models::member_class::MemberClass::from(
&d.member_class,
)),
member_level: Some(bpr::models::member_level::MemberLevel::from(
&d.member_level,
)),
referrer_member: d
.referrer_member
.as_ref()

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -0,0 +1,19 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::member_bank_account::models::MemberBankAccount>
for bpr::models::member_bank_account::MemberBankAccount
{
fn from(d: &repositories::member_bank_account::models::MemberBankAccount) -> Self {
bpr::models::member_bank_account::MemberBankAccount {
id: d.id.to_string(),
member_id: d.member_id.to_string(),
bank_id: d.bank_id.to_string(),
name: d.name.clone(),
account_number: d.account_number.to_string(),
memo: d.memo.clone(),
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}

View File

@ -0,0 +1,850 @@
//!
//!
use std::str::FromStr;
use super::models;
use crate::compositions;
use crate::repositories;
use beteran_common_rust as bcr;
use beteran_protobuf_rust as bpr;
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
use prost::Message;
///
pub struct Service {
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
site_repository: repositories::site::repository::Repository,
site_composition: compositions::site::composition::Composition,
member_bank_account_repository: repositories::member_bank_account::repository::Repository,
}
impl std::fmt::Debug for Service {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("Service of service.member.service.identity")
.finish()
}
}
impl Service {
///
pub fn new(
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
) -> Service {
Service {
connection_broker,
queue_broker,
pool,
site_repository: repositories::site::repository::Repository::new(),
site_composition: compositions::site::composition::Composition::new(),
member_bank_account_repository:
repositories::member_bank_account::repository::Repository::new(),
}
}
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.create_member_bank_account(),
self.list_member_bank_accounts(),
self.get_member_bank_account(),
self.update_member_bank_account(),
self.delete_member_bank_account(),
)
.map(|_| ())
}
fn check_site(
&self,
conn: &diesel::PgConnection,
url: Option<String>,
site_id: uuid::Uuid,
) -> Result<repositories::site::models::Site, bcr::error::rpc::Error> {
match self
.site_composition
.select_by_url(conn, url, site_id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})? {
Some(s) => Ok(s),
None => Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid site_url information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client.site_url".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::None,
message: "".to_string(),
},
},
)),
}
}
async fn create_member_bank_account(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let member_id = uuid::Uuid::from_str(request.member_id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid member_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: request.member_id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let bank_id = uuid::Uuid::from_str(request.bank_id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid bank_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "bank_id".to_string(),
value: request.bank_id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_bank_account_repository
.insert(
&conn,
&repositories::member_bank_account::models::NewMemberBankAccount {
member_id,
bank_id,
name: request.name,
account_number: request.account_number,
memo: request.memo,
},
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_account::CreateMemberBankAccountResponse {
error: None,
result: Some(
bpr::ss::member_bank_account::create_member_bank_account_response::Result {
member_bank_account: Some(
bpr::models::member_bank_account::MemberBankAccount::from(&s),
),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => {
let member_id = match s.member_id {
Some(d) => match uuid::Uuid::from_str(d.as_str()) {
Ok(dd) => Some(dd),
Err(e) => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid member_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: d.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
},
));
}
},
None => None,
};
let bank_id = match s.bank_id {
Some(d) => match uuid::Uuid::from_str(d.as_str()) {
Ok(dd) => Some(dd),
Err(e) => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid bank_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "bank_id".to_string(),
value: d.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
},
));
}
},
None => None,
};
Some(repositories::member_bank_account::models::FindAllSearch {
member_id,
bank_id,
name_like: s.name_like,
account_number_like: s.account_number_like,
memo_like: s.memo_like,
})
}
None => None,
};
let conn = self.pool.get().map_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 find_all = repositories::member_bank_account::models::FindAll {
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
.collect(),
),
};
let count = self
.member_bank_account_repository
.select_all_count(&conn, &find_all)
.map_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 list = self
.member_bank_account_repository
.select_all(&conn, &find_all)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_account::ListMemberBankAccountsResponse {
error: None,
result: Some(
bpr::ss::member_bank_account::list_member_bank_accounts_response::Result {
member_bank_accounts: list
.iter()
.map(|d| bpr::models::member_bank_account::MemberBankAccount::from(d))
.collect(),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_bank_account_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_account::GetMemberBankAccountResponse {
error: None,
result: Some(
bpr::ss::member_bank_account::get_member_bank_account_response::Result {
member_bank_account: s
.map(|d| bpr::models::member_bank_account::MemberBankAccount::from(&d)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let bank_id = uuid::Uuid::from_str(request.bank_id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "bank_id".to_string(),
value: request.bank_id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 _affected = self
.member_bank_account_repository
.update(
&conn,
id,
&repositories::member_bank_account::models::ModifyMemberBankAccount {
name: request.name,
memo: request.memo,
bank_id,
account_number: request.account_number,
},
)
.map_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 s = self
.member_bank_account_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_account::UpdateMemberBankAccountResponse {
error: None,
result: Some(
bpr::ss::member_bank_account::update_member_bank_account_response::Result {
member_bank_account: s
.map(|d| bpr::models::member_bank_account::MemberBankAccount::from(&d)),
},
),
}
.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::ss::member_bank_account::UpdateMemberBankAccountResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
async fn delete_member_bank_account(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 _affected = self
.member_bank_account_repository
.delete(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_account::DeleteMemberBankAccountResponse {
error: None,
result: Some(
bpr::ss::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::ss::member_bank_account::DeleteMemberBankAccountResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -0,0 +1,33 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::member_bank_deposit::models::MemberBankDeposit>
for bpr::models::member_bank_deposit::MemberBankDeposit
{
fn from(d: &repositories::member_bank_deposit::models::MemberBankDeposit) -> Self {
bpr::models::member_bank_deposit::MemberBankDeposit {
id: d.id.to_string(),
member_id: d.member_id.to_string(),
name: d.name.clone(),
amount: d.amount as u32,
memo: d.memo.clone(),
state: d.state as i32,
state_changed_at: d.state_changed_at as u64,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}
impl From<i32> for repositories::member_bank_deposit::schema::MemberBankDepositState {
fn from(s: i32) -> Self {
match s {
s if s
== repositories::member_bank_deposit::schema::MemberBankDepositState::Complete as i32 =>
{
repositories::member_bank_deposit::schema::MemberBankDepositState::Complete
}
_ => repositories::member_bank_deposit::schema::MemberBankDepositState::Application,
}
}
}

View File

@ -0,0 +1,946 @@
//!
//!
use std::str::FromStr;
use super::models;
use crate::compositions;
use crate::repositories;
use beteran_common_rust as bcr;
use beteran_protobuf_rust as bpr;
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
use prost::Message;
///
pub struct Service {
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
site_repository: repositories::site::repository::Repository,
site_composition: compositions::site::composition::Composition,
member_bank_deposit_repository: repositories::member_bank_deposit::repository::Repository,
}
impl std::fmt::Debug for Service {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("Service of service.member.service.identity")
.finish()
}
}
impl Service {
///
pub fn new(
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
) -> Service {
Service {
connection_broker,
queue_broker,
pool,
site_repository: repositories::site::repository::Repository::new(),
site_composition: compositions::site::composition::Composition::new(),
member_bank_deposit_repository:
repositories::member_bank_deposit::repository::Repository::new(),
}
}
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 check_site(
&self,
conn: &diesel::PgConnection,
url: Option<String>,
site_id: uuid::Uuid,
) -> Result<repositories::site::models::Site, bcr::error::rpc::Error> {
match self
.site_composition
.select_by_url(conn, url, site_id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})? {
Some(s) => Ok(s),
None => Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid site_url information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client.site_url".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::None,
message: "".to_string(),
},
},
)),
}
}
async fn create_member_bank_deposit(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let member_id = uuid::Uuid::from_str(request.member_id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid member_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: request.member_id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_bank_deposit_repository
.insert(
&conn,
&repositories::member_bank_deposit::models::NewMemberBankDeposit {
member_id,
name: request.name,
amount: request.amount as i32,
memo: request.memo,
},
)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::CreateMemberBankDepositResponse {
error: None,
result: Some(
bpr::ss::member_bank_deposit::create_member_bank_deposit_response::Result {
member_bank_deposit: Some(
bpr::models::member_bank_deposit::MemberBankDeposit::from(&s),
),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => {
let member_id = match s.member_id {
Some(d) => match uuid::Uuid::from_str(d.as_str()) {
Ok(dd) => Some(dd),
Err(e) => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid member_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: d.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
},
));
}
},
None => None,
};
Some(repositories::member_bank_deposit::models::FindAllSearch {
member_id,
name_like: s.name_like,
amount: s.amount.map(|d| d as i32),
memo_like: s.memo_like,
state: s.state.map(|d| {
repositories::member_bank_deposit::schema::MemberBankDepositState::from(d)
}),
})
}
None => None,
};
let conn = self.pool.get().map_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 find_all = repositories::member_bank_deposit::models::FindAll {
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
.collect(),
),
};
let count = self
.member_bank_deposit_repository
.select_all_count(&conn, &find_all)
.map_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 list = self
.member_bank_deposit_repository
.select_all(&conn, &find_all)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::ListMemberBankDepositsResponse {
error: None,
result: Some(
bpr::ss::member_bank_deposit::list_member_bank_deposits_response::Result {
member_bank_deposits: list
.iter()
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(d))
.collect(),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_bank_deposit_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::GetMemberBankDepositResponse {
error: None,
result: Some(
bpr::ss::member_bank_deposit::get_member_bank_deposit_response::Result {
member_bank_deposit: s
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(&d)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_member_bank_deposit =
repositories::member_bank_deposit::models::ModifyMemberBankDeposit {
name: request.name,
amount: request.amount as i32,
memo: request.memo,
};
let _affected = self
.member_bank_deposit_repository
.update(&conn, id, &modify_member_bank_deposit)
.map_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 s = self
.member_bank_deposit_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::UpdateMemberBankDepositResponse {
error: None,
result: Some(
bpr::ss::member_bank_deposit::update_member_bank_deposit_response::Result {
member_bank_deposit: s
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(&d)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_member_bank_deposit_for_state =
repositories::member_bank_deposit::models::ModifyMemberBankDepositForState {
state: repositories::member_bank_deposit::schema::MemberBankDepositState::from(
request.state,
),
};
let _affected = self
.member_bank_deposit_repository
.update_state(&conn, id, &modify_member_bank_deposit_for_state)
.map_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 s = self
.member_bank_deposit_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::UpdateMemberBankDepositResponse {
error: None,
result: Some(
bpr::ss::member_bank_deposit::update_member_bank_deposit_response::Result {
member_bank_deposit: s
.map(|d| bpr::models::member_bank_deposit::MemberBankDeposit::from(&d)),
},
),
}
.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::ss::member_bank_deposit::UpdateMemberBankDepositResponse {
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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 _affected = self
.member_bank_deposit_repository
.delete(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_deposit::DeleteMemberBankDepositResponse {
error: None,
result: Some(
bpr::ss::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::ss::member_bank_deposit::DeleteMemberBankDepositResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

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

View File

@ -0,0 +1,36 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::member_bank_withdraw::models::MemberBankWithdraw>
for bpr::models::member_bank_withdraw::MemberBankWithdraw
{
fn from(d: &repositories::member_bank_withdraw::models::MemberBankWithdraw) -> Self {
bpr::models::member_bank_withdraw::MemberBankWithdraw {
id: d.id.to_string(),
member_id: d.member_id.to_string(),
bank_name: d.bank_name.clone(),
account_number: d.account_number.clone(),
password: d.password.clone(),
name: d.name.clone(),
amount: d.amount as u32,
memo: d.memo.clone(),
state: d.state as i32,
state_changed_at: d.state_changed_at as u64,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}
impl From<i32> for repositories::member_bank_withdraw::schema::MemberBankWithdrawState {
fn from(s: i32) -> Self {
match s {
s if s
== repositories::member_bank_withdraw::schema::MemberBankWithdrawState::Complete as i32 =>
{
repositories::member_bank_withdraw::schema::MemberBankWithdrawState::Complete
}
_ => repositories::member_bank_withdraw::schema::MemberBankWithdrawState::Application,
}
}
}

View File

@ -0,0 +1,952 @@
//!
//!
use std::str::FromStr;
use super::models;
use crate::compositions;
use crate::repositories;
use beteran_common_rust as bcr;
use beteran_protobuf_rust as bpr;
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
use prost::Message;
///
pub struct Service {
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
site_repository: repositories::site::repository::Repository,
site_composition: compositions::site::composition::Composition,
member_bank_withdraw_repository: repositories::member_bank_withdraw::repository::Repository,
}
impl std::fmt::Debug for Service {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("Service of service.member.service.identity")
.finish()
}
}
impl Service {
///
pub fn new(
connection_broker: nats::asynk::Connection,
queue_broker: String,
pool: Pool<ConnectionManager<PgConnection>>,
) -> Service {
Service {
connection_broker,
queue_broker,
pool,
site_repository: repositories::site::repository::Repository::new(),
site_composition: compositions::site::composition::Composition::new(),
member_bank_withdraw_repository:
repositories::member_bank_withdraw::repository::Repository::new(),
}
}
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 check_site(
&self,
conn: &diesel::PgConnection,
url: Option<String>,
site_id: uuid::Uuid,
) -> Result<repositories::site::models::Site, bcr::error::rpc::Error> {
match self
.site_composition
.select_by_url(conn, url, site_id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})? {
Some(s) => Ok(s),
None => Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid site_url information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client.site_url".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::None,
message: "".to_string(),
},
},
)),
}
}
async fn create_member_bank_withdraw(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let member_id = uuid::Uuid::from_str(request.member_id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: request.member_id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 new_member_bank_withdraw =
repositories::member_bank_withdraw::models::NewMemberBankWithdraw {
member_id,
bank_name: request.bank_name,
name: request.name,
account_number: request.account_number,
amount: request.amount as i32,
password: request.password,
memo: request.memo,
};
let s = self
.member_bank_withdraw_repository
.insert(&conn, &new_member_bank_withdraw)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::CreateMemberBankWithdrawResponse {
error: None,
result: Some(
bpr::ss::member_bank_withdraw::create_member_bank_withdraw_response::Result {
member_bank_withdraw: Some(
bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&s),
),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => {
let member_id = match s.member_id {
Some(d) => match uuid::Uuid::from_str(d.as_str()) {
Ok(dd) => Some(dd),
Err(e) => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid member_id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "member_id".to_string(),
value: d.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
},
));
}
},
None => None,
};
Some(repositories::member_bank_withdraw::models::FindAllSearch {
member_id,
bank_name_like: s.bank_name_like,
name_like: s.name_like,
account_number_like: s.account_number_like,
amount: s.amount.map(|d| d as i32),
memo_like: s.memo_like,
state: s.state.map(|d| {
repositories::member_bank_withdraw::schema::MemberBankWithdrawState::from(d)
}),
})
}
None => None,
};
let conn = self.pool.get().map_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 find_all = repositories::member_bank_withdraw::models::FindAll {
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
.collect(),
),
};
let count = self
.member_bank_withdraw_repository
.select_all_count(&conn, &find_all)
.map_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 list = self
.member_bank_withdraw_repository
.select_all(&conn, &find_all)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::ListMemberBankWithdrawsResponse {
error: None,
result: Some(
bpr::ss::member_bank_withdraw::list_member_bank_withdraws_response::Result {
member_bank_withdraws: list
.iter()
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(d))
.collect(),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_bank_withdraw_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::GetMemberBankWithdrawResponse {
error: None,
result: Some(
bpr::ss::member_bank_withdraw::get_member_bank_withdraw_response::Result {
member_bank_withdraw: s
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&d)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_member_bank_withdraw =
repositories::member_bank_withdraw::models::ModifyMemberBankWithdraw {
bank_name: request.bank_name,
name: request.name,
account_number: request.account_number,
amount: request.amount as i32,
password: request.password,
memo: request.memo,
};
let _affected = self
.member_bank_withdraw_repository
.update(&conn, id, &modify_member_bank_withdraw)
.map_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 s = self
.member_bank_withdraw_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawResponse {
error: None,
result: Some(
bpr::ss::member_bank_withdraw::update_member_bank_withdraw_response::Result {
member_bank_withdraw: s
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&d)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_member_bank_withdraw_for_state =
repositories::member_bank_withdraw::models::ModifyMemberBankWithdrawForState {
state: repositories::member_bank_withdraw::schema::MemberBankWithdrawState::from(
request.state,
),
};
let _affected = self
.member_bank_withdraw_repository
.update_state(&conn, id, &modify_member_bank_withdraw_for_state)
.map_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 s = self
.member_bank_withdraw_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::UpdateMemberBankWithdrawForStateResponse {
error: None,
result: Some(
bpr::ss::member_bank_withdraw::update_member_bank_withdraw_for_state_response::Result {
member_bank_withdraw: s
.map(|d| bpr::models::member_bank_withdraw::MemberBankWithdraw::from(&d)),
},
),
}
.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::ss::member_bank_withdraw::UpdateMemberBankWithdrawResponse {
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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 _affected = self
.member_bank_withdraw_repository
.delete(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_bank_withdraw::DeleteMemberBankWithdrawResponse {
error: None,
result: Some(
bpr::ss::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::ss::member_bank_withdraw::DeleteMemberBankWithdrawResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
.encode_to_vec(),
)
.await?;
}
}
Ok(())
}
}

View File

@ -1 +1,17 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::member_class::models::MemberClass>
for bpr::models::member_class::MemberClass
{
fn from(d: &repositories::member_class::models::MemberClass) -> Self {
bpr::models::member_class::MemberClass {
id: d.id.to_string(),
parent_id: d.parent_id.map(|d| d.to_string()),
name: d.name.clone(),
show: d.show,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}

View File

@ -48,8 +48,9 @@ impl Service {
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.list_member_classes(),
self.create_member_class(),
self.list_member_classes(),
self.get_member_class(),
self.update_member_class(),
self.delete_member_class(),
)
@ -92,22 +93,54 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_class::SUBJECT_CREATE_MEMBER_CLASS,
bpr::ss::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 req =
bpr::ss::member::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 parent_id = match req.parent_id {
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let parent_id = match request.parent_id {
Some(parent_id) => match uuid::Uuid::from_str(parent_id.as_str()) {
Ok(parent_id) => Some(parent_id),
Err(e) => {
@ -128,24 +161,6 @@ impl Service {
None => None,
};
let client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -154,15 +169,15 @@ impl Service {
})
})?;
let new_member_class = repositories::member_class::models::NewMemberClass {
parent_id,
name: request.name,
show: request.show,
};
let s = self
.member_class_repository
.insert(
&conn,
&repositories::member_class::models::NewMemberClass {
parent_id,
name: req.name,
},
)
.insert(&conn, &new_member_class)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -173,11 +188,11 @@ impl Service {
message
.respond(
bpr::ss::member::member_class::CreateMemberClassResponse {
bpr::ss::member_class::CreateMemberClassResponse {
error: None,
result: Some(
bpr::ss::member::member_class::create_member_class_response::Result {
member_class: Some(bpr::models::member::MemberClass::from(&s)),
bpr::ss::member_class::create_member_class_response::Result {
member_class: Some(bpr::models::member_class::MemberClass::from(&s)),
},
),
}
@ -198,7 +213,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_class::CreateMemberClassResponse {
bpr::ss::member_class::CreateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -215,20 +230,19 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_class::SUBJECT_LIST_MEMBER_CLASSES,
bpr::ss::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 req =
bpr::ss::member::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
@ -247,6 +261,30 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => Some(repositories::member_class::models::FindAllSearch {
name_like: s.name_like,
show: s.show,
}),
None => None,
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -257,13 +295,13 @@ impl Service {
})?;
let find_all = repositories::member_class::models::FindAll {
name_like: None,
pagination: req
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
req
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
@ -295,13 +333,13 @@ impl Service {
message
.respond(
bpr::ss::member::member_class::ListMemberClassesResponse {
bpr::ss::member_class::ListMemberClassesResponse {
error: None,
result: Some(
bpr::ss::member::member_class::list_member_classes_response::Result {
bpr::ss::member_class::list_member_classes_response::Result {
member_classes: list
.iter()
.map(|d| bpr::models::member::MemberClass::from(d))
.map(|d| bpr::models::member_class::MemberClass::from(d))
.collect(),
},
),
@ -323,7 +361,128 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_class::ListMemberClassesResponse {
bpr::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 s = self
.member_class_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_class::GetMemberClassResponse {
error: None,
result: Some(bpr::ss::member_class::get_member_class_response::Result {
member_class: s.map(|d| bpr::models::member_class::MemberClass::from(&d)),
}),
}
.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::ss::member_class::GetMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -340,35 +499,67 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_class::SUBJECT_UPDATE_MEMBER_CLASS,
bpr::ss::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 req =
bpr::ss::member::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let parent_id = match req.parent_id {
let parent_id = match request.parent_id {
Some(parent_id) => match uuid::Uuid::from_str(parent_id.as_str()) {
Ok(parent_id) => Some(parent_id),
Err(e) => {
@ -389,24 +580,6 @@ impl Service {
None => None,
};
let client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -422,7 +595,8 @@ impl Service {
id,
&repositories::member_class::models::ModifyMemberClass {
parent_id,
name: req.name,
name: request.name,
show: request.show,
},
)
.map_err(|e| {
@ -446,11 +620,11 @@ impl Service {
message
.respond(
bpr::ss::member::member_class::UpdateMemberClassResponse {
bpr::ss::member_class::UpdateMemberClassResponse {
error: None,
result: Some(
bpr::ss::member::member_class::update_member_class_response::Result {
member_class: Some(bpr::models::member::MemberClass::from(&s)),
bpr::ss::member_class::update_member_class_response::Result {
member_class: s.map(|d| bpr::models::member_class::MemberClass::from(&d)),
},
),
}
@ -471,7 +645,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_class::UpdateMemberClassResponse {
bpr::ss::member_class::UpdateMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -488,34 +662,19 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_class::SUBJECT_DELETE_MEMBER_CLASS,
bpr::ss::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 req =
bpr::ss::member::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
@ -533,6 +692,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -555,9 +743,9 @@ impl Service {
message
.respond(
bpr::ss::member::member_class::DeleteMemberClassResponse {
bpr::ss::member_class::DeleteMemberClassResponse {
error: None,
result: Some(bpr::ss::member::member_class::delete_member_class_response::Result {}),
result: Some(bpr::ss::member_class::delete_member_class_response::Result {}),
}
.encode_to_vec(),
)
@ -576,7 +764,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_class::DeleteMemberClassResponse {
bpr::ss::member_class::DeleteMemberClassResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}

View File

@ -1 +1,17 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::member_level::models::MemberLevel>
for bpr::models::member_level::MemberLevel
{
fn from(d: &repositories::member_level::models::MemberLevel) -> Self {
bpr::models::member_level::MemberLevel {
id: d.id.to_string(),
name: d.name.clone(),
sort_order: d.sort_order as u32,
show: d.show,
created_at: d.created_at as u64,
updated_at: d.updated_at as u64,
}
}
}

View File

@ -48,8 +48,9 @@ impl Service {
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.list_member_levels(),
self.create_member_level(),
self.list_member_levels(),
self.get_member_level(),
self.update_member_level(),
self.delete_member_level(),
)
@ -92,118 +93,15 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_level::SUBJECT_CREATE_MEMBER_LEVEL,
bpr::ss::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 req =
bpr::ss::member::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_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 s = self
.member_level_repository
.insert(
&conn,
&repositories::member_level::models::NewMemberLevel {
name: req.name,
sort_order: req.sort_order as i32,
},
)
let req = bpr::ss::member_level::CreateMemberLevelRequest::decode(message.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,
})
})?;
message
.respond(
bpr::ss::member::member_level::CreateMemberLevelResponse {
error: None,
result: Some(
bpr::ss::member::member_level::create_member_level_response::Result {
member_level: Some(bpr::models::member::MemberLevel::from(&s)),
},
),
}
.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::ss::member::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::ss::member::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 req =
bpr::ss::member::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),
})
@ -226,6 +124,146 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_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 new_member_level = repositories::member_level::models::NewMemberLevel {
name: request.name,
sort_order: request.sort_order as i32,
show: request.show,
};
let s = self
.member_level_repository
.insert(&conn, &new_member_level)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_level::CreateMemberLevelResponse {
error: None,
result: Some(
bpr::ss::member_level::create_member_level_response::Result {
member_level: Some(bpr::models::member_level::MemberLevel::from(&s)),
},
),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => Some(repositories::member_level::models::FindAllSearch {
name_like: s.name_like,
show: s.show,
}),
None => None,
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -236,13 +274,13 @@ impl Service {
})?;
let find_all = repositories::member_level::models::FindAll {
name_like: None,
pagination: req
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
req
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
@ -274,16 +312,14 @@ impl Service {
message
.respond(
bpr::ss::member::member_level::ListMemberLevelsResponse {
bpr::ss::member_level::ListMemberLevelsResponse {
error: None,
result: Some(
bpr::ss::member::member_level::list_member_levels_response::Result {
member_levels: list
.iter()
.map(|d| bpr::models::member::MemberLevel::from(d))
.collect(),
},
),
result: Some(bpr::ss::member_level::list_member_levels_response::Result {
member_levels: list
.iter()
.map(|d| bpr::models::member_level::MemberLevel::from(d))
.collect(),
}),
}
.encode_to_vec(),
)
@ -302,7 +338,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_level::ListMemberLevelsResponse {
bpr::ss::member_level::ListMemberLevelsResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -315,38 +351,23 @@ impl Service {
Ok(())
}
async fn update_member_level(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn get_member_level(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_level::SUBJECT_UPDATE_MEMBER_LEVEL,
bpr::ss::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 req =
bpr::ss::member::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
@ -364,6 +385,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -373,16 +423,136 @@ impl Service {
})
})?;
let s = self
.member_level_repository
.select(&conn, id)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::member_level::GetMemberLevelResponse {
error: None,
result: Some(bpr::ss::member_level::get_member_level_response::Result {
member_level: s.map(|d| bpr::models::member_level::MemberLevel::from(&d)),
}),
}
.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::ss::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::ss::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 req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_member_level = repositories::member_level::models::ModifyMemberLevel {
name: request.name,
sort_order: request.sort_order as i32,
show: request.show,
};
let _affected = self
.member_level_repository
.update(
&conn,
id,
&repositories::member_level::models::ModifyMemberLevel {
name: req.name,
sort_order: req.sort_order as i32,
},
)
.update(&conn, id, &modify_member_level)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -404,11 +574,11 @@ impl Service {
message
.respond(
bpr::ss::member::member_level::UpdateMemberLevelResponse {
bpr::ss::member_level::UpdateMemberLevelResponse {
error: None,
result: Some(
bpr::ss::member::member_level::update_member_level_response::Result {
member_level: Some(bpr::models::member::MemberLevel::from(&s)),
bpr::ss::member_level::update_member_level_response::Result {
member_level: s.map(|d| bpr::models::member_level::MemberLevel::from(&d)),
},
),
}
@ -429,7 +599,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_level::UpdateMemberLevelResponse {
bpr::ss::member_level::UpdateMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -446,34 +616,19 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::member::member_level::SUBJECT_DELETE_MEMBER_LEVEL,
bpr::ss::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 req =
bpr::ss::member::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
@ -491,6 +646,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -513,9 +697,9 @@ impl Service {
message
.respond(
bpr::ss::member::member_level::DeleteMemberLevelResponse {
bpr::ss::member_level::DeleteMemberLevelResponse {
error: None,
result: Some(bpr::ss::member::member_level::delete_member_level_response::Result {}),
result: Some(bpr::ss::member_level::delete_member_level_response::Result {}),
}
.encode_to_vec(),
)
@ -534,7 +718,7 @@ impl Service {
{
message
.respond(
bpr::ss::member::member_level::DeleteMemberLevelResponse {
bpr::ss::member_level::DeleteMemberLevelResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}

View File

@ -1,5 +1,9 @@
pub mod bank;
pub mod identity;
pub mod member;
pub mod member_bank_account;
pub mod member_bank_deposit;
pub mod member_bank_withdraw;
pub mod member_class;
pub mod member_level;
pub mod site;

View File

@ -1,9 +1,9 @@
use crate::repositories;
use beteran_protobuf_rust as bpr;
impl From<&repositories::site::models::Site> for bpr::models::domain::Site {
impl From<&repositories::site::models::Site> for bpr::models::site::Site {
fn from(d: &repositories::site::models::Site) -> Self {
bpr::models::domain::Site {
bpr::models::site::Site {
id: d.id.to_string(),
url: d.url.clone(),
name: d.name.clone(),

View File

@ -48,8 +48,9 @@ impl Service {
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
futures::try_join!(
self.list_sites(),
self.create_site(),
self.list_sites(),
self.get_site(),
self.update_site(),
self.delete_site(),
)
@ -92,15 +93,15 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_LIST_SITES,
bpr::ss::site::SUBJECT_LIST_SITES,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::ListSitesRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::site::ListSitesRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
@ -123,7 +124,34 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let search = match request.search {
Some(s) => Some(repositories::site::models::FindAllSearch {
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 conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -133,18 +161,13 @@ impl Service {
})?;
let find_all = repositories::site::models::FindAll {
url_like: None,
name_like: None,
path_like: None,
memo_like: None,
show: None,
can_use: None,
pagination: req
search,
pagination: request
.pagination
.as_ref()
.map(|d| bcr::models::pagination::Pagination::from(d)),
sorts: Some(
req
request
.sorts
.iter()
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
@ -176,12 +199,12 @@ impl Service {
message
.respond(
bpr::ss::domain::site::ListSitesResponse {
bpr::ss::site::ListSitesResponse {
error: None,
result: Some(bpr::ss::domain::site::list_sites_response::Result {
result: Some(bpr::ss::site::list_sites_response::Result {
sites: list
.iter()
.map(|d| bpr::models::domain::Site::from(d))
.map(|d| bpr::models::site::Site::from(d))
.collect(),
}),
}
@ -202,7 +225,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::ListSitesResponse {
bpr::ss::site::ListSitesResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -219,15 +242,15 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_CREATE_SITE,
bpr::ss::site::SUBJECT_CREATE_SITE,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::CreateSiteRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::site::CreateSiteRequest::decode(message.data.as_slice()).map_err(|e| {
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
message: format!("invalid request: {}", e),
})
@ -250,7 +273,23 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -259,34 +298,30 @@ impl Service {
})
})?;
let s = self
.site_repository
.insert(
&conn,
&repositories::site::models::NewSite {
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.map(|d| d as i64),
},
)
.map_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 new_site = repositories::site::models::NewSite {
url: request.url,
name: request.name,
path: request.path,
show: request.show,
can_use: request.can_use,
memo: request.memo,
expires_at: request.expires_at.map(|d| d as i64),
};
let s = self.site_repository.insert(&conn, &new_site).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::domain::site::CreateSiteResponse {
bpr::ss::site::CreateSiteResponse {
error: None,
result: Some(bpr::ss::domain::site::create_site_response::Result {
site: Some(bpr::models::domain::Site::from(&s)),
result: Some(bpr::ss::site::create_site_response::Result {
site: Some(bpr::models::site::Site::from(&s)),
}),
}
.encode_to_vec(),
@ -306,7 +341,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::CreateSiteResponse {
bpr::ss::site::CreateSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -319,37 +354,19 @@ impl Service {
Ok(())
}
async fn update_site(&self) -> Result<(), Box<dyn std::error::Error>> {
async fn get_site(&self) -> Result<(), Box<dyn std::error::Error>> {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_UPDATE_SITE,
self.queue_broker.as_str(),
)
.queue_subscribe(bpr::ss::site::SUBJECT_GET_SITE, self.queue_broker.as_str())
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
let req = bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
@ -367,6 +384,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -376,21 +422,137 @@ impl Service {
})
})?;
let s = self.site_repository.select(&conn, id).map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
message: format!("server {}", e),
data: None,
})
})?;
message
.respond(
bpr::ss::site::GetSiteResponse {
error: None,
result: Some(bpr::ss::site::get_site_response::Result {
site: s.map(|d| bpr::models::site::Site::from(&d)),
}),
}
.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::ss::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::ss::site::SUBJECT_UPDATE_SITE,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req =
bpr::ss::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 client = match req.client {
Some(c) => c,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid client information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "client".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_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 modify_site = repositories::site::models::ModifySite {
url: request.url,
name: request.name,
path: request.path,
show: request.show,
can_use: request.can_use,
memo: request.memo,
expires_at: request.expires_at.map(|d| d as i64),
};
let _affected = self
.site_repository
.update(
&conn,
id,
&repositories::site::models::ModifySite {
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.map(|d| d as i64),
},
)
.update(&conn, id, &modify_site)
.map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
code: bpr::protobuf::rpc::Error::SERVER_00,
@ -409,10 +571,10 @@ impl Service {
message
.respond(
bpr::ss::domain::site::UpdateSiteResponse {
bpr::ss::site::UpdateSiteResponse {
error: None,
result: Some(bpr::ss::domain::site::update_site_response::Result {
site: s.map(|d| bpr::models::domain::Site::from(&d)),
result: Some(bpr::ss::site::update_site_response::Result {
site: s.map(|d| bpr::models::site::Site::from(&d)),
}),
}
.encode_to_vec(),
@ -432,7 +594,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::UpdateSiteResponse {
bpr::ss::site::UpdateSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}
@ -449,33 +611,19 @@ impl Service {
let s = self
.connection_broker
.queue_subscribe(
bpr::ss::domain::site::SUBJECT_DELETE_SITE,
bpr::ss::site::SUBJECT_DELETE_SITE,
self.queue_broker.as_str(),
)
.await?;
while let Some(message) = s.next().await {
if let Err(e) = async {
let req = bpr::ss::domain::site::DeleteSiteRequest::decode(message.data.as_slice())
.map_err(|e| {
let req =
bpr::ss::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 id = uuid::Uuid::from_str(req.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: req.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let client = match req.client {
Some(c) => c,
None => {
@ -493,6 +641,35 @@ impl Service {
));
}
};
let request = match req.request {
Some(r) => r,
None => {
return Err(bcr::error::rpc::Error::InvalidParams(
bcr::error::rpc::InvalidParams {
message: "invalid request information".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "request".to_string(),
value: "".to_string(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: "".to_string(),
},
},
));
}
};
let id = uuid::Uuid::from_str(request.id.as_str()).map_err(|e| {
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
message: "invalid id param".to_string(),
detail: bcr::error::rpc::InvalidParamsDetail {
location: "request".to_string(),
param: "id".to_string(),
value: request.id.clone(),
error_type: bcr::error::rpc::InvalidParamsType::Required,
message: e.to_string(),
},
})
})?;
let conn = self.pool.get().map_err(|e| {
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
@ -512,9 +689,9 @@ impl Service {
message
.respond(
bpr::ss::domain::site::DeleteSiteResponse {
bpr::ss::site::DeleteSiteResponse {
error: None,
result: Some(bpr::ss::domain::site::delete_site_response::Result {}),
result: Some(bpr::ss::site::delete_site_response::Result {}),
}
.encode_to_vec(),
)
@ -533,7 +710,7 @@ impl Service {
{
message
.respond(
bpr::ss::domain::site::DeleteSiteResponse {
bpr::ss::site::DeleteSiteResponse {
error: Some(bpr::protobuf::rpc::Error::from(e)),
result: None,
}