- 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
79 lines
2.3 KiB
Rust
79 lines
2.3 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 AdminVideoEditorList {
|
|
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 experience_years: Option<i32>,
|
|
pub custom_data: serde_json::Value,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
}
|
|
|
|
type AdminVideoEditorDetail = AdminVideoEditorList;
|
|
|
|
pub fn router() -> Router<AppState> {
|
|
Router::new()
|
|
.route("/", get(list_video_editors))
|
|
.route("/{id}", get(get_video_editor))
|
|
}
|
|
|
|
async fn list_video_editors(
|
|
State(state): State<AppState>,
|
|
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
|
let editors = sqlx::query_as!(
|
|
AdminVideoEditorList,
|
|
r#"
|
|
SELECT
|
|
v.id, v.user_id, v.bio, v.experience_years, v.custom_data,
|
|
v.created_at, v.updated_at,
|
|
u.first_name, u.last_name, u.email, u.phone, u.status
|
|
FROM video_editor_profiles v
|
|
JOIN users u ON v.user_id = u.id
|
|
ORDER BY v.created_at DESC
|
|
LIMIT 100
|
|
"#
|
|
)
|
|
.fetch_all(&state.pool)
|
|
.await
|
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
|
|
|
Ok(Json(editors))
|
|
}
|
|
|
|
async fn get_video_editor(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
|
let editor = sqlx::query_as!(
|
|
AdminVideoEditorDetail,
|
|
r#"
|
|
SELECT
|
|
v.id, v.user_id, v.bio, v.experience_years, v.custom_data,
|
|
v.created_at, v.updated_at,
|
|
u.first_name, u.last_name, u.email, u.phone, u.status
|
|
FROM video_editor_profiles v
|
|
JOIN users u ON v.user_id = u.id
|
|
WHERE v.id = $1
|
|
"#,
|
|
id
|
|
)
|
|
.fetch_optional(&state.pool)
|
|
.await
|
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
|
|
|
match editor {
|
|
Some(v) => Ok(Json(v)),
|
|
None => Err((StatusCode::NOT_FOUND, "Video editor not found".to_string())),
|
|
}
|
|
}
|