feat(dimentorin): add public mentor list & detail endpoints (verified only)
This commit is contained in:
@@ -7,4 +7,5 @@ pub use mutation_handlers::{
|
|||||||
};
|
};
|
||||||
pub use query_handlers::{
|
pub use query_handlers::{
|
||||||
get_mentor_by_id, get_mentor_list, get_mentor_me, get_mentor_status,
|
get_mentor_by_id, get_mentor_list, get_mentor_me, get_mentor_status,
|
||||||
|
get_public_mentor_by_id, get_public_mentor_list,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -151,3 +151,66 @@ pub async fn get_mentor_status(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/v1/dimentorin/mentors/public",
|
||||||
|
params(
|
||||||
|
("page" = Option<u64>, Query, description = "Page number"),
|
||||||
|
("per_page" = Option<u64>, Query, description = "Items per page"),
|
||||||
|
("search" = Option<String>, Query, description = "Search query"),
|
||||||
|
("sort_by" = Option<String>, Query, description = "Sort by field"),
|
||||||
|
("order" = Option<String>, Query, description = "Sort order (ASC/DESC)"),
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Get list of verified mentors", body = Vec<MentorListResponseDto>),
|
||||||
|
(status = 500, description = "Internal server error")
|
||||||
|
),
|
||||||
|
tag = "Mentors"
|
||||||
|
)]
|
||||||
|
pub async fn get_public_mentor_list(
|
||||||
|
Extension(state): Extension<AppState>,
|
||||||
|
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||||
|
PaginationQuery(params): PaginationQuery,
|
||||||
|
) -> Result<impl IntoResponse, AppError> {
|
||||||
|
let _ = state;
|
||||||
|
let result = service.list(params).await?;
|
||||||
|
let mapped = PaginatorResponse {
|
||||||
|
data: result
|
||||||
|
.data
|
||||||
|
.into_iter()
|
||||||
|
.filter(|item| item.status.eq_ignore_ascii_case("verified"))
|
||||||
|
.map(MentorListResponseDto::from)
|
||||||
|
.collect(),
|
||||||
|
meta: result.meta,
|
||||||
|
};
|
||||||
|
Ok(ApiPaginated(mapped))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/v1/dimentorin/mentors/public/{id}",
|
||||||
|
params(
|
||||||
|
("id" = String, Path, description = "Mentor ID")
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Get verified mentor by ID", body = MentorDetailResponseDto),
|
||||||
|
(status = 404, description = "Mentor not found"),
|
||||||
|
(status = 500, description = "Internal server error")
|
||||||
|
),
|
||||||
|
tag = "Mentors"
|
||||||
|
)]
|
||||||
|
pub async fn get_public_mentor_by_id(
|
||||||
|
Extension(state): Extension<AppState>,
|
||||||
|
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||||
|
Path(id): Path<String>,
|
||||||
|
) -> Result<impl IntoResponse, AppError> {
|
||||||
|
let _ = state;
|
||||||
|
let mentor_uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||||
|
AppError::BadRequestError(
|
||||||
|
"Invalid mentor ID format. Must be a valid UUID.".to_string(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let dto = MentorDetailResponseDto::from(service.get_by_id(mentor_uuid).await?);
|
||||||
|
Ok(ApiSuccess(dto))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::handlers::{
|
use super::handlers::{
|
||||||
delete_mentor, get_mentor_by_id, get_mentor_list, get_mentor_me,
|
delete_mentor, get_mentor_by_id, get_mentor_list, get_mentor_me,
|
||||||
get_mentor_status, post_register_mentor, put_update_mentor, put_update_mentor_me,
|
get_mentor_status, get_public_mentor_by_id, get_public_mentor_list,
|
||||||
|
post_register_mentor, put_update_mentor, put_update_mentor_me,
|
||||||
put_update_mentor_no_id, put_verify_mentor,
|
put_update_mentor_no_id, put_verify_mentor,
|
||||||
};
|
};
|
||||||
use crate::mentors::application::MentorServiceImpl;
|
use crate::mentors::application::MentorServiceImpl;
|
||||||
@@ -33,6 +34,8 @@ pub fn mentors_public_routes(
|
|||||||
let service = build_service(db, state);
|
let service = build_service(db, state);
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/mentors/create", post(post_register_mentor))
|
.route("/mentors/create", post(post_register_mentor))
|
||||||
|
.route("/mentors/public", get(get_public_mentor_list))
|
||||||
|
.route("/mentors/public/{id}", get(get_public_mentor_by_id))
|
||||||
.layer(Extension(service))
|
.layer(Extension(service))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user