feat: add admin leads endpoint and fix routing
- Customers service: add admin.rs with GET /api/admin/leads returning requirements with customer info - Update customers main.rs to mount admin router at /api/admin/leads (instead of /api/admin/requirements) - Gateway: route /api/admin/leads to customers service; remove /api/admin/requirements routing - This enables Leads Management page to fetch all platform requirements - Removed redundant /admin/requirements list page from frontend (kept detail page)
This commit is contained in:
parent
2c0c979c91
commit
7457af5e3f
3 changed files with 49 additions and 2 deletions
45
apps/customers/src/admin.rs
Normal file
45
apps/customers/src/admin.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use crate::AppState;
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AdminLeadRow {
|
||||
pub id: Uuid,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub profession: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub budget_min: Option<i32>,
|
||||
pub budget_max: Option<i32>,
|
||||
pub status: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
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 leads = sqlx::query_as!(
|
||||
AdminLeadRow,
|
||||
r#"
|
||||
SELECT
|
||||
r.id, r.title, r.description, r.profession_key AS "profession",
|
||||
r.location, r.budget_min, r.budget_max, r.status,
|
||||
r.created_at, r.updated_at
|
||||
FROM requirements r
|
||||
ORDER BY r.created_at DESC
|
||||
LIMIT 100
|
||||
"#
|
||||
)
|
||||
.fetch_all(&state.pool)
|
||||
.await
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
||||
|
||||
Ok(Json(leads))
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
mod handlers;
|
||||
mod admin;
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use std::net::SocketAddr;
|
||||
|
|
@ -35,6 +36,7 @@ async fn main() {
|
|||
|
||||
let app = Router::new()
|
||||
.nest("/api/customers", handlers::router())
|
||||
.nest("/api/admin/leads", admin::router())
|
||||
.route("/health", get(|| async { "Customers OK" }))
|
||||
.with_state(state);
|
||||
|
||||
|
|
|
|||
|
|
@ -124,10 +124,10 @@ impl Services {
|
|||
else if path.starts_with("/api/jobseeker") {
|
||||
Some(self.job_seekers_url.clone())
|
||||
}
|
||||
// Customers + Requirements
|
||||
// Customers + Leads
|
||||
else if path.starts_with("/api/customers")
|
||||
|| path.starts_with("/api/admin/customers")
|
||||
|| path.starts_with("/api/admin/requirements")
|
||||
|| path.starts_with("/api/admin/leads")
|
||||
{
|
||||
Some(self.customers_url.clone())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue