use contracts::ProfessionState; use db::models::developer::DeveloperProfile; use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::get, Json, Router}; use serde::Serialize; use uuid::Uuid; #[derive(Serialize)] pub struct AdminDeveloperList { pub id: Uuid, pub user_id: Uuid, pub display_name: Option, pub bio: Option, pub location: Option, pub status: String, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, } impl From for AdminDeveloperList { fn from(p: DeveloperProfile) -> Self { Self { id: p.id, user_id: p.user_id, display_name: p.display_name, bio: p.bio, location: p.location, status: p.status, created_at: p.created_at, updated_at: p.updated_at, } } } pub fn router() -> Router { Router::new() .route("/", get(list_developers)) .route("/{id}", get(get_developer)) } async fn list_developers( State(state): State, ) -> Result { let developers = sqlx::query_as::<_, DeveloperProfile>( r#" SELECT id, user_id, display_name, bio, location, custom_data, status, created_at, updated_at FROM developer_profiles ORDER BY created_at DESC LIMIT 100 "#, ) .fetch_all(&state.pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?; let list: Vec = developers.into_iter().map(|p| p.into()).collect(); Ok(Json(list)) } async fn get_developer( State(state): State, Path(id): Path, ) -> Result { let developer = sqlx::query_as::<_, DeveloperProfile>( r#" SELECT id, user_id, display_name, bio, location, custom_data, status, created_at, updated_at FROM developer_profiles WHERE id = $1 "#, ) .bind(id) .fetch_optional(&state.pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?; match developer { Some(d) => Ok(Json(AdminDeveloperList::from(d))), None => Err((StatusCode::NOT_FOUND, "Developer not found".to_string())), } }