From 67d3f2fced7b9f6c66b5527811837112edc0bb09 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Tue, 4 Aug 2026 17:55:59 +0700 Subject: [PATCH] feat(dimentorin): add public mentor list & detail endpoints (verified only) --- .../infrastructure/http/handlers/mod.rs | 1 + .../http/handlers/query_handlers.rs | 63 +++++++++++++++++++ .../src/mentors/infrastructure/http/routes.rs | 5 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/mod.rs b/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/mod.rs index fb9d3e7..bf3f180 100644 --- a/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/mod.rs +++ b/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/mod.rs @@ -7,4 +7,5 @@ pub use mutation_handlers::{ }; pub use query_handlers::{ get_mentor_by_id, get_mentor_list, get_mentor_me, get_mentor_status, + get_public_mentor_by_id, get_public_mentor_list, }; diff --git a/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/query_handlers.rs b/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/query_handlers.rs index 1cd4f4c..d9ef193 100644 --- a/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/query_handlers.rs +++ b/imphnen-dimentorin/src/mentors/infrastructure/http/handlers/query_handlers.rs @@ -151,3 +151,66 @@ pub async fn get_mentor_status( } ) } + +#[utoipa::path( + get, + path = "/v1/dimentorin/mentors/public", + params( + ("page" = Option, Query, description = "Page number"), + ("per_page" = Option, Query, description = "Items per page"), + ("search" = Option, Query, description = "Search query"), + ("sort_by" = Option, Query, description = "Sort by field"), + ("order" = Option, Query, description = "Sort order (ASC/DESC)"), + ), + responses( + (status = 200, description = "Get list of verified mentors", body = Vec), + (status = 500, description = "Internal server error") + ), + tag = "Mentors" +)] +pub async fn get_public_mentor_list( + Extension(state): Extension, + Extension(service): Extension>, + PaginationQuery(params): PaginationQuery, +) -> Result { + 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, + Extension(service): Extension>, + Path(id): Path, +) -> Result { + 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)) +} diff --git a/imphnen-dimentorin/src/mentors/infrastructure/http/routes.rs b/imphnen-dimentorin/src/mentors/infrastructure/http/routes.rs index 0a30a1e..ba6be45 100644 --- a/imphnen-dimentorin/src/mentors/infrastructure/http/routes.rs +++ b/imphnen-dimentorin/src/mentors/infrastructure/http/routes.rs @@ -1,6 +1,7 @@ use super::handlers::{ 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, }; use crate::mentors::application::MentorServiceImpl; @@ -33,6 +34,8 @@ pub fn mentors_public_routes( let service = build_service(db, state); Router::new() .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)) }