Coverage Report

Created: 2024-02-20 21:15

/builds/xfbs/cindy/common/src/api/patch.rs
Line
Count
Source (jump to first uncovered line)
1
use restless::{data::Json, methods::Patch, PatchRequest, RequestMethod};
2
use serde::{Deserialize, Serialize};
3
use std::borrow::{Borrow, Cow};
4
5
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6
pub struct TagNameEditRequest<'a> {
7
    pub name: Option<Cow<'a, str>>,
8
    pub display: Option<Cow<'a, str>>,
9
}
10
11
0
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12
pub struct TagNameEdit<S: Borrow<str>> {
13
    pub name: S,
14
    pub name_new: Option<S>,
15
    pub display_new: Option<S>,
16
}
17
18
impl<S: Borrow<str>> PatchRequest for TagNameEdit<S> {
19
    type Request = Json<TagNameEditRequest<'static>>;
20
21
0
    fn path(&self) -> Cow<'_, str> {
22
0
        format!("api/v1/tag/{}", self.name.borrow()).into()
23
0
    }
24
25
0
    fn body(&self) -> Self::Request {
26
0
        Json(TagNameEditRequest {
27
0
            name: self
28
0
                .name_new
29
0
                .as_ref()
30
0
                .map(|value| value.borrow().to_string().into()),
31
0
            display: self
32
0
                .display_new
33
0
                .as_ref()
34
0
                .map(|value| value.borrow().to_string().into()),
35
0
        })
36
0
    }
37
}
38
39
impl<S: Borrow<str>> RequestMethod for TagNameEdit<S> {
40
    type Method = Patch<Self>;
41
}