bank repositories are added
This commit is contained in:
parent
2e051c3673
commit
b9072233cb
4
migrations/202207011000_bank/down.sql
Normal file
4
migrations/202207011000_bank/down.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
DROP UNIQUE INDEX uidx_banks_url;
|
||||
DROP TRIGGER tg_banks_updated_at;
|
||||
DROP TABLE banks;
|
||||
|
20
migrations/202207011000_bank/up.sql
Normal file
20
migrations/202207011000_bank/up.sql
Normal file
|
@ -0,0 +1,20 @@
|
|||
CREATE TABLE IF NOT EXISTS banks (
|
||||
id UUID DEFAULT uuid_generate_v4(),
|
||||
name TEXT,
|
||||
show BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
can_use BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
memo TEXT,
|
||||
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),
|
||||
UNIQUE (url)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX uidx_banks_url ON banks (url);
|
||||
|
||||
-- trigger (updated_at)
|
||||
CREATE TRIGGER tg_banks_updated_at
|
||||
BEFORE UPDATE
|
||||
ON banks
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_updated_at_column();
|
3
migrations/202207011100_member_bank_account/down.sql
Normal file
3
migrations/202207011100_member_bank_account/down.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
DROP INDEX idx_member_bank_accounts_member_id;
|
||||
DROP TRIGGER tg_member_bank_accounts_updated_at;
|
||||
DROP TABLE member_bank_accounts;
|
27
migrations/202207011100_member_bank_account/up.sql
Normal file
27
migrations/202207011100_member_bank_account/up.sql
Normal file
|
@ -0,0 +1,27 @@
|
|||
CREATE TABLE IF NOT EXISTS member_bank_accounts (
|
||||
id UUID DEFAULT uuid_generate_v4(),
|
||||
member_id UUID NOT NULL,
|
||||
bank_id UUID NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
account_number TEXT NOT NULL,
|
||||
memo TEXT,
|
||||
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),
|
||||
CONSTRAINT fk_member_bank_accounts_member_id
|
||||
FOREIGN KEY(member_id)
|
||||
REFERENCES members(id),
|
||||
CONSTRAINT fk_member_bank_accounts_bank_id
|
||||
FOREIGN KEY(bank_id)
|
||||
REFERENCES banks(id)
|
||||
|
||||
);
|
||||
|
||||
CREATE INDEX idx_member_bank_accounts_member_id ON member_bank_accounts (member_id);
|
||||
|
||||
-- trigger (updated_at)
|
||||
CREATE TRIGGER tg_member_bank_accounts_updated_at
|
||||
BEFORE UPDATE
|
||||
ON member_bank_accounts
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_updated_at_column();
|
4
migrations/202207011110_member_bank_deposit/down.sql
Normal file
4
migrations/202207011110_member_bank_deposit/down.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
DROP INDEX idx_member_bank_deposits_member_id;
|
||||
DROP TRIGGER tg_member_bank_deposits_updated_at;
|
||||
DROP TRIGGER tg_member_bank_deposits_state_changed_at;
|
||||
DROP TABLE member_bank_deposits;
|
35
migrations/202207011110_member_bank_deposit/up.sql
Normal file
35
migrations/202207011110_member_bank_deposit/up.sql
Normal file
|
@ -0,0 +1,35 @@
|
|||
CREATE TYPE member_bank_deposit_state AS ENUM ('application', 'complete');
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS member_bank_deposits (
|
||||
id UUID DEFAULT uuid_generate_v4(),
|
||||
member_id UUID NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
memo TEXT,
|
||||
state MEMBER_BANK_DEPOSIT_STATE DEFAULT 'application',
|
||||
state_changed_at BIGINT,
|
||||
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),
|
||||
CONSTRAINT fk_member_bank_deposits_member_id
|
||||
FOREIGN KEY(member_id)
|
||||
REFERENCES members(id)
|
||||
|
||||
);
|
||||
|
||||
CREATE INDEX idx_member_bank_deposits_member_id ON member_bank_deposits (member_id);
|
||||
|
||||
-- trigger (updated_at)
|
||||
CREATE TRIGGER tg_member_bank_deposits_updated_at
|
||||
BEFORE UPDATE
|
||||
ON member_bank_deposits
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_updated_at_column();
|
||||
|
||||
-- trigger (state_changed_at)
|
||||
CREATE TRIGGER tg_member_bank_deposits_state_changed_at
|
||||
BEFORE UPDATE
|
||||
ON member_bank_deposits
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_state_changed_at_column();
|
4
migrations/202207011120_member_bank_withdraw/down.sql
Normal file
4
migrations/202207011120_member_bank_withdraw/down.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
DROP INDEX idx_member_bank_withdraws_member_id;
|
||||
DROP TRIGGER tg_member_bank_withdraws_updated_at;
|
||||
DROP TRIGGER tg_member_bank_withdraws_state_changed_at;
|
||||
DROP TABLE member_bank_withdraws;
|
38
migrations/202207011120_member_bank_withdraw/up.sql
Normal file
38
migrations/202207011120_member_bank_withdraw/up.sql
Normal file
|
@ -0,0 +1,38 @@
|
|||
CREATE TYPE member_bank_withdraw_state AS ENUM ('application', 'complete');
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS member_bank_withdraws (
|
||||
id UUID DEFAULT uuid_generate_v4(),
|
||||
member_id UUID NOT NULL,
|
||||
bank_name TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
account_number TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
memo TEXT,
|
||||
state MEMBER_BANK_WITHDRAW_STATE DEFAULT 'application',
|
||||
state_changed_at BIGINT,
|
||||
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),
|
||||
CONSTRAINT fk_member_bank_withdraws_member_id
|
||||
FOREIGN KEY(member_id)
|
||||
REFERENCES members(id)
|
||||
|
||||
);
|
||||
|
||||
CREATE INDEX idx_member_bank_withdraws_member_id ON member_bank_withdraws (member_id);
|
||||
|
||||
-- trigger (updated_at)
|
||||
CREATE TRIGGER tg_member_bank_withdraws_updated_at
|
||||
BEFORE UPDATE
|
||||
ON member_bank_withdraws
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_updated_at_column();
|
||||
|
||||
-- trigger (state_changed_at)
|
||||
CREATE TRIGGER tg_member_bank_withdraws_state_changed_at
|
||||
BEFORE UPDATE
|
||||
ON member_bank_withdraws
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_state_changed_at_column();
|
9
src/repositories/bank/mod.rs
Normal file
9
src/repositories/bank/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
||||
///
|
||||
pub mod schema;
|
67
src/repositories/bank/models.rs
Normal file
67
src/repositories/bank/models.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use super::schema::banks;
|
||||
use beteran_common_rust as bcr;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Identifiable, Queryable, PartialEq, Debug, Clone)]
|
||||
#[table_name = "banks"]
|
||||
pub struct Bank {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub name: Option<String>,
|
||||
///
|
||||
pub show: bool,
|
||||
///
|
||||
pub can_use: bool,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Insertable, Debug, Clone)]
|
||||
#[table_name = "banks"]
|
||||
pub struct NewBank {
|
||||
///
|
||||
pub name: Option<String>,
|
||||
///
|
||||
pub show: bool,
|
||||
///
|
||||
pub can_use: bool,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "banks"]
|
||||
pub struct ModifyBank {
|
||||
///
|
||||
pub name: Option<String>,
|
||||
///
|
||||
pub show: bool,
|
||||
///
|
||||
pub can_use: bool,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FindAll {
|
||||
///
|
||||
pub name_like: Option<String>,
|
||||
///
|
||||
pub show: Option<bool>,
|
||||
///
|
||||
pub can_use: Option<bool>,
|
||||
///
|
||||
pub memo_like: Option<String>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
}
|
167
src/repositories/bank/repository.rs
Normal file
167
src/repositories/bank/repository.rs
Normal file
|
@ -0,0 +1,167 @@
|
|||
//!
|
||||
//!
|
||||
use super::{models, schema::banks};
|
||||
use beteran_common_rust as bcr;
|
||||
use diesel::prelude::*;
|
||||
use diesel::result::Error;
|
||||
|
||||
///
|
||||
pub struct Repository {}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of banks").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Repository {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new() -> Repository {
|
||||
Repository {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn insert(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_member: &models::NewBank,
|
||||
) -> Result<models::Bank, Error> {
|
||||
let inserted = diesel::insert_into(banks::table)
|
||||
.values(new_member)
|
||||
.get_result::<models::Bank>(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<Option<models::Bank>, Error> {
|
||||
match banks::table.find(id).first::<models::Bank>(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,
|
||||
) -> 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));
|
||||
}
|
||||
|
||||
q.count().get_result(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
find_all: &models::FindAll,
|
||||
) -> 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(p) = &find_all.pagination {
|
||||
let page = p.page.unwrap_or(1);
|
||||
|
||||
if let Some(page_size) = p.page_size {
|
||||
q = q.offset(((page - 1) * page_size) as i64);
|
||||
q = q.limit(page_size as i64);
|
||||
}
|
||||
}
|
||||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(banks::name.asc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(banks::created_at.asc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(banks::updated_at.asc());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(banks::name.desc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(banks::created_at.desc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(banks::updated_at.desc());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
q.load::<models::Bank>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyBank,
|
||||
) -> Result<u64, Error> {
|
||||
use banks::dsl;
|
||||
|
||||
diesel::update(dsl::banks.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 banks::dsl;
|
||||
|
||||
diesel::delete(banks::table.filter(dsl::id.eq(id)))
|
||||
.execute(conn)
|
||||
.map(|c| c as u64)
|
||||
}
|
||||
}
|
22
src/repositories/bank/schema.rs
Normal file
22
src/repositories/bank/schema.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
table! {
|
||||
///
|
||||
banks(id) {
|
||||
///
|
||||
id -> Uuid,
|
||||
///
|
||||
name -> Nullable<Text>,
|
||||
///
|
||||
show -> Bool,
|
||||
///
|
||||
can_use -> Bool,
|
||||
///
|
||||
memo -> Nullable<Text>,
|
||||
///
|
||||
created_at -> BigInt,
|
||||
///
|
||||
updated_at -> BigInt,
|
||||
}
|
||||
}
|
9
src/repositories/member_bank_account/mod.rs
Normal file
9
src/repositories/member_bank_account/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
||||
///
|
||||
pub mod schema;
|
73
src/repositories/member_bank_account/models.rs
Normal file
73
src/repositories/member_bank_account/models.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
use super::schema::member_bank_accounts;
|
||||
use beteran_common_rust as bcr;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Identifiable, Queryable, PartialEq, Debug, Clone)]
|
||||
#[table_name = "member_bank_accounts"]
|
||||
pub struct MemberBankAccount {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub bank_id: uuid::Uuid,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Insertable, Debug, Clone)]
|
||||
#[table_name = "member_bank_accounts"]
|
||||
pub struct NewMemberBankAccount {
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub bank_id: uuid::Uuid,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "member_bank_accounts"]
|
||||
pub struct ModifyMemberBankAccount {
|
||||
///
|
||||
pub bank_id: uuid::Uuid,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FindAll {
|
||||
///
|
||||
pub member_id: Option<uuid::Uuid>,
|
||||
///
|
||||
pub bank_id: Option<uuid::Uuid>,
|
||||
///
|
||||
pub name_like: Option<String>,
|
||||
///
|
||||
pub account_number_like: Option<String>,
|
||||
///
|
||||
pub memo_like: Option<String>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
}
|
168
src/repositories/member_bank_account/repository.rs
Normal file
168
src/repositories/member_bank_account/repository.rs
Normal file
|
@ -0,0 +1,168 @@
|
|||
//!
|
||||
//!
|
||||
use super::{models, schema::member_bank_accounts};
|
||||
use beteran_common_rust as bcr;
|
||||
use diesel::prelude::*;
|
||||
use diesel::result::Error;
|
||||
|
||||
///
|
||||
pub struct Repository {}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of member_bank_accounts")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Repository {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new() -> Repository {
|
||||
Repository {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn insert(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_resource: &models::NewMemberBankAccount,
|
||||
) -> Result<models::MemberBankAccount, Error> {
|
||||
let inserted = diesel::insert_into(member_bank_accounts::table)
|
||||
.values(new_resource)
|
||||
.get_result::<models::MemberBankAccount>(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<models::MemberBankAccount, Error> {
|
||||
member_bank_accounts::table
|
||||
.find(id as uuid::Uuid)
|
||||
.first::<models::MemberBankAccount>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all_count(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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));
|
||||
}
|
||||
|
||||
q.count().get_result(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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(p) = find_all.pagination {
|
||||
let page = p.page.unwrap_or(1);
|
||||
|
||||
if let Some(page_size) = p.page_size {
|
||||
q = q.offset(((page - 1) * page_size) as i64);
|
||||
q = q.limit(page_size as i64);
|
||||
}
|
||||
}
|
||||
if let Some(orderbys) = find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_accounts::name.asc());
|
||||
}
|
||||
"account_number" => {
|
||||
q = q.order_by(member_bank_accounts::account_number.asc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_accounts::created_at.asc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_accounts::updated_at.asc());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_accounts::name.desc());
|
||||
}
|
||||
"account_number" => {
|
||||
q = q.order_by(member_bank_accounts::account_number.desc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_accounts::created_at.desc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_accounts::updated_at.desc());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
q.load::<models::MemberBankAccount>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyMemberBankAccount,
|
||||
) -> 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)
|
||||
}
|
||||
}
|
24
src/repositories/member_bank_account/schema.rs
Normal file
24
src/repositories/member_bank_account/schema.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
table! {
|
||||
///
|
||||
member_bank_accounts(id) {
|
||||
///
|
||||
id -> Uuid,
|
||||
///
|
||||
member_id -> Uuid,
|
||||
///
|
||||
bank_id -> Uuid,
|
||||
///
|
||||
name -> Text,
|
||||
///
|
||||
account_number -> Text,
|
||||
///
|
||||
memo -> Nullable<Text>,
|
||||
///
|
||||
created_at -> BigInt,
|
||||
///
|
||||
updated_at -> BigInt,
|
||||
}
|
||||
}
|
9
src/repositories/member_bank_deposit/mod.rs
Normal file
9
src/repositories/member_bank_deposit/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
||||
///
|
||||
pub mod schema;
|
73
src/repositories/member_bank_deposit/models.rs
Normal file
73
src/repositories/member_bank_deposit/models.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
use super::schema::{member_bank_deposits, MemberBankDepositState};
|
||||
use beteran_common_rust as bcr;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Identifiable, Queryable, PartialEq, Debug, Clone)]
|
||||
#[table_name = "member_bank_deposits"]
|
||||
pub struct MemberBankDeposit {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub state: MemberBankDepositState,
|
||||
///
|
||||
pub state_changed_at: Option<i64>,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Insertable, Debug, Clone)]
|
||||
#[table_name = "member_bank_deposits"]
|
||||
pub struct NewMemberBankDeposit {
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "member_bank_deposits"]
|
||||
pub struct ModifyMemberBankDeposit {
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub state: Option<MemberBankDepositState>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FindAll {
|
||||
///
|
||||
pub member_id: Option<uuid::Uuid>,
|
||||
///
|
||||
pub name_like: Option<String>,
|
||||
///
|
||||
pub amount: Option<i32>,
|
||||
///
|
||||
pub memo_like: Option<String>,
|
||||
///
|
||||
pub state: Option<MemberBankDepositState>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
}
|
174
src/repositories/member_bank_deposit/repository.rs
Normal file
174
src/repositories/member_bank_deposit/repository.rs
Normal file
|
@ -0,0 +1,174 @@
|
|||
//!
|
||||
//!
|
||||
use super::{models, schema::member_bank_deposits};
|
||||
use beteran_common_rust as bcr;
|
||||
use diesel::prelude::*;
|
||||
use diesel::result::Error;
|
||||
|
||||
///
|
||||
pub struct Repository {}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of member_bank_deposits")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Repository {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new() -> Repository {
|
||||
Repository {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn insert(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_resource: &models::NewMemberBankDeposit,
|
||||
) -> Result<models::MemberBankDeposit, Error> {
|
||||
let inserted = diesel::insert_into(member_bank_deposits::table)
|
||||
.values(new_resource)
|
||||
.get_result::<models::MemberBankDeposit>(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<models::MemberBankDeposit, Error> {
|
||||
member_bank_deposits::table
|
||||
.find(id as uuid::Uuid)
|
||||
.first::<models::MemberBankDeposit>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all_count(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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));
|
||||
}
|
||||
|
||||
q.count().get_result(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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(p) = find_all.pagination {
|
||||
let page = p.page.unwrap_or(1);
|
||||
|
||||
if let Some(page_size) = p.page_size {
|
||||
q = q.offset(((page - 1) * page_size) as i64);
|
||||
q = q.limit(page_size as i64);
|
||||
}
|
||||
}
|
||||
if let Some(orderbys) = find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_deposits::name.asc());
|
||||
}
|
||||
"amount" => {
|
||||
q = q.order_by(member_bank_deposits::amount.asc());
|
||||
}
|
||||
"state" => {
|
||||
q = q.order_by(member_bank_deposits::state.asc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_deposits::created_at.asc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_deposits::updated_at.asc());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_deposits::name.desc());
|
||||
}
|
||||
"amount" => {
|
||||
q = q.order_by(member_bank_deposits::amount.desc());
|
||||
}
|
||||
"state" => {
|
||||
q = q.order_by(member_bank_deposits::state.desc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_deposits::created_at.desc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_deposits::updated_at.desc());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
q.load::<models::MemberBankDeposit>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyMemberBankDeposit,
|
||||
) -> 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)
|
||||
}
|
||||
}
|
36
src/repositories/member_bank_deposit/schema.rs
Normal file
36
src/repositories/member_bank_deposit/schema.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Debug, Clone, Copy, PartialEq, diesel_derive_enum::DbEnum)]
|
||||
pub enum MemberBankDepositState {
|
||||
Application,
|
||||
Complete,
|
||||
}
|
||||
|
||||
table! {
|
||||
use diesel::sql_types::{Uuid, Text, BigInt, Nullable, Integer};
|
||||
use super::MemberBankDepositStateMapping;
|
||||
|
||||
///
|
||||
member_bank_deposits(id) {
|
||||
///
|
||||
id -> Uuid,
|
||||
///
|
||||
member_id -> Uuid,
|
||||
///
|
||||
name -> Text,
|
||||
///
|
||||
amount -> Integer,
|
||||
///
|
||||
state -> MemberBankDepositStateMapping,
|
||||
///
|
||||
state_changed_at -> Nullable<BigInt>,
|
||||
///
|
||||
memo -> Nullable<Text>,
|
||||
///
|
||||
created_at -> BigInt,
|
||||
///
|
||||
updated_at -> BigInt,
|
||||
}
|
||||
}
|
9
src/repositories/member_bank_withdraw/mod.rs
Normal file
9
src/repositories/member_bank_withdraw/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
||||
///
|
||||
pub mod schema;
|
95
src/repositories/member_bank_withdraw/models.rs
Normal file
95
src/repositories/member_bank_withdraw/models.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
use super::schema::{member_bank_withdraws, MemberBankWithdrawState};
|
||||
use beteran_common_rust as bcr;
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Identifiable, Queryable, PartialEq, Debug, Clone)]
|
||||
#[table_name = "member_bank_withdraws"]
|
||||
pub struct MemberBankWithdraw {
|
||||
///
|
||||
pub id: uuid::Uuid,
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub bank_name: String,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub password: String,
|
||||
///
|
||||
pub state: MemberBankWithdrawState,
|
||||
///
|
||||
pub state_changed_at: Option<i64>,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub created_at: i64,
|
||||
///
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Insertable, Debug, Clone)]
|
||||
#[table_name = "member_bank_withdraws"]
|
||||
pub struct NewMemberBankWithdraw {
|
||||
///
|
||||
pub member_id: uuid::Uuid,
|
||||
///
|
||||
pub bank_name: String,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(AsChangeset, Debug, Clone)]
|
||||
#[table_name = "member_bank_withdraws"]
|
||||
pub struct ModifyMemberBankWithdraw {
|
||||
///
|
||||
pub bank_name: String,
|
||||
///
|
||||
pub name: String,
|
||||
///
|
||||
pub account_number: String,
|
||||
///
|
||||
pub amount: i32,
|
||||
///
|
||||
pub password: String,
|
||||
///
|
||||
pub memo: Option<String>,
|
||||
///
|
||||
pub state: Option<MemberBankWithdrawState>,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FindAll {
|
||||
///
|
||||
pub member_id: Option<uuid::Uuid>,
|
||||
///
|
||||
pub bank_name_like: Option<String>,
|
||||
///
|
||||
pub name_like: Option<String>,
|
||||
///
|
||||
pub account_number_like: Option<String>,
|
||||
///
|
||||
pub amount: Option<i32>,
|
||||
///
|
||||
pub memo_like: Option<String>,
|
||||
///
|
||||
pub state: Option<MemberBankWithdrawState>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
}
|
204
src/repositories/member_bank_withdraw/repository.rs
Normal file
204
src/repositories/member_bank_withdraw/repository.rs
Normal file
|
@ -0,0 +1,204 @@
|
|||
//!
|
||||
//!
|
||||
use super::{models, schema::member_bank_withdraws};
|
||||
use beteran_common_rust as bcr;
|
||||
use diesel::prelude::*;
|
||||
use diesel::result::Error;
|
||||
|
||||
///
|
||||
pub struct Repository {}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of member_bank_withdraws")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Repository {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new() -> Repository {
|
||||
Repository {}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn insert(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
new_resource: &models::NewMemberBankWithdraw,
|
||||
) -> Result<models::MemberBankWithdraw, Error> {
|
||||
let inserted = diesel::insert_into(member_bank_withdraws::table)
|
||||
.values(new_resource)
|
||||
.get_result::<models::MemberBankWithdraw>(conn)?;
|
||||
|
||||
Ok(inserted)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
) -> Result<models::MemberBankWithdraw, Error> {
|
||||
member_bank_withdraws::table
|
||||
.find(id as uuid::Uuid)
|
||||
.first::<models::MemberBankWithdraw>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all_count(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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));
|
||||
}
|
||||
|
||||
q.count().get_result(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn select_all(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
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(p) = find_all.pagination {
|
||||
let page = p.page.unwrap_or(1);
|
||||
|
||||
if let Some(page_size) = p.page_size {
|
||||
q = q.offset(((page - 1) * page_size) as i64);
|
||||
q = q.limit(page_size as i64);
|
||||
}
|
||||
}
|
||||
if let Some(orderbys) = find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_bank_withdraws::member_id.asc());
|
||||
}
|
||||
"bank_name" => {
|
||||
q = q.order_by(member_bank_withdraws::bank_name.asc());
|
||||
}
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_withdraws::name.asc());
|
||||
}
|
||||
"account_number" => {
|
||||
q = q.order_by(member_bank_withdraws::account_number.asc());
|
||||
}
|
||||
"amount" => {
|
||||
q = q.order_by(member_bank_withdraws::amount.asc());
|
||||
}
|
||||
"state" => {
|
||||
q = q.order_by(member_bank_withdraws::state.asc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_withdraws::created_at.asc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_withdraws::updated_at.asc());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_bank_withdraws::member_id.desc());
|
||||
}
|
||||
"bank_name" => {
|
||||
q = q.order_by(member_bank_withdraws::bank_name.desc());
|
||||
}
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_withdraws::name.desc());
|
||||
}
|
||||
"account_number" => {
|
||||
q = q.order_by(member_bank_withdraws::account_number.desc());
|
||||
}
|
||||
"amount" => {
|
||||
q = q.order_by(member_bank_withdraws::amount.desc());
|
||||
}
|
||||
"state" => {
|
||||
q = q.order_by(member_bank_withdraws::state.desc());
|
||||
}
|
||||
"created_at" => {
|
||||
q = q.order_by(member_bank_withdraws::created_at.desc());
|
||||
}
|
||||
"updated_at" => {
|
||||
q = q.order_by(member_bank_withdraws::updated_at.desc());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
q.load::<models::MemberBankWithdraw>(conn)
|
||||
}
|
||||
|
||||
///
|
||||
pub fn update(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
id: uuid::Uuid,
|
||||
modify: &models::ModifyMemberBankWithdraw,
|
||||
) -> 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)
|
||||
}
|
||||
}
|
42
src/repositories/member_bank_withdraw/schema.rs
Normal file
42
src/repositories/member_bank_withdraw/schema.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
#[derive(Eq, Hash, Debug, Clone, Copy, PartialEq, diesel_derive_enum::DbEnum)]
|
||||
pub enum MemberBankWithdrawState {
|
||||
Application,
|
||||
Complete,
|
||||
}
|
||||
|
||||
table! {
|
||||
use diesel::sql_types::{Uuid, Text, BigInt, Nullable, Integer};
|
||||
use super::MemberBankWithdrawStateMapping;
|
||||
|
||||
///
|
||||
member_bank_withdraws(id) {
|
||||
///
|
||||
id -> Uuid,
|
||||
///
|
||||
member_id -> Uuid,
|
||||
///
|
||||
bank_name -> Text,
|
||||
///
|
||||
name -> Text,
|
||||
///
|
||||
account_number -> Text,
|
||||
///
|
||||
amount -> Integer,
|
||||
///
|
||||
password -> Text,
|
||||
///
|
||||
state -> MemberBankWithdrawStateMapping,
|
||||
///
|
||||
state_changed_at -> Nullable<BigInt>,
|
||||
///
|
||||
memo -> Nullable<Text>,
|
||||
///
|
||||
created_at -> BigInt,
|
||||
///
|
||||
updated_at -> BigInt,
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
pub mod bank;
|
||||
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 member_permission;
|
||||
|
|
|
@ -86,7 +86,7 @@ impl Repository {
|
|||
q = q.filter(sites::dsl::url.like(sp));
|
||||
}
|
||||
if let Some(sp) = &find_all.name_like {
|
||||
q = q.filter(sites::dsl::url.like(sp));
|
||||
q = q.filter(sites::dsl::name.like(sp));
|
||||
}
|
||||
if let Some(sp) = &find_all.path_like {
|
||||
q = q.filter(sites::dsl::path.like(sp));
|
||||
|
@ -116,7 +116,7 @@ impl Repository {
|
|||
q = q.filter(sites::dsl::url.like(sp));
|
||||
}
|
||||
if let Some(sp) = &find_all.name_like {
|
||||
q = q.filter(sites::dsl::url.like(sp));
|
||||
q = q.filter(sites::dsl::name.like(sp));
|
||||
}
|
||||
if let Some(sp) = &find_all.path_like {
|
||||
q = q.filter(sites::dsl::path.like(sp));
|
||||
|
@ -147,10 +147,10 @@ impl Repository {
|
|||
q = q.order_by(sites::url.asc());
|
||||
}
|
||||
"name" => {
|
||||
q = q.order_by(sites::url.asc());
|
||||
q = q.order_by(sites::name.asc());
|
||||
}
|
||||
"path" => {
|
||||
q = q.order_by(sites::url.asc());
|
||||
q = q.order_by(sites::path.asc());
|
||||
}
|
||||
"expires_at" => {
|
||||
q = q.order_by(sites::expires_at.asc());
|
||||
|
@ -168,10 +168,10 @@ impl Repository {
|
|||
q = q.order_by(sites::url.desc());
|
||||
}
|
||||
"name" => {
|
||||
q = q.order_by(sites::url.desc());
|
||||
q = q.order_by(sites::name.desc());
|
||||
}
|
||||
"path" => {
|
||||
q = q.order_by(sites::url.desc());
|
||||
q = q.order_by(sites::path.desc());
|
||||
}
|
||||
"expires_at" => {
|
||||
q = q.order_by(sites::expires_at.desc());
|
||||
|
|
Loading…
Reference in New Issue
Block a user