Added the capability to upload CSV files
This commit is contained in:
parent
90b02eef79
commit
d1e736d7a7
19 changed files with 678 additions and 99 deletions
|
|
@ -6,7 +6,7 @@ use hyper::StatusCode;
|
|||
use serde::Deserialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use accounters::models::Transaction;
|
||||
use accounters::models::{transaction::TxConflictResolutionMode, Transaction};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TransactionContent {
|
||||
|
|
@ -14,6 +14,8 @@ pub struct TransactionContent {
|
|||
timestamp: DateTime<Utc>,
|
||||
category: Option<String>,
|
||||
amount: i32,
|
||||
#[serde(default)]
|
||||
error_on_conflict: Option<bool>,
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
|
|
@ -21,6 +23,11 @@ pub async fn create(
|
|||
Path(account): Path<i32>,
|
||||
Json(txcnt): Json<TransactionContent>,
|
||||
) -> (StatusCode, String) {
|
||||
let error_on_conflict = if txcnt.error_on_conflict.is_some_and(|x| x) {
|
||||
TxConflictResolutionMode::Error
|
||||
} else {
|
||||
TxConflictResolutionMode::Nothing
|
||||
};
|
||||
match Transaction::new(
|
||||
db.as_ref(),
|
||||
account,
|
||||
|
|
@ -28,6 +35,7 @@ pub async fn create(
|
|||
&txcnt.timestamp,
|
||||
None,
|
||||
txcnt.amount,
|
||||
error_on_conflict,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue