misskey_api/endpoint/admin/announcements/
create.rs

1use crate::model::announcement::Announcement;
2
3use serde::Serialize;
4use typed_builder::TypedBuilder;
5use url::Url;
6
7#[derive(Serialize, Debug, Clone, TypedBuilder)]
8#[serde(rename_all = "camelCase")]
9#[builder(doc)]
10pub struct Request {
11    #[builder(setter(into))]
12    pub title: String,
13    #[builder(setter(into))]
14    pub text: String,
15    #[builder(default, setter(strip_option))]
16    pub image_url: Option<Url>,
17}
18
19impl misskey_core::Request for Request {
20    type Response = Announcement;
21    const ENDPOINT: &'static str = "admin/announcements/create";
22}
23
24#[cfg(test)]
25mod tests {
26    use super::Request;
27    use crate::test::{ClientExt, TestClient};
28
29    #[tokio::test]
30    async fn request() {
31        let client = TestClient::new();
32        client
33            .admin
34            .test(Request {
35                title: "attention".to_string(),
36                text: "hello".to_string(),
37                image_url: None,
38            })
39            .await;
40    }
41
42    #[tokio::test]
43    async fn request_with_image() {
44        let client = TestClient::new();
45        let image_url = client.avatar_url().await;
46
47        client
48            .admin
49            .test(Request {
50                title: "hey".to_string(),
51                text: "ok".to_string(),
52                image_url: Some(image_url),
53            })
54            .await;
55    }
56}