es_entity/
query.rs

1#[derive(Default, std::fmt::Debug, Clone, Copy)]
2pub enum ListDirection {
3    #[default]
4    Ascending,
5    Descending,
6}
7
8#[derive(std::fmt::Debug, Clone, Copy)]
9pub struct Sort<T> {
10    pub by: T,
11    pub direction: ListDirection,
12}
13
14#[derive(Debug)]
15pub struct PaginatedQueryArgs<T: std::fmt::Debug> {
16    pub first: usize,
17    pub after: Option<T>,
18}
19
20impl<T: std::fmt::Debug> Clone for PaginatedQueryArgs<T>
21where
22    T: Clone,
23{
24    fn clone(&self) -> Self {
25        Self {
26            first: self.first,
27            after: self.after.clone(),
28        }
29    }
30}
31
32impl<T: std::fmt::Debug> Default for PaginatedQueryArgs<T> {
33    fn default() -> Self {
34        Self {
35            first: 100,
36            after: None,
37        }
38    }
39}
40
41pub struct PaginatedQueryRet<T, C> {
42    pub entities: Vec<T>,
43    pub has_next_page: bool,
44    pub end_cursor: Option<C>,
45}
46
47impl<T, C> PaginatedQueryRet<T, C> {
48    pub fn into_next_query(self) -> Option<PaginatedQueryArgs<C>>
49    where
50        C: std::fmt::Debug,
51    {
52        if self.has_next_page {
53            Some(PaginatedQueryArgs {
54                first: self.entities.len(),
55                after: self.end_cursor,
56            })
57        } else {
58            None
59        }
60    }
61}