mirror of
https://github.com/alvierahman90/rabbit.git
synced 2024-12-15 02:51:59 +00:00
implement get_series for JsonDb
This commit is contained in:
parent
eebbef6782
commit
bd8266b795
@ -29,8 +29,8 @@ pub trait Storage {
|
||||
fn add_series_point(&mut self, category_id: i32, series_id: i32, series_point: NewSeriesPoint) -> Result<i32, Error>;
|
||||
//fn add_user(&mut self, id: i32, user: NewUser) -> Result<User, Error>;
|
||||
fn get_category(&self, id: i32) -> Option<Category>;
|
||||
//fn get_series(&self, id: i32) -> Result<Series, Error>;
|
||||
//fn get_user(&self, id: i32) -> Result<User, Error>;
|
||||
fn get_series(&self, category_id: i32, series_id: i32) -> Option<Series>;
|
||||
//fn get_user(&self, id: i32) -> Option<User>;
|
||||
//fn update_category(&mut self, id: i32, changeset: CategoryChangeset) -> Result<(), Error>;
|
||||
//fn update_series(&mut self, id: i32, changeset: SeriesChangeset) -> Result<(), Error>;
|
||||
//fn update_user(&mut self, id: i32, changeset: UserChangeset) -> Result<(), Error>;
|
||||
|
@ -133,4 +133,25 @@ impl Storage for JsonDb {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn get_series(&self, category_id: i32, series_id: i32) -> Option<Series> {
|
||||
let data = self.load().ok()?;
|
||||
let mut cat: Option<Category> = None;
|
||||
|
||||
for cat_opt in data {
|
||||
if cat_opt.id == category_id {
|
||||
cat = Some(cat_opt);
|
||||
}
|
||||
}
|
||||
|
||||
let cat = cat.unwrap();
|
||||
|
||||
for series_opt in cat.series {
|
||||
if series_opt.id == series_id {
|
||||
return Some(series_opt)
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user