-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OSS-118] Support for pagination (#53)
- Loading branch information
1 parent
a3d496a
commit 33886a5
Showing
7 changed files
with
389 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
mod _generic; | ||
pub mod binding; | ||
pub mod connection; | ||
pub mod exchange; | ||
pub mod message; | ||
pub mod node; | ||
pub mod overview; | ||
mod pagination; | ||
pub mod permission; | ||
pub mod policy; | ||
pub mod queue; | ||
pub mod user; | ||
pub mod vhost; | ||
|
||
pub use pagination::{RabbitMqPaginatedResponse, RabbitMqPagination, RabbitMqPaginationFilter}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
const PAGINATION_PAGE_SIZE: u32 = 50; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RabbitMqPagination { | ||
pub page: u32, | ||
pub page_size: Option<u32>, | ||
pub filter: Option<RabbitMqPaginationFilter>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum RabbitMqPaginationFilter { | ||
StringFilter(String), | ||
RegexFilter(String), | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize)] | ||
pub struct RabbitMqPaginationRequest { | ||
pub page: u32, | ||
pub page_size: u32, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub name: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub use_regex: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct RabbitMqPaginatedResponse<T> { | ||
pub filtered_count: u32, | ||
pub item_count: u32, | ||
pub items: Vec<T>, | ||
pub page: u32, | ||
pub page_count: u32, | ||
pub page_size: u32, | ||
pub total_count: u32, | ||
} | ||
|
||
impl Default for RabbitMqPagination { | ||
fn default() -> Self { | ||
Self { | ||
page: 1, | ||
page_size: None, | ||
filter: None, | ||
} | ||
} | ||
} | ||
|
||
impl From<RabbitMqPagination> for RabbitMqPaginationRequest { | ||
fn from(value: RabbitMqPagination) -> Self { | ||
let (name, use_regex) = match value.filter { | ||
None => (None, None), | ||
Some(f) => match f { | ||
RabbitMqPaginationFilter::StringFilter(s) => (Some(s), Some(false)), | ||
RabbitMqPaginationFilter::RegexFilter(r) => (Some(r), Some(true)), | ||
}, | ||
}; | ||
|
||
Self { | ||
page: value.page, | ||
page_size: value.page_size.unwrap_or(PAGINATION_PAGE_SIZE), | ||
name, | ||
use_regex, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.