Added query parameters.

This commit is contained in:
2026-09-26 20:19:06 +02:00
parent 9279258ff1
commit 859ae71c51
12 changed files with 172 additions and 20 deletions
@@ -1,7 +1,7 @@
use uuid::Uuid;
use super::{
DecodeError, Delete, RepositoryError, Upsert,
DecodeError, Delete, QueryConversionError, RepositoryError, Upsert,
encoding::{
decode_direction, decode_recurrence_unit, decode_weekend_adjustment, encode_direction,
encode_recurrence_unit, encode_weekend_adjustment,
@@ -14,11 +14,36 @@ use crate::{
domain::{Cents, Recurrence, RecurrenceInterval, RecurringTransaction, Schedule},
};
pub async fn list<'e, E>(executor: E) -> Result<Vec<RecurringTransaction>, RepositoryError>
pub struct Query {
pub limit: Option<u64>,
pub offset: Option<u64>,
}
impl TryFrom<Query> for db::Query {
type Error = QueryConversionError;
fn try_from(query: Query) -> Result<Self, Self::Error> {
Ok(db::Query {
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
.transpose()?,
offset: query
.offset
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
.transpose()?,
})
}
}
pub async fn query<'e, E>(
executor: E,
query: Query,
) -> Result<Vec<RecurringTransaction>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transactions = db::query_recurring_transactions(executor)
let transactions = db::query_recurring_transactions(executor, query.try_into()?)
.await?
.into_iter()
.map(decode)