use crate::request::context::RequestContext;
use std::collections::{HashMap, HashSet};
use std::fmt::Display;
pub trait ViewTrait: Display {
fn get_object(&self) -> &'static str;
}
#[derive(Default)]
pub struct ViewStorage {
storage: HashMap<&'static str, HashSet<String>>,
}
impl ViewStorage {
pub fn add_view(&mut self, view: impl ViewTrait) {
self.storage
.entry(view.get_object())
.or_default()
.insert(view.to_string());
}
pub fn build_query_drain(&mut self, request_context: &mut RequestContext) {
for (object, extend) in self.storage.drain() {
request_context.query.push((
format!("views[{}]", object),
extend.into_iter().collect::<Vec<_>>().join(","),
));
}
}
}