Added query parameters.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
DecodeError, Delete, RepositoryError, Upsert,
|
||||
DecodeError, Delete, QueryConversionError, RepositoryError, Upsert,
|
||||
encoding::{decode_direction, encode_direction},
|
||||
};
|
||||
use crate::{
|
||||
@@ -9,11 +9,33 @@ use crate::{
|
||||
domain::{Cents, Transaction},
|
||||
};
|
||||
|
||||
pub async fn list<'e, E>(executor: E) -> Result<Vec<Transaction>, 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 list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::query_transactions(executor)
|
||||
let transactions = db::query_transactions(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
|
||||
Reference in New Issue
Block a user