Skip to main content

meztide/api_models/
post.rs

1use chrono::{DateTime, FixedOffset};
2use serde::Deserialize;
3
4use crate::ids::PostId;
5
6use super::{Content, Empty, MinimalAuthorInfo, MinimalCommunityInfo, PollInfo};
7
8#[derive(Debug, Deserialize)]
9pub struct PostInfo {
10    #[serde(flatten)]
11    pub base: PostListPost,
12
13    pub approved: bool,
14    pub rejected: bool,
15    pub local: bool,
16    pub poll: Option<PollInfo>,
17}
18
19impl PartialEq for PostInfo {
20    fn eq(&self, other: &Self) -> bool {
21        self.base.id() == other.base.id()
22    }
23}
24
25impl PostInfo {
26    #[inline]
27    pub fn id(&self) -> PostId {
28        self.base.id()
29    }
30}
31
32#[derive(Debug, Deserialize)]
33pub struct PostListPost {
34    #[serde(flatten)]
35    pub base: MinimalPostInfo,
36
37    #[serde(flatten)]
38    pub content: Content,
39
40    pub href: Option<Box<str>>,
41    pub author: Option<MinimalAuthorInfo>,
42    pub created: DateTime<FixedOffset>,
43    pub community: MinimalCommunityInfo,
44    pub replies_count_total: Option<i64>,
45    pub relevance: Option<f32>,
46    pub score: i64,
47    pub sticky: bool,
48    pub your_vote: Option<Empty>,
49}
50
51impl PartialEq for PostListPost {
52    fn eq(&self, other: &Self) -> bool {
53        self.id() == other.id()
54    }
55}
56
57impl PostListPost {
58    #[inline]
59    pub fn id(&self) -> PostId {
60        self.base.id
61    }
62}
63
64#[derive(Debug, Deserialize)]
65pub struct MinimalPostInfo {
66    pub id: PostId,
67    pub title: Box<str>,
68    pub remote_url: Option<Box<str>>,
69    pub sensitive: bool,
70}