mirror of
https://github.com/MalteT/mensa.git
synced 2024-10-22 21:59:17 +02:00
Make meal fetching respect pagination
This commit is contained in:
parent
0fe0494e94
commit
9339f52755
|
@ -176,13 +176,13 @@ impl Canteen {
|
|||
ENDPOINT, lat, long, geo.radius,
|
||||
)
|
||||
};
|
||||
PaginatedList::new(url, *TTL_CANTEENS)?.consume()
|
||||
PaginatedList::new(url, *TTL_CANTEENS).consume()
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch_dates_for_canteen(id: CanteenId) -> Result<HashMap<NaiveDate, Fetchable<Vec<Meal>>>> {
|
||||
let url = format!("{}/canteens/{}/days", ENDPOINT, id,);
|
||||
let days: Vec<Day> = fetch_json(url, *TTL_MEALS)?;
|
||||
let days: Vec<Day> = PaginatedList::new(url, *TTL_MEALS).consume()?;
|
||||
Ok(days
|
||||
.into_iter()
|
||||
.map(|day| (day.date, Fetchable::None))
|
||||
|
@ -191,7 +191,7 @@ fn fetch_dates_for_canteen(id: CanteenId) -> Result<HashMap<NaiveDate, Fetchable
|
|||
|
||||
fn fetch_meals(id: CanteenId, date: &NaiveDate) -> Result<Vec<Meal>> {
|
||||
let url = format!("{}/canteens/{}/days/{}/meals", ENDPOINT, id, date);
|
||||
fetch_json(url, *TTL_MEALS)
|
||||
PaginatedList::new(url, *TTL_MEALS).consume()
|
||||
}
|
||||
|
||||
impl From<CanteenId> for Canteen {
|
||||
|
|
|
@ -47,12 +47,12 @@ where
|
|||
///
|
||||
/// Takes the `url` for the first page and a
|
||||
/// `local_ttl` for the cached values.
|
||||
pub fn new<S: AsRef<str>>(url: S, ttl: Duration) -> Result<Self> {
|
||||
Ok(PaginatedList {
|
||||
pub fn new<S: AsRef<str>>(url: S, ttl: Duration) -> Self {
|
||||
PaginatedList {
|
||||
ttl,
|
||||
next_page: Some(url.as_ref().into()),
|
||||
__item: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue