Refactored src and dst account to just account in preparation for a "counter party", instead of a full account.
This commit is contained in:
@@ -4,10 +4,9 @@ use uuid::Uuid;
|
||||
pub struct RecurringTransactionRow {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub account_id: Uuid,
|
||||
pub amount_cents: i64,
|
||||
pub direction: String,
|
||||
pub source_account_id: Option<Uuid>,
|
||||
pub destination_account_id: Option<Uuid>,
|
||||
pub starts_at: DateTime<Utc>,
|
||||
pub ends_at: Option<DateTime<Utc>>,
|
||||
pub recurrence_every: i32,
|
||||
|
||||
@@ -3,8 +3,9 @@ use uuid::Uuid;
|
||||
|
||||
pub struct TransactionRow {
|
||||
pub id: Uuid,
|
||||
pub description: String,
|
||||
pub account_id: Uuid,
|
||||
pub amount_cents: i64,
|
||||
pub direction: String,
|
||||
pub date: DateTime<Utc>,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
@@ -32,10 +32,9 @@ where
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
account_id,
|
||||
amount_cents,
|
||||
direction,
|
||||
source_account_id,
|
||||
destination_account_id,
|
||||
starts_at,
|
||||
ends_at,
|
||||
recurrence_every,
|
||||
@@ -66,10 +65,9 @@ where
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
account_id,
|
||||
amount_cents,
|
||||
direction,
|
||||
source_account_id,
|
||||
destination_account_id,
|
||||
starts_at,
|
||||
ends_at,
|
||||
recurrence_every,
|
||||
@@ -97,23 +95,21 @@ where
|
||||
INSERT INTO recurring_transactions (
|
||||
id,
|
||||
name,
|
||||
account_id,
|
||||
amount_cents,
|
||||
direction,
|
||||
source_account_id,
|
||||
destination_account_id,
|
||||
starts_at,
|
||||
ends_at,
|
||||
recurrence_every,
|
||||
recurrence_unit,
|
||||
weekend_adjustment
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
account_id = EXCLUDED.account_id,
|
||||
amount_cents = EXCLUDED.amount_cents,
|
||||
direction = EXCLUDED.direction,
|
||||
source_account_id = EXCLUDED.source_account_id,
|
||||
destination_account_id = EXCLUDED.destination_account_id,
|
||||
starts_at = EXCLUDED.starts_at,
|
||||
ends_at = EXCLUDED.ends_at,
|
||||
recurrence_every = EXCLUDED.recurrence_every,
|
||||
@@ -123,10 +119,9 @@ where
|
||||
old_row.id AS "old_id?",
|
||||
new_row.id AS "id!",
|
||||
new_row.name AS "name!",
|
||||
new_row.account_id AS "account_id!",
|
||||
new_row.amount_cents AS "amount_cents!",
|
||||
new_row.direction AS "direction!",
|
||||
new_row.source_account_id AS "source_account_id?",
|
||||
new_row.destination_account_id AS "destination_account_id?",
|
||||
new_row.starts_at AS "starts_at!",
|
||||
new_row.ends_at AS "ends_at?",
|
||||
new_row.recurrence_every AS "recurrence_every!",
|
||||
@@ -135,10 +130,9 @@ where
|
||||
"#,
|
||||
transaction.id,
|
||||
transaction.name,
|
||||
transaction.account_id,
|
||||
transaction.amount_cents,
|
||||
transaction.direction,
|
||||
transaction.source_account_id,
|
||||
transaction.destination_account_id,
|
||||
transaction.starts_at,
|
||||
transaction.ends_at,
|
||||
transaction.recurrence_every,
|
||||
@@ -152,10 +146,9 @@ where
|
||||
let transaction = RecurringTransactionRow {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
account_id: row.account_id,
|
||||
amount_cents: row.amount_cents,
|
||||
direction: row.direction,
|
||||
source_account_id: row.source_account_id,
|
||||
destination_account_id: row.destination_account_id,
|
||||
starts_at: row.starts_at,
|
||||
ends_at: row.ends_at,
|
||||
recurrence_every: row.recurrence_every,
|
||||
|
||||
@@ -26,7 +26,7 @@ where
|
||||
sqlx::query_as!(
|
||||
TransactionRow,
|
||||
r#"
|
||||
SELECT id, description, amount_cents, direction, date
|
||||
SELECT id, account_id, amount_cents, direction, date, description
|
||||
FROM transactions
|
||||
ORDER BY date DESC, id DESC
|
||||
LIMIT $1
|
||||
@@ -50,7 +50,7 @@ where
|
||||
sqlx::query_as!(
|
||||
TransactionRow,
|
||||
r#"
|
||||
SELECT id, description, amount_cents, direction, date
|
||||
SELECT id, account_id, amount_cents, direction, date, description
|
||||
FROM transactions
|
||||
WHERE id = $1
|
||||
"#,
|
||||
@@ -70,26 +70,29 @@ where
|
||||
{
|
||||
let row = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO transactions (id, description, amount_cents, direction, date)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO transactions (id, account_id, amount_cents, direction, date, description)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
description = EXCLUDED.description,
|
||||
account_id = EXCLUDED.account_id,
|
||||
amount_cents = EXCLUDED.amount_cents,
|
||||
direction = EXCLUDED.direction,
|
||||
date = EXCLUDED.date
|
||||
date = EXCLUDED.date,
|
||||
description = EXCLUDED.description
|
||||
RETURNING WITH (OLD AS old_row, NEW AS new_row)
|
||||
old_row.id AS "old_id?",
|
||||
new_row.id AS "id!",
|
||||
new_row.description AS "description!",
|
||||
new_row.account_id AS "account_id!",
|
||||
new_row.amount_cents AS "amount_cents!",
|
||||
new_row.direction AS "direction!",
|
||||
new_row.date AS "date!"
|
||||
new_row.date AS "date!",
|
||||
new_row.description AS "description!"
|
||||
"#,
|
||||
transaction.id,
|
||||
transaction.description,
|
||||
transaction.account_id,
|
||||
transaction.amount_cents,
|
||||
transaction.direction,
|
||||
transaction.date,
|
||||
transaction.description,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
@@ -97,10 +100,11 @@ where
|
||||
|
||||
let transaction = TransactionRow {
|
||||
id: row.id,
|
||||
description: row.description,
|
||||
account_id: row.account_id,
|
||||
amount_cents: row.amount_cents,
|
||||
direction: row.direction,
|
||||
date: row.date,
|
||||
description: row.description,
|
||||
};
|
||||
|
||||
if row.old_id.is_some() {
|
||||
|
||||
Reference in New Issue
Block a user