Make meal fetching respect pagination

This commit is contained in:
Malte Tammena 2021-10-22 17:05:13 +02:00
parent 0fe0494e94
commit 9339f52755
2 changed files with 6 additions and 6 deletions

View file

@ -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 {

View file

@ -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,
})
}
}
}