fix(dimentorin): resolve mentor profile id to user id before booking session

This commit is contained in:
asepharyana
2026-08-04 18:34:13 +07:00
parent 67d3f2fced
commit 7d1078f52a
24 changed files with 437 additions and 1 deletions
@@ -12,7 +12,13 @@ use axum::{
use imphnen_libs::{ValidatedJson, decode_access_token};
use imphnen_utils::AppError;
use imphnen_utils::ApiSuccess;
use imphnen_entities::seaorm::auth::mentors::{
Column as MentorColumn, Entity as MentorsEntity,
};
use imphnen_libs::AppState;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use std::sync::Arc;
use uuid::Uuid;
fn extract_user_id(headers: &HeaderMap) -> Result<String, AppError> {
let token = headers
@@ -43,14 +49,23 @@ fn extract_user_id(headers: &HeaderMap) -> Result<String, AppError> {
)]
pub async fn post_book_session(
headers: HeaderMap,
Extension(state): Extension<AppState>,
Extension(service): Extension<Arc<dyn SessionService>>,
Path(mentor_id): Path<String>,
ValidatedJson(dto): ValidatedJson<BookSessionRequestDto>,
) -> Result<impl IntoResponse, AppError> {
let user_id = extract_user_id(&headers)?;
let mentor_uuid = Uuid::parse_str(&mentor_id).map_err(|_| {
AppError::BadRequestError("Invalid mentor ID format".to_string())
})?;
// Resolve mentor profile id -> user id (sessions.mentor_id FK ke app_users)
let mentor = MentorsEntity::find_by_id(mentor_uuid)
.one(&state.postgres_connection.conn)
.await?
.ok_or_else(|| AppError::NotFoundError("Mentor not found".to_string()))?;
let resp = BookSessionResponseDto::from(
service
.book_session(mentor_id, user_id, dto.into())
.book_session(mentor.user_id.to_string(), user_id, dto.into())
.await?,
);
Ok(ApiSuccess(resp))