Files
api_rust/src/listing/sitemap.rs

33 lines
792 B
Rust

use axum::{
extract::State,
http::StatusCode,
Json,
};
use crate::auth::structs::AppState;
use serde::Serialize;
use serde_json::json;
#[derive(Serialize)]
pub struct ListingId {
pub id: i32,
pub company_name: String,
}
pub async fn get_all_active_listing_ids(
State(app_state): State<AppState>,
) -> Result<Json<Vec<ListingId>>, (StatusCode, Json<serde_json::Value>)> {
match sqlx::query_as!(
ListingId,
"SELECT id, company_name FROM listings WHERE is_active = true ORDER BY id DESC"
)
.fetch_all(&*app_state.db)
.await
{
Ok(ids) => Ok(Json(ids)),
Err(e) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
Json(json!({"error": format!("Failed to fetch listing ids: {}", e)}))
)),
}
}