Added Postgres backend and SQLx.

This commit is contained in:
2026-09-19 22:13:38 +02:00
parent 04ebc95920
commit 15b8ae8f62
17 changed files with 1545 additions and 49 deletions
+46
View File
@@ -0,0 +1,46 @@
use chrono::{DateTime, Utc};
use serde::Serialize;
use uuid::Uuid;
use crate::database::dtos::transaction::TransactionRow;
#[derive(Serialize)]
pub struct TransactionResponse {
pub id: Uuid,
pub description: String,
pub amount: f64,
pub date: DateTime<Utc>,
}
impl From<TransactionRow> for TransactionResponse {
fn from(row: TransactionRow) -> Self {
Self {
id: row.id,
description: row.description,
amount: row.amount_cents as f64 / 100.0,
date: row.date,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn converts_cents_to_major_currency_units() {
let id = Uuid::new_v4();
let date = Utc::now();
let response = TransactionResponse::from(TransactionRow {
id,
description: "Groceries".to_string(),
amount_cents: 4250,
date,
});
assert_eq!(response.id, id);
assert_eq!(response.description, "Groceries");
assert_eq!(response.amount, 42.5);
assert_eq!(response.date, date);
}
}