Condensed classifiers in one place

This commit is contained in:
Manuel Forcén Muñoz 2024-03-20 20:49:22 +01:00
parent cf7fc2ec87
commit e336292db4
8 changed files with 256 additions and 34 deletions

View file

@ -101,6 +101,32 @@ impl Transaction {
Ok(res)
}
pub async fn list_by_user(
pool: &SqlitePool,
user: i32,
limit: i32,
offset: i32,
asc: bool,
) -> Result<Vec<Self>> {
let rows = sqlx::query(
if asc {
"SELECT t.* FROM transactions t JOIN accounts a ON a.account_id=t.account WHERE a.user=? ORDER BY transaction_timestamp ASC LIMIT ? OFFSET ?"
} else {
"SELECT t.* FROM transactions t JOIN accounts a ON a.account_id=t.account WHERE a.user=? ORDER BY transaction_timestamp DESC LIMIT ? OFFSET ?"
}
).bind(user)
.bind(limit)
.bind(offset)
.fetch_all(pool)
.await?;
let mut res = Vec::new();
for r in &rows {
res.push(Transaction::from_row(r)?);
}
Ok(res)
}
pub fn query_by_date<'a>(
account: i32,
after: Option<DateTime<Utc>>,