add user endpoint

This commit is contained in:
2025-08-15 18:38:57 -04:00
parent 34a6f211de
commit 8a05f4edac
8 changed files with 72 additions and 1 deletions

View File

@@ -88,7 +88,12 @@ Here are the available API endpoints for the service.
- **Description:** Used to verify that the service is running and healthy.
- **Success Response:**
- **Code:** `200 OK`
- **Content:** `{"status": "ok"}`
- **Content:** `{
"message": "health check successful",
"data": {},
"success": true,
"error": false
}`
#### Example Usage

View File

@@ -1,3 +1,4 @@
// src/handlers/mod.rs
pub mod health;
pub mod user;

3
src/handlers/user/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
// src/handlers/user/mod.rs
pub mod user;

48
src/handlers/user/user.rs Normal file
View 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,
}
)),
)
}

View File

@@ -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

View File

@@ -1,3 +1,4 @@
// src/routes/mod.rs
pub mod health;
pub mod user;

3
src/routes/user/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
// src/routes/user/mod.rs
pub mod user;

9
src/routes/user/user.rs Normal file
View 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))
}