/// The developer catalogue. This page displays all of the users in the
/// RCOS database.
The developer catalogue. This page displays all of the users in the
RCOS database.
The developer catalogue . This page displays all of the users in the RCOS database .
pub async fn developers_page(
    req: HttpRequest,
    identity: Identity,
    page: Option<Path<u32>>,
    Query(query): Query<DevelopersPageQuery>,
) -> Result<Page, TelescopeError> {
    // Resolve the page number from the request
    let page_num: u32 = page
        // Extract from path if available.
        .map(|page_path| page_path.0)
        // Filter and subtract 1, since the page numbers in the UI index from 1.
        // Filter first since subtracting first could result in underflow.
        .filter(|p| *p >= 1)
        .map(|p| p - 1)
        // Otherwise default to 0
        .unwrap_or(0);
    // Get the API data by sending one of the developer page queries.
    let api_data: Value;
    // Determine which API query to send using the request query.
    if query.include_old {
        // Get all the developers (including ones not active this semester).
        let query_response = AllDevelopers::get(page_num, query.search.clone()).await?;
        // Convert the response into a JSON value.
        // Unwrap because this conversion should never fail.
        api_data = serde_json::to_value(query_response).unwrap();
    } else {
        // Get only the current developers.
        let query_response = CurrentDevelopers::get(page_num, query.search.clone()).await?;
        api_data = serde_json::to_value(query_response).unwrap();
    }
    // Get the viewers user ID
    let viewer: Option<Uuid> = identity.get_user_id().await?;
    // Build developers page template.
    let mut template = Template::new(TEMPLATE_PATH);
    template.fields = json!({
        "pagination": get_page_numbers(&api_data, page_num as u64 + 1),
        "data": api_data,
        "query": query,
        "identity": viewer,
        "preserved_query_string": req.query_string()
    });
    return template.in_page(&req, "Developers").await;
}
pub async fn developers_page ( req : HttpRequest , identity : Identity , page : Option < Path < u32 > > , Query ( query ) : Query < DevelopersPageQuery > , ) -> Result < Page , TelescopeError > { // Resolve the page number from the request let page_num : u32 = page // Extract from path if available. . map ( | page_path | page_path . 0 ) // Filter and subtract 1, since the page numbers in the UI index from 1. // Filter first since subtracting first could result in underflow. . filter ( | p | * p >= 1 ) . map ( | p | p - 1 ) // Otherwise default to 0 . unwrap_or ( 0 ) ; // Get the API data by sending one of the developer page queries. let api_data : Value ; // Determine which API query to send using the request query. if query . include_old { // Get all the developers (including ones not active this semester). let query_response = AllDevelopers :: get ( page_num , query . search . clone ( ) ) . await ? ; // Convert the response into a JSON value. // Unwrap because this conversion should never fail. api_data = serde_json :: to_value ( query_response ) . unwrap ( ) ; } else { // Get only the current developers. let query_response = CurrentDevelopers :: get ( page_num , query . search . clone ( ) ) . await ? ; api_data = serde_json :: to_value ( query_response ) . unwrap ( ) ; } // Get the viewers user ID let viewer : Option < Uuid > = identity . get_user_id ( ) . await ? ; // Build developers page template. let mut template = Template :: new ( TEMPLATE_PATH ) ; template . fields = json ! ( { " " get_page_numbers ( api_data page_num as u64 1 ) " " api_data " " query " " viewer " " req query_string ( ) } ) ; return template . in_page ( & req , " " ) . await ; }
The developer catalogue.
The developer catalogue .
req
HttpRequest
identity
Identity
page
Query<DevelopersPageQuery>