1use std::collections::BTreeSet;
2use std::time::{SystemTime, UNIX_EPOCH};
3
4use serde::Serialize;
5
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
7pub struct BookmarkId(pub String);
8
9impl BookmarkId {
10 pub fn new() -> Self {
11 Self(ulid::Ulid::new().to_string())
12 }
13
14 pub fn as_str(&self) -> &str {
15 &self.0
16 }
17}
18
19impl Default for BookmarkId {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24
25impl std::fmt::Display for BookmarkId {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 write!(f, "{}", self.0)
28 }
29}
30
31impl From<String> for BookmarkId {
32 fn from(s: String) -> Self {
33 Self(s)
34 }
35}
36
37impl From<&str> for BookmarkId {
38 fn from(s: &str) -> Self {
39 Self(s.to_string())
40 }
41}
42
43pub fn now_ts() -> i64 {
44 SystemTime::now()
45 .duration_since(UNIX_EPOCH)
46 .unwrap_or_default()
47 .as_secs() as i64
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
51pub struct Bookmark {
52 pub id: BookmarkId,
53 pub url: String,
54 pub title: String,
55 pub desc: String,
56 pub tags: BTreeSet<String>,
57 pub flags: i64,
58 pub created_at: i64,
59 pub updated_at: i64,
60}
61
62#[derive(Debug, Clone, Default)]
63pub struct BookmarkPatch {
64 pub url: Option<String>,
65 pub title: Option<String>,
66 pub desc: Option<String>,
67 pub flags: Option<i64>,
68}