summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/api.rs8
-rw-r--r--src/api/users.rs10
-rw-r--r--src/auth.rs8
-rw-r--r--src/lib.rs8
4 files changed, 16 insertions, 18 deletions
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<AppState> {
+ use axum::routing::get;
+
axum::Router::new()
.nest("/account", account::router())
.merge(users::router())
@@ -14,11 +14,11 @@ pub fn router() -> axum::Router<AppState> {
.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<AppState> {
#[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<AppState> {
- Router::new()
+pub fn router() -> axum::Router<AppState> {
+ 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<state::AppState> {
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<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
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(|| {