member, member_bank_account are modified
This commit is contained in:
parent
2aea4f1a16
commit
629527eebf
|
@ -38,7 +38,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.72-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.56-snapshot" }
|
||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.73-snapshot" }
|
||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.57-snapshot" }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -72,11 +72,17 @@ pub struct ModifyMember {
|
|||
///
|
||||
pub member_level_id: Option<uuid::Uuid>,
|
||||
///
|
||||
pub password: Option<String>,
|
||||
///
|
||||
pub mobile_phone_number: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "members"]
|
||||
pub struct ModifyMemberForPassword {
|
||||
///
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "members"]
|
||||
|
|
|
@ -275,6 +275,21 @@ impl Repository {
|
|||
.map(|c| c as u64)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update_password(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyMemberForPassword,
|
||||
) -> 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_state(
|
||||
&self,
|
||||
|
|
|
@ -54,11 +54,17 @@ pub struct ModifyMemberBankAccount {
|
|||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub exchange_password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "member_bank_accounts"]
|
||||
pub struct ModifyMemberBankAccountForExchangePassword {
|
||||
///
|
||||
pub exchange_password: String,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FindAllSearch {
|
||||
|
|
|
@ -197,6 +197,21 @@ impl Repository {
|
|||
.map(|c| c as u64)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update_exchange_password(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyMemberBankAccountForExchangePassword,
|
||||
) -> Result<u64, Error> {
|
||||
use member_bank_accounts::dsl;
|
||||
|
||||
diesel::update(dsl::member_bank_accounts.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_accounts::dsl;
|
||||
|
|
|
@ -283,12 +283,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -70,6 +70,7 @@ impl Service<'_> {
|
|||
self.get_member(),
|
||||
self.get_member_by_username(),
|
||||
self.update_member(),
|
||||
self.update_member_for_password(),
|
||||
self.update_member_for_state(),
|
||||
self.delete_member(),
|
||||
)
|
||||
|
@ -1153,28 +1154,9 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let password_hash = match request.password {
|
||||
Some(p) => match argon2::hash_encoded(
|
||||
p.as_bytes(),
|
||||
self.password_salt.as_bytes(),
|
||||
&self.argon2_config,
|
||||
) {
|
||||
Ok(p) => Some(p),
|
||||
Err(e) => {
|
||||
return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
}));
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
let modify_member = repositories::member::models::ModifyMember {
|
||||
site_id,
|
||||
member_level_id,
|
||||
password: password_hash,
|
||||
mobile_phone_number: request.mobile_phone_number,
|
||||
};
|
||||
|
||||
|
@ -1216,25 +1198,11 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let exchange_password_hash = argon2::hash_encoded(
|
||||
a.exchange_password.as_bytes(),
|
||||
self.password_salt.as_bytes(),
|
||||
&self.argon2_config,
|
||||
)
|
||||
.map_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_account =
|
||||
repositories::member_bank_account::models::ModifyMemberBankAccount {
|
||||
bank_id,
|
||||
name: a.name,
|
||||
account_number: a.account_number,
|
||||
exchange_password: exchange_password_hash,
|
||||
memo: None,
|
||||
};
|
||||
self
|
||||
|
@ -1385,6 +1353,154 @@ impl Service<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_member_for_password(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
.queue_subscribe(
|
||||
bpr::ss::member::SUBJECT_UPDATE_MEMBER_FOR_PASSWORD,
|
||||
self.queue_broker.as_str(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
while let Some(message) = s.next().await {
|
||||
if let Err(e) = async {
|
||||
let req = bpr::ss::member::UpdateMemberForPasswordRequest::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 password_hash = match argon2::hash_encoded(
|
||||
request.password.as_bytes(),
|
||||
self.password_salt.as_bytes(),
|
||||
&self.argon2_config,
|
||||
) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(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_for_password = repositories::member::models::ModifyMemberForPassword {
|
||||
password: password_hash,
|
||||
};
|
||||
|
||||
let _affected = self
|
||||
.member_repository
|
||||
.update_password(&conn, id, &modify_member_for_password)
|
||||
.map_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 m = self.member_composition.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::UpdateMemberForPasswordResponse {
|
||||
error: None,
|
||||
result: Some(bpr::ss::member::update_member_for_password_response::Result {}),
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok::<(), bcr::error::rpc::Error>(())
|
||||
}
|
||||
.await
|
||||
{
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member::UpdateMemberForPasswordResponse {
|
||||
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||
result: None,
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_member_for_state(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
|
|
|
@ -54,6 +54,7 @@ impl Service {
|
|||
self.list_member_bank_accounts(),
|
||||
self.get_member_bank_account(),
|
||||
self.update_member_bank_account(),
|
||||
self.update_member_bank_account_for_exchange_password(),
|
||||
self.delete_member_bank_account(),
|
||||
)
|
||||
.map(|_| ())
|
||||
|
@ -363,12 +364,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
@ -661,7 +662,6 @@ impl Service {
|
|||
bank_id,
|
||||
name: request.name,
|
||||
account_number: request.account_number,
|
||||
exchange_password: request.exchange_password,
|
||||
memo: request.memo,
|
||||
},
|
||||
)
|
||||
|
@ -725,6 +725,151 @@ impl Service {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_member_bank_account_for_exchange_password(
|
||||
&self,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
.queue_subscribe(
|
||||
bpr::ss::member_bank_account::SUBJECT_UPDATE_MEMBER_BANK_ACCOUNT_FOR_EXCHANGE_PASSWORD,
|
||||
self.queue_broker.as_str(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
while let Some(message) = s.next().await {
|
||||
if let Err(e) = async {
|
||||
let req =
|
||||
bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordRequest::decode(
|
||||
message.data.as_slice(),
|
||||
)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||
message: format!("invalid request: {}", e),
|
||||
})
|
||||
})?;
|
||||
|
||||
let 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
|
||||
.update_exchange_password(
|
||||
&conn,
|
||||
id,
|
||||
&repositories::member_bank_account::models::ModifyMemberBankAccountForExchangePassword {
|
||||
exchange_password: request.exchange_password,
|
||||
},
|
||||
)
|
||||
.map_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::UpdateMemberBankAccountForExchangePasswordResponse {
|
||||
error: None,
|
||||
result: Some(
|
||||
bpr::ss::member_bank_account::update_member_bank_account_for_exchange_password_response::Result {
|
||||
},
|
||||
),
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
data: None,
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok::<(), bcr::error::rpc::Error>(())
|
||||
}
|
||||
.await
|
||||
{
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member_bank_account::UpdateMemberBankAccountForExchangePasswordResponse {
|
||||
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||
result: None,
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_member_bank_account(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
|
|
|
@ -332,12 +332,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -335,12 +335,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -299,12 +299,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -326,12 +326,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -278,12 +278,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -343,12 +343,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user