use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router}; use db::models::photographer::{PhotographerRepository, UpsertPhotographerProfilePayload}; use contracts::{auth_middleware::AuthUser, ProfessionState}; pub fn router() -> Router { Router::new() .route("/profile/me", get(get_profile).patch(update_profile)) .merge(contracts::profession_shared::shared_routes("PHOTOGRAPHER")) } async fn get_profile(State(state): State, auth: AuthUser) -> impl IntoResponse { match PhotographerRepository::get_by_user_id(&state.pool, auth.user_id).await { Ok(Some(p)) => (StatusCode::OK, Json(p)).into_response(), Ok(None) => (StatusCode::NOT_FOUND, "Profile not found").into_response(), Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), } } async fn update_profile( State(state): State, auth: AuthUser, Json(payload): Json, ) -> impl IntoResponse { match PhotographerRepository::upsert(&state.pool, auth.user_id, payload).await { Ok(p) => (StatusCode::OK, Json(p)).into_response(), Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), } }