1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::Entry;
use crate::utils::serde::bool_to_int;
#[derive(Deserialize, Serialize, Debug)]
pub struct PatchEntry {
pub title: Option<String>,
pub tags: Option<Vec<String>>,
#[serde(serialize_with = "bool_to_int")]
pub archive: Option<bool>,
#[serde(serialize_with = "bool_to_int")]
pub starred: Option<bool>,
#[serde(serialize_with = "bool_to_int")]
pub public: Option<bool>,
pub content: Option<String>,
pub language: Option<String>,
pub preview_picture: Option<String>,
pub published_at: Option<DateTime<Utc>>,
pub authors: Option<String>,
pub origin_url: Option<String>,
}
impl Default for PatchEntry {
fn default() -> Self {
Self {
title: None,
tags: None,
archive: None,
starred: None,
public: None,
content: None,
language: None,
preview_picture: None,
published_at: None,
authors: None,
origin_url: None,
}
}
}
impl From<&Entry> for PatchEntry {
fn from(entry: &Entry) -> Self {
let tags: Vec<String> = entry.tags.iter().map(|t| t.label.clone()).collect();
Self {
title: entry.title.clone(),
tags: Some(tags),
archive: Some(entry.is_archived),
starred: Some(entry.is_starred),
public: Some(entry.is_public),
content: entry.content.clone(),
language: entry.language.clone(),
preview_picture: entry.preview_picture.clone(),
published_at: entry.published_at,
authors: None,
origin_url: entry.origin_url.clone(),
}
}
}