No need for query transformation gymnastics if they're only used at one place.

This commit is contained in:
Rogier Reerink
2026-10-08 15:43:51 +02:00
parent c88cfac8a0
commit 8576da980e
4 changed files with 33 additions and 61 deletions
+12 -18
View File
@@ -33,30 +33,24 @@ pub struct QueryParams {
pub offset: Option<u64>,
}
impl TryFrom<QueryParams> for repository::accounts::Query {
type Error = AppError;
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
Ok(repository::accounts::Query {
name: query.name,
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
..Default::default()
})
}
}
#[axum::debug_handler]
#[tracing::instrument(skip(pool))]
async fn list_accounts(
State(pool): State<PgPool>,
Query(query): Query<QueryParams>,
) -> Result<Json<Vec<AccountResponse>>, AppError> {
let accounts = repository::accounts::list(&pool, query.try_into()?)
.await?
.into_iter()
.map(AccountResponse::from)
.collect();
let accounts = repository::accounts::list(
&pool,
repository::accounts::Query {
name: query.name,
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
},
)
.await?
.into_iter()
.map(AccountResponse::from)
.collect();
Ok(Json(accounts))
}