pub async fn api_view_specific_asynchronous_task(
    class_id: i32,
    task_id: i32,
    auth: AuthCookie,
    conn: Database,
) -> Json<ApiResponse<ViewSpecificAsynchronousTaskRes>> {
    let role = if let Some(role) = get_user_role_in_class(auth.0, class_id, &conn).await {
        role
    } else {
        return Json(ApiResponse::new_err(
            "You don't have permission to view this task.",
        ));
    };
    Json(match role {
        crate::class::ClassMemberRole::Teacher => {
            match get_teacher_async_task_summary(task_id, class_id, auth.0, &conn).await {
                Ok((class_task, student_tasks)) => ApiResponse::new_ok(
                    ViewSpecificAsynchronousTaskRes::Teacher(TeacherViewTaskRes {
                        task: class_task,
                        student_tasks: student_tasks
                            .into_iter()
                            .map(|(student, task)| StudentTask { student, task })
                            .collect(),
                    }),
                ),
                Err(e) => ApiResponse::new_err(match e {
                    ViewAsyncTaskSummaryError::DatabaseError => {
                        "Encountered an error trying to get this item from the database."
                    }
                }),
            }
        }
        crate::class::ClassMemberRole::Student => {
            match get_student_async_task_summary(task_id, class_id, auth.0, &conn).await {
                Ok((class_task, student_task)) => ApiResponse::new_ok(
                    ViewSpecificAsynchronousTaskRes::Student(StudentViewClassRes {
                        task: class_task,
                        student_task,
                    }),
                ),
                Err(e) => ApiResponse::new_err(match e {
                    ViewAsyncTaskSummaryError::DatabaseError => {
                        "Encountered an error trying to get this item from the database."
                    }
                }),
            }
        }
    })
}
/// Retrieve information about a specific asynchronous task.
Retrieve information about a specific asynchronous task.
Retrieve information about a specific asynchronous task .
pub async fn api_view_specific_asynchronous_task(
    class_id: i32,
    task_id: i32,
    auth: AuthCookie,
    conn: Database,
) -> Json<ApiResponse<ViewSpecificAsynchronousTaskRes>> {
    let role = if let Some(role) = get_user_role_in_class(auth.0, class_id, &conn).await {
        role
    } else {
        return Json(ApiResponse::new_err(
            "You don't have permission to view this task.",
        ));
    };
    Json(match role {
        crate::class::ClassMemberRole::Teacher => {
            match get_teacher_async_task_summary(task_id, class_id, auth.0, &conn).await {
                Ok((class_task, student_tasks)) => ApiResponse::new_ok(
                    ViewSpecificAsynchronousTaskRes::Teacher(TeacherViewTaskRes {
                        task: class_task,
                        student_tasks: student_tasks
                            .into_iter()
                            .map(|(student, task)| StudentTask { student, task })
                            .collect(),
                    }),
                ),
                Err(e) => ApiResponse::new_err(match e {
                    ViewAsyncTaskSummaryError::DatabaseError => {
                        "Encountered an error trying to get this item from the database."
                    }
                }),
            }
        }
        crate::class::ClassMemberRole::Student => {
            match get_student_async_task_summary(task_id, class_id, auth.0, &conn).await {
                Ok((class_task, student_task)) => ApiResponse::new_ok(
                    ViewSpecificAsynchronousTaskRes::Student(StudentViewClassRes {
                        task: class_task,
                        student_task,
                    }),
                ),
                Err(e) => ApiResponse::new_err(match e {
                    ViewAsyncTaskSummaryError::DatabaseError => {
                        "Encountered an error trying to get this item from the database."
                    }
                }),
            }
        }
    })
}
pub async fn api_view_specific_asynchronous_task ( class_id : i32 , task_id : i32 , auth : AuthCookie , conn : Database , ) -> Json < ApiResponse < ViewSpecificAsynchronousTaskRes > > { let role = if let Some ( role ) = get_user_role_in_class ( auth . 0 , class_id , & conn ) . await { role } else { return Json ( ApiResponse :: new_err ( " " , ) ) ; } ; Json ( match role { crate :: class :: ClassMemberRole :: Teacher => { match get_teacher_async_task_summary ( task_id , class_id , auth . 0 , & conn ) . await { Ok ( ( class_task , student_tasks ) ) => ApiResponse :: new_ok ( ViewSpecificAsynchronousTaskRes :: Teacher ( TeacherViewTaskRes { task : class_task , student_tasks : student_tasks . into_iter ( ) . map ( | ( student , task ) | StudentTask { student , task } ) . collect ( ) , } ) , ) , Err ( e ) => ApiResponse :: new_err ( match e { ViewAsyncTaskSummaryError :: DatabaseError => { " " } } ) , } } crate :: class :: ClassMemberRole :: Student => { match get_student_async_task_summary ( task_id , class_id , auth . 0 , & conn ) . await { Ok ( ( class_task , student_task ) ) => ApiResponse :: new_ok ( ViewSpecificAsynchronousTaskRes :: Student ( StudentViewClassRes { task : class_task , student_task , } ) , ) , Err ( e ) => ApiResponse :: new_err ( match e { ViewAsyncTaskSummaryError :: DatabaseError => { " " } } ) , } } } ) }
Retrieve information about a specific asynchronous task.
Retrieve information about a specific asynchronous task .
class_id
i32
task_id
i32
auth
AuthCookie
conn
Database