add user endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// src/handlers/mod.rs
|
||||
|
||||
pub mod health;
|
||||
pub mod user;
|
||||
|
||||
3
src/handlers/user/mod.rs
Normal file
3
src/handlers/user/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/handlers/user/mod.rs
|
||||
|
||||
pub mod user;
|
||||
48
src/handlers/user/user.rs
Normal file
48
src/handlers/user/user.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// src/handlers/user/user.rs
|
||||
|
||||
use axum::Json;
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use serde_json::json;
|
||||
|
||||
pub async fn user() -> impl IntoResponse {
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(json!(
|
||||
{
|
||||
"message": "health check successful",
|
||||
"data": {
|
||||
"id": "usr_123456789",
|
||||
"username": "john_doe",
|
||||
"email": "john.doe@example.com",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"role": "user",
|
||||
"is_active": true,
|
||||
"created_at": "2024-01-15T10:30:00Z",
|
||||
"updated_at": "2024-08-15T14:20:00Z",
|
||||
"profile": {
|
||||
"avatar_url": "https://api.example.com/avatars/john_doe.png",
|
||||
"bio": "Software developer passionate about Rust",
|
||||
"location": "San Francisco, CA",
|
||||
"website": "https://johndoe.dev"
|
||||
},
|
||||
"preferences": {
|
||||
"theme": "dark",
|
||||
"language": "en",
|
||||
"notifications_enabled": true,
|
||||
"email_verified": true
|
||||
},
|
||||
"stats": {
|
||||
"total_posts": 42,
|
||||
"total_comments": 156,
|
||||
"total_likes": 523,
|
||||
"account_age_days": 213
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"error": false,
|
||||
}
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -44,6 +44,7 @@ async fn main() {
|
||||
let app = Router::new()
|
||||
// .nest("/health", routes::health::health::health_routes())
|
||||
.nest("/health", routes::health::health::health_routes())
|
||||
.nest("/user", routes::user::user::user_routes())
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
// Run the server
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/routes/mod.rs
|
||||
|
||||
pub mod health;
|
||||
pub mod user;
|
||||
|
||||
3
src/routes/user/mod.rs
Normal file
3
src/routes/user/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/routes/user/mod.rs
|
||||
|
||||
pub mod user;
|
||||
9
src/routes/user/user.rs
Normal file
9
src/routes/user/user.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// src/routes/user/user.rs
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
|
||||
use crate::handlers::user::user::user;
|
||||
|
||||
pub fn user_routes() -> Router {
|
||||
Router::new().route("/", get(user))
|
||||
}
|
||||
Reference in New Issue
Block a user