Coverage Report

Created: 2024-02-20 21:15

/builds/xfbs/cindy/common/src/api/post.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::{hash::*, TagPredicate};
2
use restless::{data::Json, methods::Post, PostRequest, RequestMethod};
3
use serde::{Deserialize, Serialize};
4
use std::borrow::{Borrow, Cow};
5
6
49
#[derive(
S7
erializ
e7
,
D28
eserialize,
Debug0
,
Clone0
,
P0
artialE
q0
, Eq,
P0
artialOr
d0
,
O0
r
d0
,
Hash0
)]
7
pub struct TagValueCreateRequest<'a> {
8
    pub name: Cow<'a, str>,
9
    pub value: Cow<'a, str>,
10
    pub display: Option<Cow<'a, str>>,
11
}
12
13
20
#[derive(
S4
erializ
e4
,
D12
eserialize,
Debug0
,
Clone0
,
P0
artialE
q0
, Eq,
P0
artialOr
d0
,
O0
r
d0
,
Hash0
)]
14
pub struct TagNameCreateRequest<'a> {
15
    pub name: Cow<'a, str>,
16
    pub display: Option<Cow<'a, str>>,
17
}
18
19
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
20
pub struct TagNameCreate<S: Borrow<str>> {
21
    pub name: S,
22
    pub display: Option<S>,
23
}
24
25
impl<S: Borrow<str>> PostRequest for TagNameCreate<S> {
26
    type Request = Json<TagNameCreateRequest<'static>>;
27
28
8
    fn path(&self) -> Cow<'_, str> {
29
8
        "api/v1/tags".into()
30
8
    }
31
32
8
    fn body(&self) -> Self::Request {
33
8
        Json(TagNameCreateRequest {
34
8
            name: self.name.borrow().to_string().into(),
35
8
            display: self
36
8
                .display
37
8
                .as_ref()
38
8
                .map(|value| 
value.borrow().to_string().into()0
),
39
8
        })
40
8
    }
41
}
42
43
impl<S: Borrow<str>> RequestMethod for TagNameCreate<S> {
44
    type Method = Post<Self>;
45
}
46
47
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
48
pub struct TagValueCreate<S: Borrow<str>> {
49
    pub name: S,
50
    pub value: S,
51
    pub display: Option<S>,
52
}
53
54
impl<S: Borrow<str>> PostRequest for TagValueCreate<S> {
55
    type Request = Json<TagValueCreateRequest<'static>>;
56
57
14
    fn path(&self) -> Cow<'_, str> {
58
14
        "api/v1/tags/values".into()
59
14
    }
60
61
14
    fn body(&self) -> Self::Request {
62
14
        Json(TagValueCreateRequest {
63
14
            name: self.name.borrow().to_string().into(),
64
14
            value: self.value.borrow().to_string().into(),
65
14
            display: self
66
14
                .display
67
14
                .as_ref()
68
14
                .map(|value| value.borrow().to_string().into()),
69
14
        })
70
14
    }
71
}
72
73
impl<S: Borrow<str>> RequestMethod for TagValueCreate<S> {
74
    type Method = Post<Self>;
75
}
76
77
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
78
pub struct FileTagCreate<H: Borrow<Hash>, S: Borrow<str>> {
79
    pub hash: H,
80
    pub name: S,
81
    pub value: S,
82
}
83
84
10
#[derive(
S2
erializ
e2
,
D6
eserialize,
Debug0
,
Clone0
,
P0
artialE
q0
, Eq,
P0
artialOr
d0
,
O0
r
d0
,
Hash0
)]
85
pub struct FileTagCreateBody<'a> {
86
    pub name: Cow<'a, str>,
87
    pub value: Cow<'a, str>,
88
}
89
90
impl<H: Borrow<Hash>, S: Borrow<str>> PostRequest for FileTagCreate<H, S> {
91
    type Request = Json<FileTagCreateBody<'static>>;
92
93
4
    fn path(&self) -> Cow<'_, str> {
94
4
        let hash = self.hash.borrow();
95
4
        format!("api/v1/file/{hash}/tags").into()
96
4
    }
97
98
4
    fn body(&self) -> Self::Request {
99
4
        Json(FileTagCreateBody {
100
4
            name: self.name.borrow().to_string().into(),
101
4
            value: self.value.borrow().to_string().into(),
102
4
        })
103
4
    }
104
}
105
106
impl<H: Borrow<Hash>, S: Borrow<str>> RequestMethod for FileTagCreate<H, S> {
107
    type Method = Post<Self>;
108
}
109
110
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
111
pub struct QueryTagCreate<S: Borrow<str>> {
112
    pub query: Vec<TagPredicate<'static>>,
113
    pub name: S,
114
    pub value: S,
115
}
116
117
impl<S: Borrow<str>> PostRequest for QueryTagCreate<S> {
118
    type Request = Json<QueryTagCreate<String>>;
119
120
0
    fn path(&self) -> Cow<'_, str> {
121
0
        "api/v1/query/tags".into()
122
0
    }
123
124
0
    fn body(&self) -> Self::Request {
125
0
        Json(QueryTagCreate {
126
0
            query: self.query.clone(),
127
0
            name: self.name.borrow().into(),
128
0
            value: self.value.borrow().into(),
129
0
        })
130
0
    }
131
}
132
133
impl<S: Borrow<str>> RequestMethod for QueryTagCreate<S> {
134
    type Method = Post<Self>;
135
}