Skip to content
Snippets Groups Projects
Select Git revision
  • a5a57dec3b59485c2b20eb11b294c4ad6c75e7a4
  • master default protected
  • dev
  • appimage
  • fix_gitlab
  • fixappveyor
  • gitlab
  • fix_ci
  • fix_dbus_error
  • fix_ci_osx
  • sakia020
  • fix_travis#1105
  • feature/backend
  • check_uniq_node_by_endpoints
  • qt5.7
  • feature/agent_architecture
  • translations
  • pyqt5.6
  • qtwebengine
  • pyinstaller
  • landscape
  • 0.53.2
  • 0.53.1
  • 0.53.0
  • 0.52.0
  • 0.51.1
  • 0.51.0
  • 0.50.5
  • 0.50.4
  • 0.50.3
  • 0.50.2
  • 0.50.1
  • 0.50.0
  • 0.33.0rc7
  • 0.33.0rc6
  • 0.33.0rc5
  • 0.33.0rc4
  • 0.33.0rc3
  • 0.33.0rc2
  • 0.33.0rc1
  • 0.32.10post1
41 results

crypto_box.h

Blame
  • pagination.rs 2.10 KiB
    use std::str::FromStr;
    
    //  Copyright (C) 2020 Éloïs SANCHEZ.
    //
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Affero General Public License as
    // published by the Free Software Foundation, either version 3 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU Affero General Public License for more details.
    //
    // You should have received a copy of the GNU Affero General Public License
    // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
    use crate::*;
    
    const MAX_PAGE_SIZE: u32 = 10_000;
    
    #[derive(Clone, Copy, async_graphql::Enum, Eq, PartialEq)]
    pub(crate) enum Order {
        /// Ascending order
        Asc,
        /// Decreasing order
        Desc,
    }
    impl Default for Order {
        fn default() -> Self {
            Order::Asc
        }
    }
    
    #[derive(async_graphql::InputObject)]
    pub(crate) struct Pagination {
        /// Identifier of the 1st desired element (of the last one in descending order)
        cursor: Option<String>,
        ord: Order,
        page_size: u32,
    }
    
    impl Default for Pagination {
        fn default() -> Self {
            Pagination {
                cursor: None,
                ord: Order::default(),
                page_size: 10,
            }
        }
    }
    
    impl Pagination {
        pub(crate) fn convert_to_page_info<
            E: 'static + std::error::Error + Send + Sync,
            T: FromStr<Err = E>,
        >(
            self,
            is_whitelisted: bool,
        ) -> anyhow::Result<duniter_gva_dbs_reader::PageInfo<T>> {
            let page_size = if is_whitelisted || (self.page_size > 0 && self.page_size <= MAX_PAGE_SIZE)
            {
                NonZeroUsize::new(self.page_size as usize)
            } else {
                return Err(anyhow::Error::msg("pageSize must be between 1 and 10000."));
            };
            Ok(duniter_gva_dbs_reader::PageInfo::new(
                self.cursor.map(|c| T::from_str(&c)).transpose()?,
                self.ord == Order::Asc,
                page_size,
            ))
        }
    }