nxtgauge-backend-rust/apps/customers/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

60 lines
1.8 KiB
Rust

use crate::AppState;
use db::models::requirement::Requirement;
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use serde::Serialize;
use uuid::Uuid;
#[derive(Serialize)]
pub struct AdminLeadRow {
pub id: Uuid,
pub title: String,
pub description: Option<String>,
pub profession_key: String,
pub location: String,
pub budget: Option<i32>,
pub status: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
}
impl From<Requirement> for AdminLeadRow {
fn from(r: Requirement) -> Self {
Self {
id: r.id,
title: r.title,
description: Some(r.description),
profession_key: r.profession_key,
location: r.location,
budget: r.budget,
status: r.status,
created_at: r.created_at,
updated_at: r.updated_at,
}
}
}
pub fn router() -> Router<AppState> {
Router::new().route("/", get(list_leads))
}
async fn list_leads(
State(state): State<AppState>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
let requirements = sqlx::query_as!(
Requirement,
r#"
SELECT id, customer_id, profession_key, title, description, location, budget,
preferred_date, extra_data_json, status, rejection_reason, request_count, accepted_count,
expires_at, approved_at, approved_by, created_at, updated_at
FROM requirements
ORDER BY created_at DESC
LIMIT 100
"#
)
.fetch_all(&state.pool)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
let leads: Vec<AdminLeadRow> = requirements.into_iter().map(|r| r.into()).collect();
Ok(Json(leads))
}