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
+11 -17
View File
@@ -32,29 +32,23 @@ pub struct QueryParams {
pub offset: Option<u64>,
}
impl TryFrom<QueryParams> for repository::users::Query {
type Error = AppError;
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
Ok(repository::users::Query {
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
..Default::default()
})
}
}
#[axum::debug_handler]
#[tracing::instrument(skip(pool))]
async fn list_users(
State(pool): State<PgPool>,
Query(query): Query<QueryParams>,
) -> Result<Json<Vec<UserResponse>>, AppError> {
let users = repository::users::list(&pool, query.try_into()?)
.await?
.into_iter()
.map(UserResponse::from)
.collect();
let users = repository::users::list(
&pool,
repository::users::Query {
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
},
)
.await?
.into_iter()
.map(UserResponse::from)
.collect();
Ok(Json(users))
}