From 7b67a5f28d327c665be64a0091b0a46fedf3e99a Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 16 Apr 2024 14:05:17 -0500 Subject: style: clean up imports --- src/api.rs | 8 ++++---- src/api/users.rs | 10 +++++----- src/auth.rs | 8 +++++--- src/lib.rs | 8 ++------ 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/api.rs b/src/api.rs index f6dd76a..a35fba5 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,5 +1,3 @@ -use axum::{http::Uri, response::IntoResponse, routing::get}; - use crate::state::AppState; pub mod account; @@ -7,6 +5,8 @@ pub mod error; pub mod users; pub fn router() -> axum::Router { + use axum::routing::get; + axum::Router::new() .nest("/account", account::router()) .merge(users::router()) @@ -14,11 +14,11 @@ pub fn router() -> axum::Router { .fallback(fallback) } -pub async fn healthcheck() -> impl IntoResponse { +pub async fn healthcheck() -> &'static str { "success" } -pub async fn fallback(uri: Uri) -> impl IntoResponse { +pub async fn fallback(uri: axum::http::Uri) -> self::error::Error { self::error::Error::RouteNotFound(uri) } diff --git a/src/api/users.rs b/src/api/users.rs index 7b378ef..68986e7 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -21,7 +21,7 @@ pub fn router() -> Resource { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FromRow)] #[serde(rename_all = "camelCase")] -pub struct UserSchema { +pub struct User { pub id: Uuid, pub name: String, pub email: String, @@ -65,7 +65,7 @@ pub async fn create( .await?; let user = sqlx::query_as!( - UserSchema, + User, "INSERT INTO user_ (id,name,email) VALUES ($1, $2, $3) RETURNING *", refresh.sub, name, @@ -86,7 +86,7 @@ pub async fn show( return Err(Error::InvalidToken); } - sqlx::query_as!(UserSchema, "SELECT * FROM user_ WHERE id = $1 LIMIT 1", sub) + sqlx::query_as!(User, "SELECT * FROM user_ WHERE id = $1 LIMIT 1", sub) .fetch_optional(&state.pool) .await? .ok_or_else(|| Error::UserNotFound) @@ -136,7 +136,7 @@ mod tests { assert_eq!(StatusCode::OK, response.status()); let body_bytes = response.into_body().collect().await?.to_bytes(); - let UserSchema { + let User { id, name, email, .. } = serde_json::from_slice(&body_bytes)?; @@ -244,7 +244,7 @@ mod tests { assert_eq!(StatusCode::CREATED, response.status()); let body_bytes = response.into_body().collect().await?.to_bytes(); - let UserSchema { name, email, .. } = serde_json::from_slice(&body_bytes)?; + let User { name, email, .. } = serde_json::from_slice(&body_bytes)?; assert_eq!(USER_NAME, name); assert_eq!(USER_EMAIL, email); diff --git a/src/auth.rs b/src/auth.rs index a27deb2..09494fb 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,5 +1,5 @@ use argon2::{Argon2, PasswordHash, PasswordVerifier}; -use axum::{extract::State, routing::get, Router}; +use axum::extract::State; use axum_extra::{ headers::{authorization::Basic, Authorization}, TypedHeader, @@ -17,8 +17,10 @@ pub mod credentials; pub mod error; pub mod jwt; -pub fn router() -> Router { - Router::new() +pub fn router() -> axum::Router { + use axum::routing::get; + + axum::Router::new() .route("/issue", get(issue)) .route("/refresh", get(refresh)) .merge(credentials::router()) diff --git a/src/lib.rs b/src/lib.rs index b8f322b..86f6752 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -use tower_http::trace::TraceLayer; - pub use error::{Error, Result}; pub mod api; @@ -12,20 +10,18 @@ pub fn router() -> axum::Router { axum::Router::new() .nest("/api", api::router()) .nest("/auth", auth::router()) - .layer(TraceLayer::new_for_http()) + .layer(tower_http::trace::TraceLayer::new_for_http()) } #[cfg(test)] pub(crate) mod tests { - use std::sync::Once; - use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; pub type TestResult> = std::result::Result; pub const JWT_SECRET: &str = "test-jwt-secret-token"; - static INIT: Once = Once::new(); + static INIT: std::sync::Once = std::sync::Once::new(); pub fn setup_test_env() { INIT.call_once(|| { -- cgit v1.2.3-70-g09d2