diff options
Diffstat (limited to 'src/api/users.rs')
-rw-r--r-- | src/api/users.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/api/users.rs b/src/api/users.rs index 6ac0bb8..e73e229 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -7,7 +7,7 @@ use axum::{ }; use axum_extra::routing::Resource; use serde::{Deserialize, Serialize}; -use sqlx::FromRow; +use sqlx::PgPool; use time::OffsetDateTime; use uuid::Uuid; @@ -22,7 +22,7 @@ pub fn router() -> Resource<AppState> { Resource::named("users").create(create).show(show) } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FromRow)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct User { pub id: Uuid, @@ -40,7 +40,7 @@ pub struct Registration { } pub async fn create( - State(state): State<AppState>, + State(pool): State<PgPool>, Json(Registration { name, email, @@ -53,7 +53,7 @@ pub async fn create( "SELECT EXISTS(SELECT 1 FROM user_ WHERE email = $1 LIMIT 1)", email.to_ascii_lowercase() ) - .fetch_one(&state.pool) + .fetch_one(&pool) .await?; if exists.is_some_and(|b| b) { @@ -62,7 +62,7 @@ pub async fn create( // TODO: Move this into a micro service, possibly behind a feature flag. let (status, (access, refresh)) = - crate::auth::credentials::create(State(state.clone()), Json(Credential { password })) + crate::auth::credentials::create(State(pool.clone()), Json(Credential { password })) .await?; let user = sqlx::query_as!( @@ -72,7 +72,7 @@ pub async fn create( name, email.to_ascii_lowercase(), ) - .fetch_one(&state.pool) + .fetch_one(&pool) .await?; Ok((status, access, refresh, Json(user))) @@ -80,7 +80,7 @@ pub async fn create( pub async fn show( Path(uuid): Path<Uuid>, - State(state): State<AppState>, + State(pool): State<PgPool>, AccessClaims { sub, .. }: AccessClaims, ) -> Result<impl IntoResponse, Error> { if uuid != sub { @@ -88,7 +88,7 @@ pub async fn show( } sqlx::query_as!(User, "SELECT * FROM user_ WHERE id = $1 LIMIT 1", sub) - .fetch_optional(&state.pool) + .fetch_optional(&pool) .await? .ok_or_else(|| Error::UserNotFound) .map(Json) @@ -108,7 +108,6 @@ mod tests { }; use http_body_util::BodyExt; - use sqlx::PgPool; use tower::ServiceExt; use crate::{ |