use contracts::ProfessionState; use db::models::catering_service::CateringServiceProfile; use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::get, Json, Router}; use serde::Serialize; use uuid::Uuid; #[derive(Serialize)] pub struct AdminCateringServiceList { pub id: Uuid, pub user_id: Uuid, pub business_name: Option, pub bio: Option, pub location: Option, pub status: String, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, } impl From for AdminCateringServiceList { fn from(p: CateringServiceProfile) -> Self { Self { id: p.id, user_id: p.user_id, business_name: p.business_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_catering_services)) .route("/{id}", get(get_catering_service)) } async fn list_catering_services( State(state): State, ) -> Result { let services = sqlx::query_as::<_, CateringServiceProfile>( r#" SELECT id, user_id, business_name, bio, location, custom_data, status, created_at, updated_at FROM catering_service_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 = services.into_iter().map(|p| p.into()).collect(); Ok(Json(list)) } async fn get_catering_service( State(state): State, Path(id): Path, ) -> Result { let service = sqlx::query_as::<_, CateringServiceProfile>( r#" SELECT id, user_id, business_name, bio, location, custom_data, status, created_at, updated_at FROM catering_service_profiles WHERE id = $1 "#, ) .bind(id) .fetch_optional(&state.pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?; match service { Some(s) => Ok(Json(AdminCateringServiceList::from(s))), None => Err((StatusCode::NOT_FOUND, "Catering Service not found".to_string())), } }