Compare commits
2 Commits
21a6b91139
...
56fc4be355
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56fc4be355 | ||
|
|
1ae32dd595 |
@@ -26,6 +26,7 @@ pub struct CreateCategoryResponse {
|
|||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_category_id: i64,
|
parent_category_id: i64,
|
||||||
|
book_id: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_nest_handlers() -> Router<crate::AppState> {
|
pub fn get_nest_handlers() -> Router<crate::AppState> {
|
||||||
@@ -39,6 +40,7 @@ pub struct CreateCategoryRequest {
|
|||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_category_id: i64,
|
parent_category_id: i64,
|
||||||
|
book_id: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
@@ -59,6 +61,7 @@ pub async fn create_category(
|
|||||||
uid: uid,
|
uid: uid,
|
||||||
level: payload.level,
|
level: payload.level,
|
||||||
parent_category_id: payload.parent_category_id,
|
parent_category_id: payload.parent_category_id,
|
||||||
|
book_id: payload.book_id,
|
||||||
};
|
};
|
||||||
let res = conn
|
let res = conn
|
||||||
.interact(move |conn| {
|
.interact(move |conn| {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use crate::middleware::auth::Claims;
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct CreateTagRequest {
|
pub struct CreateTagRequest {
|
||||||
|
book_id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_tag_id: i64,
|
parent_tag_id: i64,
|
||||||
@@ -30,6 +31,7 @@ pub struct CreateTagRequest {
|
|||||||
pub struct CreateTagResponse {
|
pub struct CreateTagResponse {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
|
book_id: i64,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_tag_id: i64,
|
parent_tag_id: i64,
|
||||||
}
|
}
|
||||||
@@ -53,6 +55,7 @@ pub async fn create_tag(
|
|||||||
.await
|
.await
|
||||||
.map_err(util::req::internal_error)?;
|
.map_err(util::req::internal_error)?;
|
||||||
let new_tag = db_model::TagForm {
|
let new_tag = db_model::TagForm {
|
||||||
|
book_id:payload.book_id,
|
||||||
name: payload.name,
|
name: payload.name,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
level: payload.level,
|
level: payload.level,
|
||||||
|
|||||||
@@ -19,6 +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;
|
||||||
|
|
||||||
const PAYMENT_STORE_EXPO: i64 = 5;
|
const PAYMENT_STORE_EXPO: i64 = 5;
|
||||||
|
|
||||||
@@ -176,6 +177,7 @@ pub async fn create_transaction(
|
|||||||
|
|
||||||
let amount = db_model::AmountForm {
|
let amount = db_model::AmountForm {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
|
account_id: amount_req.account_id,
|
||||||
transaction_id: 0,
|
transaction_id: 0,
|
||||||
value: value,
|
value: value,
|
||||||
expo: expo,
|
expo: expo,
|
||||||
@@ -338,5 +340,25 @@ pub async fn get_amounts_by_tid(
|
|||||||
claims: Claims,
|
claims: Claims,
|
||||||
Query(params): Query<Params>,
|
Query(params): Query<Params>,
|
||||||
) -> Result<Json<Vec<db_model::Amount>>, (StatusCode, String)> {
|
) -> Result<Json<Vec<db_model::Amount>>, (StatusCode, String)> {
|
||||||
|
info!(params.transaction_id);
|
||||||
|
let tid = match params.transaction_id {
|
||||||
|
None => 0,
|
||||||
|
Some(idx) => idx,
|
||||||
|
};
|
||||||
|
let uid: i64 = claims.uid.clone();
|
||||||
|
let conn = app_state
|
||||||
|
.db
|
||||||
|
.get()
|
||||||
|
.await
|
||||||
|
.map_err(util::req::internal_error)?;
|
||||||
|
let res = conn.interact(move |conn| {
|
||||||
|
schema::amounts::table
|
||||||
|
.filter(schema::amounts::uid.eq(uid))
|
||||||
|
.filter(schema::amounts::transaction_id.eq(tid))
|
||||||
|
.select(db_model::Amount::as_select())
|
||||||
|
.load(conn)
|
||||||
|
}).await
|
||||||
|
.map_err(util::req::internal_error)?
|
||||||
|
.map_err(util::req::internal_error)?;
|
||||||
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ pub struct Category {
|
|||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_category_id: i64,
|
parent_category_id: i64,
|
||||||
|
book_id: i64,
|
||||||
is_delete: bool,
|
is_delete: bool,
|
||||||
create_at: chrono::NaiveDateTime,
|
create_at: chrono::NaiveDateTime,
|
||||||
update_at: chrono::NaiveDateTime,
|
update_at: chrono::NaiveDateTime,
|
||||||
@@ -21,6 +22,7 @@ pub struct Category {
|
|||||||
pub struct CategoryForm {
|
pub struct CategoryForm {
|
||||||
pub uid: i64,
|
pub uid: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub book_id: i64,
|
||||||
pub level: i32,
|
pub level: i32,
|
||||||
pub parent_category_id: i64,
|
pub parent_category_id: i64,
|
||||||
}
|
}
|
||||||
@@ -31,6 +33,7 @@ pub struct CategoryForm {
|
|||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
id: i64,
|
id: i64,
|
||||||
uid: i64,
|
uid: i64,
|
||||||
|
book_id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
level: i32,
|
level: i32,
|
||||||
parent_tag_id: i64,
|
parent_tag_id: i64,
|
||||||
@@ -43,6 +46,7 @@ pub struct Tag {
|
|||||||
#[diesel(table_name = schema::tags)]
|
#[diesel(table_name = schema::tags)]
|
||||||
pub struct TagForm {
|
pub struct TagForm {
|
||||||
pub uid: i64,
|
pub uid: i64,
|
||||||
|
pub book_id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub level: i32,
|
pub level: i32,
|
||||||
pub parent_tag_id: i64,
|
pub parent_tag_id: i64,
|
||||||
@@ -120,6 +124,7 @@ pub struct TransactionForm {
|
|||||||
pub struct Amount {
|
pub struct Amount {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
uid: i64,
|
uid: i64,
|
||||||
|
account_id: i64,
|
||||||
transaction_id: i64,
|
transaction_id: i64,
|
||||||
value: i64,
|
value: i64,
|
||||||
expo: i64,
|
expo: i64,
|
||||||
@@ -134,6 +139,7 @@ pub struct Amount {
|
|||||||
pub struct AmountForm {
|
pub struct AmountForm {
|
||||||
pub uid: i64,
|
pub uid: i64,
|
||||||
pub transaction_id: i64,
|
pub transaction_id: i64,
|
||||||
|
pub account_id: i64,
|
||||||
pub value: i64,
|
pub value: i64,
|
||||||
pub expo: i64,
|
pub expo: i64,
|
||||||
pub currency: String,
|
pub currency: String,
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
|
use std::fmt;
|
||||||
|
use std::str::FromStr;
|
||||||
use serde::{de, Deserialize, Deserializer};
|
use serde::{de, Deserialize, Deserializer};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
#[serde(default, deserialize_with="empty_string_as_none")]
|
#[serde(default, deserialize_with="empty_string_as_none")]
|
||||||
transaction_id: Option<i64>,
|
pub transaction_id: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Serde deserialization decorator to map empty Strings to None,
|
||||||
|
fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
T: FromStr,
|
||||||
|
T::Err: fmt::Display,
|
||||||
|
{
|
||||||
|
let opt = Option::<String>::deserialize(de)?;
|
||||||
|
match opt.as_deref() {
|
||||||
|
None | Some("") => Ok(None),
|
||||||
|
Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ diesel::table! {
|
|||||||
amounts (id) {
|
amounts (id) {
|
||||||
id -> Int8,
|
id -> Int8,
|
||||||
uid -> Int8,
|
uid -> Int8,
|
||||||
|
account_id -> Int8,
|
||||||
transaction_id -> Int8,
|
transaction_id -> Int8,
|
||||||
value -> Int8,
|
value -> Int8,
|
||||||
expo -> Int8,
|
expo -> Int8,
|
||||||
@@ -41,6 +42,7 @@ diesel::table! {
|
|||||||
categories (id) {
|
categories (id) {
|
||||||
id -> Int8,
|
id -> Int8,
|
||||||
uid -> Int8,
|
uid -> Int8,
|
||||||
|
book_id -> Int8,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
level -> Int4,
|
level -> Int4,
|
||||||
parent_category_id -> Int8,
|
parent_category_id -> Int8,
|
||||||
@@ -54,6 +56,7 @@ diesel::table! {
|
|||||||
tags (id) {
|
tags (id) {
|
||||||
id -> Int8,
|
id -> Int8,
|
||||||
uid -> Int8,
|
uid -> Int8,
|
||||||
|
book_id -> Int8,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
level -> Int4,
|
level -> Int4,
|
||||||
parent_tag_id -> Int8,
|
parent_tag_id -> Int8,
|
||||||
|
|||||||
Reference in New Issue
Block a user