Mobile support to come.
use axum::{
extract::{Path, State},
http::StatusCode,
};
use gitdot_core::dto::{ListQuestionsRequest, RepositoryAuthorizationRequest};
use crate::app::{AppError, AppResponse, AppState, AuthenticatedUser};
use crate::dto::QuestionServerResponse;
#[axum::debug_handler]
pub async fn get_questions(
auth_user: Option<AuthenticatedUser>,
State(state): State<AppState>,
Path((owner, repo)): Path<(String, String)>,
) -> Result<AppResponse<Vec<QuestionServerResponse>>, AppError> {
let user_id = auth_user.as_ref().map(|u| u.id);
let request = RepositoryAuthorizationRequest::new(user_id, &owner, &repo)?;
state
.auth_service
.verify_authorized_for_repository(request)
.await?;
let request = ListQuestionsRequest::new(&owner, &repo, user_id)?;
state
.question_service
.list_questions(request)
.await
.map_err(AppError::from)
.map(|qs| AppResponse::new(StatusCode::OK, qs.into_iter().map(|q| q.into()).collect()))
}
nits
mike•b040df512d ago
removed questions server response and replaced with vec<question>
mike•b6f08c912d ago
implemented voting system
mike•cfbefbc13d ago
rolled back to standard question apis
mike•ef0cc8213d ago
added authorization for create and get apis
mike•03250fe14d ago
wired up question apis
mike•4ea4d4014d ago