hdk_crud/datetime_queries/
fetch_by_time.rs

1use crate::datetime_queries::inputs::FetchEntriesTime;
2use crate::wire_record::WireRecord;
3use hdk::prelude::*;
4
5#[cfg(not(feature = "mock"))]
6use crate::datetime_queries::fetch_by_day::FetchByDay;
7#[cfg(not(feature = "mock"))]
8use crate::datetime_queries::fetch_by_hour::FetchByHour;
9#[cfg(not(feature = "mock"))]
10use crate::retrieval::get_latest_for_entry::GetLatestEntry;
11
12#[cfg(feature = "mock")]
13use crate::datetime_queries::fetch_by_day::MockFetchByDay as FetchByDay;
14#[cfg(feature = "mock")]
15use crate::datetime_queries::fetch_by_hour::MockFetchByHour as FetchByHour;
16#[cfg(feature = "mock")]
17use crate::retrieval::get_latest_for_entry::MockGetLatestEntry as GetLatestEntry;
18
19/// fetches all entries linked to a time path index for either a specific day or hour of a day
20pub fn fetch_entries_by_time<
21    EntryType: 'static + TryFrom<SerializedBytes, Error = SerializedBytesError>,
22    TY,
23    E,
24>(
25    fetch_by_day: &FetchByDay,
26    fetch_by_hour: &FetchByHour,
27    get_latest_entry: &GetLatestEntry,
28    link_type_filter: LinkTypeFilter,
29    link_type: TY,
30    time: FetchEntriesTime,
31    base_component: String,
32) -> Result<Vec<WireRecord<EntryType>>, WasmError>
33where
34    ScopedLinkType: TryFrom<TY, Error = E>,
35    TY: Clone,
36    WasmError: From<E>,
37{
38    Ok(match time.hour {
39        None => fetch_by_day.fetch_entries_by_day(
40            &fetch_by_hour,
41            &get_latest_entry,
42            link_type_filter,
43            link_type,
44            time,
45            base_component,
46        ),
47        Some(h) => fetch_by_hour.fetch_entries_by_hour(
48            &get_latest_entry,
49            link_type_filter,
50            link_type,
51            time.year,
52            time.month,
53            time.day,
54            h,
55            base_component,
56        ),
57    }?)
58}