Refactor handlers and OpenAPI documentation for improved readability and consistency
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 6m49s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 17m7s
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 6m49s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 17m7s
- Reorganized imports in health, notifications, social, thoughts, and users handlers for clarity. - Updated function signatures in handlers to improve readability by aligning parameters. - Enhanced JSON response formatting in notifications and thoughts handlers. - Improved error handling in user-related functions. - Refactored OpenAPI documentation to maintain consistent formatting and structure. - Cleaned up unnecessary code and comments across various files. - Ensured consistent use of `Arc` for shared state in AppState and WorkerHandlers.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
|
||||
use api_types::{requests::{LoginRequest, RegisterRequest}, responses::{AuthResponse, ErrorResponse, UserResponse}};
|
||||
use application::use_cases::auth::{login, register, LoginInput, RegisterInput};
|
||||
use crate::{errors::ApiError, state::AppState};
|
||||
use api_types::{
|
||||
requests::{LoginRequest, RegisterRequest},
|
||||
responses::{AuthResponse, ErrorResponse, UserResponse},
|
||||
};
|
||||
use application::use_cases::auth::{login, register, LoginInput, RegisterInput};
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
|
||||
|
||||
pub fn to_user_response(u: &domain::models::user::User) -> UserResponse {
|
||||
UserResponse {
|
||||
@@ -25,13 +28,26 @@ pub fn to_user_response(u: &domain::models::user::User) -> UserResponse {
|
||||
(status = 422, description = "Invalid input", body = ErrorResponse),
|
||||
)
|
||||
)]
|
||||
pub async fn post_register(State(s): State<AppState>, Json(body): Json<RegisterRequest>) -> Result<impl IntoResponse, ApiError> {
|
||||
let out = register(&*s.users, &*s.hasher, &*s.auth, &*s.events, RegisterInput {
|
||||
username: body.username,
|
||||
email: body.email,
|
||||
password: body.password,
|
||||
}).await?;
|
||||
let resp = AuthResponse { token: out.token, user: to_user_response(&out.user) };
|
||||
pub async fn post_register(
|
||||
State(s): State<AppState>,
|
||||
Json(body): Json<RegisterRequest>,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
let out = register(
|
||||
&*s.users,
|
||||
&*s.hasher,
|
||||
&*s.auth,
|
||||
&*s.events,
|
||||
RegisterInput {
|
||||
username: body.username,
|
||||
email: body.email,
|
||||
password: body.password,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let resp = AuthResponse {
|
||||
token: out.token,
|
||||
user: to_user_response(&out.user),
|
||||
};
|
||||
Ok((StatusCode::CREATED, Json(resp)))
|
||||
}
|
||||
|
||||
@@ -43,10 +59,22 @@ pub async fn post_register(State(s): State<AppState>, Json(body): Json<RegisterR
|
||||
(status = 401, description = "Invalid credentials", body = ErrorResponse),
|
||||
)
|
||||
)]
|
||||
pub async fn post_login(State(s): State<AppState>, Json(body): Json<LoginRequest>) -> Result<impl IntoResponse, ApiError> {
|
||||
let out = login(&*s.users, &*s.hasher, &*s.auth, LoginInput {
|
||||
email: body.email,
|
||||
password: body.password,
|
||||
}).await?;
|
||||
Ok(Json(AuthResponse { token: out.token, user: to_user_response(&out.user) }))
|
||||
pub async fn post_login(
|
||||
State(s): State<AppState>,
|
||||
Json(body): Json<LoginRequest>,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
let out = login(
|
||||
&*s.users,
|
||||
&*s.hasher,
|
||||
&*s.auth,
|
||||
LoginInput {
|
||||
email: body.email,
|
||||
password: body.password,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(AuthResponse {
|
||||
token: out.token,
|
||||
user: to_user_response(&out.user),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user