fn group(context: &Context, id: String) -> Result<Option<Group>, GraphQLError> {
        // Check id validity
        let id = match uuid::Uuid::parse_str(id.as_str()) {
            Err(e) => return Err(GraphQLError::InvalidId),
            Ok(u) => u,
        };
        // FIXME: Very inefficient quering. Should use joins instead ?
        let viewer = repositories::UserRepository::find_one(context.viewer.id(), &context.db_pool)
            .map_err(GraphQLError::InternalServerError)
            .and_then(|o| match o {
                None => Err(GraphQLError::UserNotFound),
                Some(u) => Ok(u),
            });
        viewer.and_then(|u| {
            repositories::GroupRepository::find_by_user(&u, &context.db_pool)
                .map_err(GraphQLError::InternalServerError)
                .map(|v| v.into_iter().find(|g| g.id == id).map(|g| g.into()))
        })
    }
// FIXME: Extract domain and repository logic to own module
/// Get a group of the use.
/// This is a user context dependant query.
Extract domain and repository logic to own module
Get a group of the use.
This is a user context dependant query.
Extract domain and repository logic to own module Get a group of the use . This is a user context dependant query .
fn group(context: &Context, id: String) -> Result<Option<Group>, GraphQLError> {
        // Check id validity
        let id = match uuid::Uuid::parse_str(id.as_str()) {
            Err(e) => return Err(GraphQLError::InvalidId),
            Ok(u) => u,
        };
        // FIXME: Very inefficient quering. Should use joins instead ?
        let viewer = repositories::UserRepository::find_one(context.viewer.id(), &context.db_pool)
            .map_err(GraphQLError::InternalServerError)
            .and_then(|o| match o {
                None => Err(GraphQLError::UserNotFound),
                Some(u) => Ok(u),
            });
        viewer.and_then(|u| {
            repositories::GroupRepository::find_by_user(&u, &context.db_pool)
                .map_err(GraphQLError::InternalServerError)
                .map(|v| v.into_iter().find(|g| g.id == id).map(|g| g.into()))
        })
    }
fn group ( context : & Context , id : String ) -> Result < Option < Group > , GraphQLError > { // Check id validity let id = match uuid :: Uuid :: parse_str ( id . as_str ( ) ) { Err ( e ) => return Err ( GraphQLError :: InvalidId ) , Ok ( u ) => u , } ; // FIXME: Very inefficient quering. Should use joins instead ? let viewer = repositories :: UserRepository :: find_one ( context . viewer . id ( ) , & context . db_pool ) . map_err ( GraphQLError :: InternalServerError ) . and_then ( | o | match o { None => Err ( GraphQLError :: UserNotFound ) , Some ( u ) => Ok ( u ) , } ) ; viewer . and_then ( | u | { repositories :: GroupRepository :: find_by_user ( & u , & context . db_pool ) . map_err ( GraphQLError :: InternalServerError ) . map ( | v | v . into_iter ( ) . find ( | g | g . id == id ) . map ( | g | g . into ( ) ) ) } ) }
FIXME: Extract domain and repository logic to own module
Get a group of the use.
FIXME : Extract domain and repository logic to own module Get a group of the use .
context
&Context
id
String
context
&Context
id
String