2021-11-03 12:03:56 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2023-04-25 13:49:35 +00:00
|
|
|
use fedimovies_models::markers::types::{DbTimelineMarker, Timeline};
|
2023-03-30 20:27:17 +00:00
|
|
|
|
2021-11-03 12:03:56 +00:00
|
|
|
use crate::errors::ValidationError;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct MarkerQueryParams {
|
|
|
|
#[serde(rename = "timeline[]")]
|
|
|
|
pub timeline: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MarkerQueryParams {
|
|
|
|
pub fn to_timeline(&self) -> Result<Timeline, ValidationError> {
|
|
|
|
let timeline = match self.timeline.as_ref() {
|
|
|
|
"home" => Timeline::Home,
|
|
|
|
"notifications" => Timeline::Notifications,
|
2023-04-26 10:55:42 +00:00
|
|
|
_ => return Err(ValidationError("invalid timeline name".to_string())),
|
2021-11-03 12:03:56 +00:00
|
|
|
};
|
|
|
|
Ok(timeline)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct MarkerCreateData {
|
|
|
|
#[serde(rename = "notifications[last_read_id]")]
|
|
|
|
pub notifications: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// https://docs.joinmastodon.org/entities/marker/
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct Marker {
|
|
|
|
last_read_id: String,
|
|
|
|
version: i32,
|
|
|
|
updated_at: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct Markers {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub notifications: Option<Marker>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<DbTimelineMarker> for Marker {
|
|
|
|
fn from(value: DbTimelineMarker) -> Self {
|
|
|
|
Self {
|
|
|
|
last_read_id: value.last_read_id,
|
|
|
|
version: 0,
|
|
|
|
updated_at: value.updated_at,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|