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
use crate::model::{announcement::Announcement, id::Id};

use serde::Serialize;
use typed_builder::TypedBuilder;
use url::Url;

#[derive(Serialize, Debug, Clone, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[builder(doc)]
pub struct Request {
    pub id: Id<Announcement>,
    #[builder(setter(into))]
    pub title: String,
    #[builder(setter(into))]
    pub text: String,
    #[builder(default, setter(strip_option))]
    pub image_url: Option<Url>,
}

impl misskey_core::Request for Request {
    type Response = ();
    const ENDPOINT: &'static str = "admin/announcements/update";
}

#[cfg(test)]
mod tests {
    use super::Request;
    use crate::test::{ClientExt, TestClient};

    #[tokio::test]
    async fn request() {
        let client = TestClient::new();
        let announcement = client
            .admin
            .test(crate::endpoint::admin::announcements::create::Request {
                title: "hello".to_string(),
                text: "ok".to_string(),
                image_url: None,
            })
            .await;

        client
            .admin
            .test(Request {
                id: announcement.id,
                title: "attention".to_string(),
                text: "hello".to_string(),
                image_url: None,
            })
            .await;
    }

    #[tokio::test]
    async fn request_with_image() {
        let client = TestClient::new();
        let announcement = client
            .admin
            .test(crate::endpoint::admin::announcements::create::Request {
                title: "hello".to_string(),
                text: "ok".to_string(),
                image_url: None,
            })
            .await;
        let image_url = client.avatar_url().await;

        client
            .admin
            .test(Request {
                id: announcement.id,
                title: "hey".to_string(),
                text: "ok".to_string(),
                image_url: Some(image_url),
            })
            .await;
    }
}