use crate::{
cdk::types::Principal,
dto::{
page::{Page, PageRequest},
topology::IndexEntryResponse,
},
ids::CanisterRole,
ops::storage::index::{app::AppIndexOps, mapper::IndexEntryMapper, subnet::SubnetIndexOps},
view::topology::IndexEntryView,
workflow::view::paginate::paginate_vec,
};
pub struct AppIndexQuery;
impl AppIndexQuery {
#[must_use]
pub fn get(role: CanisterRole) -> Option<Principal> {
AppIndexOps::get(&role)
}
#[must_use]
pub fn page(page: PageRequest) -> Page<IndexEntryResponse> {
index_page(AppIndexOps::entry_projections(), page)
}
}
pub struct SubnetIndexQuery;
impl SubnetIndexQuery {
#[must_use]
pub fn get(role: CanisterRole) -> Option<Principal> {
SubnetIndexOps::get(&role)
}
#[must_use]
pub fn page(page: PageRequest) -> Page<IndexEntryResponse> {
index_page(SubnetIndexOps::entry_projections(), page)
}
}
fn index_page(entries: Vec<IndexEntryView>, page: PageRequest) -> Page<IndexEntryResponse> {
IndexEntryMapper::projection_page_to_response(paginate_vec(entries, page))
}