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

81 lines
2.5 KiB
Rust

use contracts::ProfessionState;
use db::models::graphic_designer::GraphicDesignerProfile;
use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use serde::Serialize;
use uuid::Uuid;
#[derive(Serialize)]
pub struct AdminGraphicDesignerList {
pub id: Uuid,
pub user_id: Uuid,
pub display_name: Option<String>,
pub bio: Option<String>,
pub location: Option<String>,
pub status: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
}
impl From<GraphicDesignerProfile> for AdminGraphicDesignerList {
fn from(p: GraphicDesignerProfile) -> Self {
Self {
id: p.id,
user_id: p.user_id,
display_name: p.display_name,
bio: p.bio,
location: p.location,
status: p.status,
created_at: p.created_at,
updated_at: p.updated_at,
}
}
}
pub fn router() -> Router<ProfessionState> {
Router::new()
.route("/", get(list_graphic_designers))
.route("/{id}", get(get_graphic_designer))
}
async fn list_graphic_designers(
State(state): State<ProfessionState>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
let designers = sqlx::query_as!(
GraphicDesignerProfile,
r#"
SELECT id, user_id, display_name, bio, location, custom_data, status, created_at, updated_at
FROM graphic_designer_profiles
ORDER BY created_at DESC
LIMIT 100
"#
)
.fetch_all(&state.pool)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
let list: Vec<AdminGraphicDesignerList> = designers.into_iter().map(|p| p.into()).collect();
Ok(Json(list))
}
async fn get_graphic_designer(
State(state): State<ProfessionState>,
Path(id): Path<Uuid>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
let designer = sqlx::query_as!(
GraphicDesignerProfile,
r#"
SELECT id, user_id, display_name, bio, location, custom_data, status, created_at, updated_at
FROM graphic_designer_profiles
WHERE id = $1
"#,
id
)
.fetch_optional(&state.pool)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
match designer {
Some(d) => Ok(Json(AdminGraphicDesignerList::from(d))),
None => Err((StatusCode::NOT_FOUND, "Graphic Designer not found".to_string())),
}
}