Compare commits
2 Commits
56fc4be355
...
2b2b895b7d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b2b895b7d | ||
|
|
dcc4c68abb |
@@ -19,7 +19,7 @@ use crate::util;
|
|||||||
use crate::util::req::CommonResp;
|
use crate::util::req::CommonResp;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use crate::model::req::Params;
|
use crate::model::req::GetAmountParams;
|
||||||
|
|
||||||
const PAYMENT_STORE_EXPO: i64 = 5;
|
const PAYMENT_STORE_EXPO: i64 = 5;
|
||||||
|
|
||||||
@@ -315,6 +315,7 @@ pub async fn get_transaction(
|
|||||||
pub async fn get_all_transactions(
|
pub async fn get_all_transactions(
|
||||||
State(app_state): State<crate::AppState>,
|
State(app_state): State<crate::AppState>,
|
||||||
claims: Claims,
|
claims: Claims,
|
||||||
|
Query(queryParams): Query<req::GetTransactionsQueryParams>,
|
||||||
) -> Result<Json<Vec<db_model::Transaction>>, (StatusCode, String)> {
|
) -> Result<Json<Vec<db_model::Transaction>>, (StatusCode, String)> {
|
||||||
let uid: i64 = claims.uid.clone();
|
let uid: i64 = claims.uid.clone();
|
||||||
let conn = app_state
|
let conn = app_state
|
||||||
@@ -322,10 +323,27 @@ pub async fn get_all_transactions(
|
|||||||
.get()
|
.get()
|
||||||
.await
|
.await
|
||||||
.map_err(util::req::internal_error)?;
|
.map_err(util::req::internal_error)?;
|
||||||
|
let offset = match queryParams.start {
|
||||||
|
None => {0}
|
||||||
|
Some(start) => if start > 0 {start-1} else {0}
|
||||||
|
};
|
||||||
|
let limit = match queryParams.limit {
|
||||||
|
None => {1 as i32}
|
||||||
|
Some(limit_num) => {
|
||||||
|
if(limit_num > req::MAX_QUERY_LIMIT) {
|
||||||
|
req::MAX_QUERY_LIMIT
|
||||||
|
} else if(limit_num < 1) {
|
||||||
|
1 as i32
|
||||||
|
} else {
|
||||||
|
limit_num
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
let res = conn
|
let res = conn
|
||||||
.interact(move |conn| {
|
.interact(move |conn| {
|
||||||
schema::transactions::table
|
schema::transactions::table.filter(schema::transactions::uid.eq(uid))
|
||||||
.filter(schema::transactions::uid.eq(uid))
|
.offset(offset)
|
||||||
|
.limit(limit as i64)
|
||||||
.select(db_model::Transaction::as_select())
|
.select(db_model::Transaction::as_select())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
})
|
})
|
||||||
@@ -338,7 +356,7 @@ pub async fn get_all_transactions(
|
|||||||
pub async fn get_amounts_by_tid(
|
pub async fn get_amounts_by_tid(
|
||||||
State(app_state): State<crate::AppState>,
|
State(app_state): State<crate::AppState>,
|
||||||
claims: Claims,
|
claims: Claims,
|
||||||
Query(params): Query<Params>,
|
Query(params): Query<GetAmountParams>,
|
||||||
) -> Result<Json<Vec<db_model::Amount>>, (StatusCode, String)> {
|
) -> Result<Json<Vec<db_model::Amount>>, (StatusCode, String)> {
|
||||||
info!(params.transaction_id);
|
info!(params.transaction_id);
|
||||||
let tid = match params.transaction_id {
|
let tid = match params.transaction_id {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub struct Category {
|
|||||||
level: i32,
|
level: i32,
|
||||||
parent_category_id: i64,
|
parent_category_id: i64,
|
||||||
book_id: i64,
|
book_id: i64,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -37,6 +38,7 @@ pub struct Tag {
|
|||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_tag_id: i64,
|
parent_tag_id: i64,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -59,6 +61,7 @@ pub struct Book {
|
|||||||
id: i64,
|
id: i64,
|
||||||
uid: i64,
|
uid: i64,
|
||||||
name: String,
|
name: String,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -79,6 +82,7 @@ pub struct Account {
|
|||||||
uid: i64,
|
uid: i64,
|
||||||
name: String,
|
name: String,
|
||||||
account_type: i64,
|
account_type: i64,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -102,6 +106,7 @@ pub struct Transaction {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
pub category_id: i64,
|
pub category_id: i64,
|
||||||
pub time: chrono::DateTime<Utc>,
|
pub time: chrono::DateTime<Utc>,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -129,6 +134,7 @@ pub struct Amount {
|
|||||||
value: i64,
|
value: i64,
|
||||||
expo: i64,
|
expo: i64,
|
||||||
currency: String,
|
currency: String,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -152,6 +158,7 @@ pub struct User {
|
|||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub mail: String,
|
pub mail: String,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
pub is_delete: bool,
|
pub is_delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ use std::fmt;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use serde::{de, Deserialize, Deserializer};
|
use serde::{de, Deserialize, Deserializer};
|
||||||
|
|
||||||
|
pub const QUERY_ORDER_INCREASE:i32 = 0;
|
||||||
|
pub const QUERY_ORDER_INVERT:i32 = 1;
|
||||||
|
|
||||||
|
pub const MAX_QUERY_LIMIT:i32 =1000;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Params {
|
pub struct GetAmountParams {
|
||||||
#[serde(default, deserialize_with="empty_string_as_none")]
|
#[serde(default, deserialize_with="empty_string_as_none")]
|
||||||
pub transaction_id: Option<i64>,
|
pub transaction_id: Option<i64>,
|
||||||
}
|
}
|
||||||
@@ -21,3 +27,9 @@ where
|
|||||||
Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some),
|
Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct GetTransactionsQueryParams {
|
||||||
|
pub start: Option<i64>,
|
||||||
|
pub limit: Option<i32>,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user