fix: add visitor_data to recommendation paginator
This commit is contained in:
parent
39fca50731
commit
3a0db09e23
18 changed files with 155 additions and 124 deletions
|
|
@ -4,7 +4,6 @@ mod ordering;
|
|||
mod paginator;
|
||||
pub mod richtext;
|
||||
|
||||
pub use paginator::ContinuationEndpoint;
|
||||
pub use paginator::Paginator;
|
||||
|
||||
use std::ops::Range;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ use std::convert::TryInto;
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::param::ContinuationEndpoint;
|
||||
|
||||
/// Wrapper around progressively fetched items
|
||||
///
|
||||
/// The paginator is a wrapper around a list of items that are fetched
|
||||
|
|
@ -35,24 +37,6 @@ pub struct Paginator<T> {
|
|||
pub endpoint: ContinuationEndpoint,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ContinuationEndpoint {
|
||||
Browse,
|
||||
Search,
|
||||
Next,
|
||||
}
|
||||
|
||||
impl ContinuationEndpoint {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
ContinuationEndpoint::Browse => "browse",
|
||||
ContinuationEndpoint::Search => "search",
|
||||
ContinuationEndpoint::Next => "next",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Paginator<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -67,31 +51,14 @@ impl<T> Default for Paginator<T> {
|
|||
|
||||
impl<T> Paginator<T> {
|
||||
pub(crate) fn new(count: Option<u64>, items: Vec<T>, ctoken: Option<String>) -> Self {
|
||||
Self::new_with_vdata(count, items, ctoken, None)
|
||||
Self::new_ext(count, items, ctoken, None, ContinuationEndpoint::Browse)
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_vdata(
|
||||
pub(crate) fn new_ext(
|
||||
count: Option<u64>,
|
||||
items: Vec<T>,
|
||||
ctoken: Option<String>,
|
||||
visitor_data: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
count: match ctoken {
|
||||
Some(_) => count,
|
||||
None => items.len().try_into().ok(),
|
||||
},
|
||||
items,
|
||||
ctoken,
|
||||
visitor_data,
|
||||
endpoint: ContinuationEndpoint::Browse,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_endpoint(
|
||||
count: Option<u64>,
|
||||
items: Vec<T>,
|
||||
ctoken: Option<String>,
|
||||
endpoint: ContinuationEndpoint,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
|
@ -101,7 +68,7 @@ impl<T> Paginator<T> {
|
|||
},
|
||||
items,
|
||||
ctoken,
|
||||
visitor_data: None,
|
||||
visitor_data,
|
||||
endpoint,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue