- Companies service: add GET /api/admin/jobs and GET /api/admin/applications - Gateway: route /api/admin/applications to companies; add routing for all 9 profession admin endpoints - For each profession service (photographers, makeup_artists, tutors, developers, video_editors, graphic_designers, social_media_managers, fitness_trainers, catering_services): - Create admin.rs with list and detail endpoints that join with users - Update main.rs to mount admin router under /api/admin/<profession> - Admin endpoints enable cross-platform visibility of all professionals by internal staff
81 lines
2.4 KiB
Rust
81 lines
2.4 KiB
Rust
use crate::AppState;
|
|
use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
|
|
use chrono::{DateTime, Utc};
|
|
use serde::Serialize;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct AdminPhotographerList {
|
|
pub id: Uuid,
|
|
pub user_id: Uuid,
|
|
pub first_name: String,
|
|
pub last_name: String,
|
|
pub email: String,
|
|
pub phone: Option<String>,
|
|
pub status: String,
|
|
pub bio: Option<String>,
|
|
pub location: Option<String>,
|
|
pub years_experience: Option<i32>,
|
|
pub avg_rating: Option<f64>,
|
|
pub is_verified: Option<bool>,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
}
|
|
|
|
type AdminPhotographerDetail = AdminPhotographerList;
|
|
|
|
pub fn router() -> Router<AppState> {
|
|
Router::new()
|
|
.route("/", get(list_photographers))
|
|
.route("/{id}", get(get_photographer))
|
|
}
|
|
|
|
async fn list_photographers(
|
|
State(state): State<AppState>,
|
|
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
|
let photographers = sqlx::query_as!(
|
|
AdminPhotographerList,
|
|
r#"
|
|
SELECT
|
|
p.id, p.user_id, p.bio, p.location, p.years_experience, p.avg_rating, p.is_verified,
|
|
p.created_at, p.updated_at,
|
|
u.first_name, u.last_name, u.email, u.phone, u.status
|
|
FROM photographers p
|
|
JOIN users u ON p.user_id = u.id
|
|
ORDER BY p.created_at DESC
|
|
LIMIT 100
|
|
"#
|
|
)
|
|
.fetch_all(&state.pool)
|
|
.await
|
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
|
|
|
Ok(Json(photographers))
|
|
}
|
|
|
|
async fn get_photographer(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
|
let photographer = sqlx::query_as!(
|
|
AdminPhotographerDetail,
|
|
r#"
|
|
SELECT
|
|
p.id, p.user_id, p.bio, p.location, p.years_experience, p.avg_rating, p.is_verified,
|
|
p.created_at, p.updated_at,
|
|
u.first_name, u.last_name, u.email, u.phone, u.status
|
|
FROM photographers p
|
|
JOIN users u ON p.user_id = u.id
|
|
WHERE p.id = $1
|
|
"#,
|
|
id
|
|
)
|
|
.fetch_optional(&state.pool)
|
|
.await
|
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
|
|
|
match photographer {
|
|
Some(p) => Ok(Json(p)),
|
|
None => Err((StatusCode::NOT_FOUND, "Photographer not found".to_string())),
|
|
}
|
|
}
|