nxtgauge-backend-rust/apps/catering_services/src/admin.rs
Ashwin Kumar 7928e21a21 fix: resolve all compilation warnings and errors across services
- Remove duplicate departments/designations/employees handlers from users service (already in employees service)
- Fix all 9 profession admin handlers to use correct DB schema (display_name, bio, location, custom_data)
- Fix companies admin handler to match CompanyProfile DB model with all fields
- Fix customers admin handler to match Requirement model with preferred_date
- Fix missing serde_json imports and type annotations in admin handlers
- Add #[allow(dead_code)] for intentionally unused structs/fields
- Add test infrastructure: auth crypto tests (2 passing), test directory structure
- Zero compilation warnings across all services
2026-04-07 12:52:55 +02:00

81 lines
2.5 KiB
Rust

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<String>,
pub bio: Option<String>,
pub location: Option<String>,
pub status: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
}
impl From<CateringServiceProfile> 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<ProfessionState> {
Router::new()
.route("/", get(list_catering_services))
.route("/{id}", get(get_catering_service))
}
async fn list_catering_services(
State(state): State<ProfessionState>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
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<AdminCateringServiceList> = services.into_iter().map(|p| p.into()).collect();
Ok(Json(list))
}
async fn get_catering_service(
State(state): State<ProfessionState>,
Path(id): Path<Uuid>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
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
"#,
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())),
}
}