pub async fn api_view_all_async_tasks_in_class(
    class_id: i32,
    auth: AuthCookie,
    conn: Database,
) -> Json<ApiResponse<ViewTasksSummary>> {
    Json(
        if let Some(role) = get_user_role_in_class(auth.0, class_id, &conn).await {
            match role {
                crate::class::ClassMemberRole::Teacher => {
                    match get_teacher_async_tasks_summary(class_id, auth.0, &conn).await {
                        Ok((tasks, completion_count, student_count)) => {
                            ApiResponse::new_ok(ViewTasksSummary::Teacher(ClassStudentCount {
                                student_count,
                                tasks: tasks
                                    .into_iter()
                                    .zip(completion_count)
                                    .map(|((task, user), completed)| -> TeacherTasksSummary {
                                        TeacherTasksSummary {
                                            task,
                                            set_by: user,
                                            num_complete: completed,
                                        }
                                    })
                                    .collect(),
                            }))
                        }
                        Err(e) => ApiResponse::new_err(match e {
                            ShowAsyncTaskSummaryError::DatabaseError => "database error",
                        }),
                    }
                }
                crate::class::ClassMemberRole::Student => {
                    match get_student_async_tasks_summary(class_id, auth.0, &conn).await {
                        Ok(res) => ApiResponse::new_ok(ViewTasksSummary::Student(
                            res.into_iter()
                                .map(|(student_task, task)| StudentTasksSummary {
                                    task,
                                    student_task,
                                })
                                .collect(),
                        )),
                        Err(e) => ApiResponse::new_err(match e {
                            ShowAsyncTaskSummaryError::DatabaseError => "database error",
                        }),
                    }
                }
            }
        } else {
            ApiResponse::new_err("permission error")
        },
    )
}
/// Show a list of all the asynchronous tasks have been set in a class, either to a teacher or a
/// student (this is retrieved from the database).
Show a list of all the asynchronous tasks have been set in a class, either to a teacher or a
student (this is retrieved from the database).
Show a list of all the asynchronous tasks have been set in a class either to a teacher or a student ( this is retrieved from the database ) .
pub async fn api_view_all_async_tasks_in_class(
    class_id: i32,
    auth: AuthCookie,
    conn: Database,
) -> Json<ApiResponse<ViewTasksSummary>> {
    Json(
        if let Some(role) = get_user_role_in_class(auth.0, class_id, &conn).await {
            match role {
                crate::class::ClassMemberRole::Teacher => {
                    match get_teacher_async_tasks_summary(class_id, auth.0, &conn).await {
                        Ok((tasks, completion_count, student_count)) => {
                            ApiResponse::new_ok(ViewTasksSummary::Teacher(ClassStudentCount {
                                student_count,
                                tasks: tasks
                                    .into_iter()
                                    .zip(completion_count)
                                    .map(|((task, user), completed)| -> TeacherTasksSummary {
                                        TeacherTasksSummary {
                                            task,
                                            set_by: user,
                                            num_complete: completed,
                                        }
                                    })
                                    .collect(),
                            }))
                        }
                        Err(e) => ApiResponse::new_err(match e {
                            ShowAsyncTaskSummaryError::DatabaseError => "database error",
                        }),
                    }
                }
                crate::class::ClassMemberRole::Student => {
                    match get_student_async_tasks_summary(class_id, auth.0, &conn).await {
                        Ok(res) => ApiResponse::new_ok(ViewTasksSummary::Student(
                            res.into_iter()
                                .map(|(student_task, task)| StudentTasksSummary {
                                    task,
                                    student_task,
                                })
                                .collect(),
                        )),
                        Err(e) => ApiResponse::new_err(match e {
                            ShowAsyncTaskSummaryError::DatabaseError => "database error",
                        }),
                    }
                }
            }
        } else {
            ApiResponse::new_err("permission error")
        },
    )
}
pub async fn api_view_all_async_tasks_in_class ( class_id : i32 , auth : AuthCookie , conn : Database , ) -> Json < ApiResponse < ViewTasksSummary > > { Json ( if let Some ( role ) = get_user_role_in_class ( auth . 0 , class_id , & conn ) . await { match role { crate :: class :: ClassMemberRole :: Teacher => { match get_teacher_async_tasks_summary ( class_id , auth . 0 , & conn ) . await { Ok ( ( tasks , completion_count , student_count ) ) => { ApiResponse :: new_ok ( ViewTasksSummary :: Teacher ( ClassStudentCount { student_count , tasks : tasks . into_iter ( ) . zip ( completion_count ) . map ( | ( ( task , user ) , completed ) | -> TeacherTasksSummary { TeacherTasksSummary { task , set_by : user , num_complete : completed , } } ) . collect ( ) , } ) ) } Err ( e ) => ApiResponse :: new_err ( match e { ShowAsyncTaskSummaryError :: DatabaseError => " " , } ) , } } crate :: class :: ClassMemberRole :: Student => { match get_student_async_tasks_summary ( class_id , auth . 0 , & conn ) . await { Ok ( res ) => ApiResponse :: new_ok ( ViewTasksSummary :: Student ( res . into_iter ( ) . map ( | ( student_task , task ) | StudentTasksSummary { task , student_task , } ) . collect ( ) , ) ) , Err ( e ) => ApiResponse :: new_err ( match e { ShowAsyncTaskSummaryError :: DatabaseError => " " , } ) , } } } } else { ApiResponse :: new_err ( " " ) } , ) }
Show a list of all the asynchronous tasks have been set in a class, either to a teacher or a
student (this is retrieved from the database).
Show a list of all the asynchronous tasks have been set in a class either to a teacher or a student ( this is retrieved from the database ) .
class_id
i32
auth
AuthCookie
conn
Database