nxtgauge-backend-rust/apps/fitness_trainers/src/handlers.rs
Tracewebstudio Dev c433ab5fed feat(db): update service handlers and models for new schema
- Update leads service to use 'leads' table
- Update extension models to use user_role_profile_id
- Update ProfessionalRepository to work with new schema
- Create TracecoinWalletRepository for wallet operations
- Update all handlers to use new model fields
- Rename Application fields (job_seeker_id -> applicant_user_id)
- Update cron tasks for new schema
- Fix compilation errors across all services
2026-04-13 00:29:44 +02:00

28 lines
1.3 KiB
Rust

use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use db::models::fitness_trainer::{FitnessTrainerRepository, UpsertFitnessTrainerProfilePayload};
use contracts::{auth_middleware::AuthUser, ProfessionState};
pub fn router() -> Router<ProfessionState> {
Router::new()
.route("/profile/me", get(get_profile).patch(update_profile))
.merge(contracts::profession_shared::shared_routes("FITNESS_TRAINER"))
}
async fn get_profile(State(state): State<ProfessionState>, auth: AuthUser) -> impl IntoResponse {
match FitnessTrainerRepository::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<ProfessionState>,
auth: AuthUser,
Json(payload): Json<UpsertFitnessTrainerProfilePayload>,
) -> impl IntoResponse {
match FitnessTrainerRepository::upsert_by_user_id(&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(),
}
}