Coverage Report

Created: 2024-02-20 21:15

/builds/xfbs/cindy/common/src/api/delete.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::{api::TagQuery, hash::*, tag::TagPredicate};
2
use restless::{methods::Delete, query::Qs, DeleteRequest, RequestMethod};
3
use serde::{Deserialize, Serialize};
4
use std::borrow::{Borrow, Cow};
5
6
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7
pub struct TagDelete<S: Borrow<str>> {
8
    pub name: Option<S>,
9
    pub value: Option<S>,
10
}
11
12
impl<S: Borrow<str>> DeleteRequest for TagDelete<S> {
13
    type Query = Qs<TagQuery<String>>;
14
15
4
    fn path(&self) -> Cow<'_, str> {
16
4
        "api/v1/tags/values".into()
17
4
    }
18
19
4
    fn query(&self) -> Self::Query {
20
4
        TagQuery {
21
4
            name: self.name.as_ref().map(Borrow::borrow).map(Into::into),
22
4
            value: self.value.as_ref().map(Borrow::borrow).map(Into::into),
23
4
        }
24
4
        .into()
25
4
    }
26
}
27
28
impl<S: Borrow<str>> RequestMethod for TagDelete<S> {
29
    type Method = Delete<Self>;
30
}
31
32
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
33
pub struct FileTagDelete<H: Borrow<Hash>, S: Borrow<str>> {
34
    pub hash: H,
35
    pub name: Option<S>,
36
    pub value: Option<S>,
37
}
38
39
impl<H: Borrow<Hash>, S: Borrow<str>> DeleteRequest for FileTagDelete<H, S> {
40
    type Query = Qs<TagQuery<String>>;
41
42
2
    fn path(&self) -> Cow<'_, str> {
43
2
        let hash = self.hash.borrow();
44
2
        format!("api/v1/file/{hash}/tags").into()
45
2
    }
46
47
2
    fn query(&self) -> Self::Query {
48
2
        TagQuery {
49
2
            name: self.name.as_ref().map(Borrow::borrow).map(Into::into),
50
2
            value: self.value.as_ref().map(Borrow::borrow).map(Into::into),
51
2
        }
52
2
        .into()
53
2
    }
54
}
55
56
impl<H: Borrow<Hash>, S: Borrow<str>> RequestMethod for FileTagDelete<H, S> {
57
    type Method = Delete<Self>;
58
}
59
60
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
61
pub struct QueryTagRemove<S: Borrow<str>> {
62
    pub query: Vec<TagPredicate<'static>>,
63
    pub name: Option<S>,
64
    pub value: Option<S>,
65
}
66
67
impl<S: Borrow<str>> DeleteRequest for QueryTagRemove<S> {
68
    type Query = Qs<QueryTagRemove<String>>;
69
70
0
    fn path(&self) -> Cow<'_, str> {
71
0
        "api/v1/query/tags".into()
72
0
    }
73
74
0
    fn query(&self) -> Self::Query {
75
0
        QueryTagRemove {
76
0
            query: self.query.clone(),
77
0
            name: self.name.as_ref().map(|n| n.borrow().into()),
78
0
            value: self.value.as_ref().map(|n| n.borrow().into()),
79
0
        }
80
0
        .into()
81
0
    }
82
}
83
84
impl<S: Borrow<str>> RequestMethod for QueryTagRemove<S> {
85
    type Method = Delete<Self>;
86
}