feat(dimentorin): admin sessions endpoint untuk backoffice (GET /admin/sessions, paginated + nama + feedback)
This commit is contained in:
@@ -5,5 +5,6 @@ pub use mutation_handlers::{
|
||||
post_book_session, post_submit_feedback, put_update_session_status,
|
||||
};
|
||||
pub use query_handlers::{
|
||||
get_mentor_availability, get_mentor_sessions, get_mentor_stats, get_my_sessions,
|
||||
get_admin_sessions, get_mentor_availability, get_mentor_sessions, get_mentor_stats,
|
||||
get_my_sessions,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::super::dto::{MentorAvailabilityDto, MentorStatsDto, SessionListResponseDto};
|
||||
use super::super::dto::{AdminSessionListItemDto, MentorAvailabilityDto, MentorStatsDto, SessionListResponseDto};
|
||||
use crate::sessions::domain::SessionService;
|
||||
use axum::{
|
||||
extract::{Extension, Path, Query},
|
||||
@@ -8,6 +8,7 @@ use axum::{
|
||||
use imphnen_libs::decode_access_token;
|
||||
use imphnen_utils::AppError;
|
||||
use imphnen_utils::{ApiSuccess, extract_email};
|
||||
use paginator_axum::PaginationQuery;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -118,3 +119,41 @@ pub async fn get_my_sessions(
|
||||
);
|
||||
Ok(ApiSuccess(resp))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/v1/dimentorin/admin/sessions",
|
||||
tag = "sessions",
|
||||
security(("Bearer" = [])),
|
||||
params(
|
||||
("page" = Option<u64>, Query, description = "Page number"),
|
||||
("per_page" = Option<u64>, Query, description = "Items per page"),
|
||||
("status" = Option<String>, Query, description = "Filter by status"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "All sessions (admin) retrieved successfully", body = AdminSessionListItemDto),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 403, description = "Forbidden"),
|
||||
)
|
||||
)]
|
||||
pub async fn get_admin_sessions(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<imphnen_libs::AppState>,
|
||||
Extension(service): Extension<Arc<dyn SessionService>>,
|
||||
PaginationQuery(params): PaginationQuery,
|
||||
Query(filter): Query<SessionStatusFilter>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
imphnen_iam::require_permissions!(
|
||||
headers,
|
||||
state,
|
||||
[imphnen_entities::PermissionsEnum::Administrator],
|
||||
{
|
||||
let page = u64::from(params.page.max(1));
|
||||
let per_page = u64::from(params.per_page.clamp(1, 100));
|
||||
let resp = service
|
||||
.get_admin_sessions(page, per_page, filter.status)
|
||||
.await?;
|
||||
Ok(imphnen_utils::ApiPaginated(resp))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user