Added name query to accounts and updated query handling.

This commit is contained in:
2026-09-27 10:32:08 +02:00
parent bb58e3fd77
commit d219d63dca
10 changed files with 74 additions and 4 deletions
+15 -2
View File
@@ -3,10 +3,21 @@ use uuid::Uuid;
use super::dtos::{AccountRow, Delete, Upsert};
pub struct Query {
pub name: Option<String>,
pub limit: Option<i64>,
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
name: None,
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, sqlx::Error>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
@@ -16,10 +27,12 @@ where
r#"
SELECT id, name
FROM accounts
WHERE ($1::text IS NULL OR name ILIKE '%' || $1 || '%')
ORDER BY name DESC, id DESC
LIMIT $1
OFFSET $2
LIMIT $2
OFFSET $3
"#,
query.name,
query.limit,
query.offset,
)
@@ -7,6 +7,15 @@ pub struct Query {
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(
executor: E,
query: Query,
+9
View File
@@ -7,6 +7,15 @@ pub struct Query {
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, sqlx::Error>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
+13
View File
@@ -10,15 +10,27 @@ use crate::{
};
pub struct Query {
pub name: Option<String>,
pub limit: Option<u64>,
pub offset: Option<u64>,
}
impl Default for Query {
fn default() -> Self {
Self {
name: None,
limit: None,
offset: None,
}
}
}
impl TryFrom<Query> for db::Query {
type Error = QueryConversionError;
fn try_from(query: Query) -> Result<Self, Self::Error> {
Ok(db::Query {
name: query.name,
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
@@ -27,6 +39,7 @@ impl TryFrom<Query> for db::Query {
.offset
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
.transpose()?,
..Default::default()
})
}
}
@@ -18,6 +18,15 @@ pub struct Query {
pub offset: Option<u64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
impl TryFrom<Query> for db::Query {
type Error = QueryConversionError;
@@ -31,6 +40,7 @@ impl TryFrom<Query> for db::Query {
.offset
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
.transpose()?,
..Default::default()
})
}
}
+10
View File
@@ -15,6 +15,15 @@ pub struct Query {
pub offset: Option<u64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
impl TryFrom<Query> for db::Query {
type Error = QueryConversionError;
@@ -28,6 +37,7 @@ impl TryFrom<Query> for db::Query {
.offset
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
.transpose()?,
..Default::default()
})
}
}
+3
View File
@@ -28,6 +28,7 @@ pub fn create_router() -> axum::Router<PgPool> {
#[derive(Debug, Deserialize)]
pub struct QueryParams {
pub name: Option<String>,
pub limit: Option<u64>,
pub offset: Option<u64>,
}
@@ -37,8 +38,10 @@ impl TryFrom<QueryParams> for repository::Query {
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
Ok(repository::Query {
name: query.name,
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
..Default::default()
})
}
}
@@ -43,6 +43,7 @@ impl TryFrom<QueryParams> for repository::Query {
Ok(repository::Query {
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
..Default::default()
})
}
}
+1
View File
@@ -39,6 +39,7 @@ impl TryFrom<QueryParams> for repository::Query {
Ok(repository::Query {
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
..Default::default()
})
}
}