misskey_api/endpoint/i/
favorites.rs

1use crate::model::{id::Id, note_favorite::NoteFavorite};
2
3use serde::Serialize;
4use typed_builder::TypedBuilder;
5
6#[derive(Serialize, Default, Debug, Clone, TypedBuilder)]
7#[serde(rename_all = "camelCase")]
8#[builder(doc)]
9pub struct Request {
10    /// 1 .. 100
11    #[serde(skip_serializing_if = "Option::is_none")]
12    #[builder(default, setter(strip_option))]
13    pub limit: Option<u8>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    #[builder(default, setter(strip_option))]
16    pub since_id: Option<Id<NoteFavorite>>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[builder(default, setter(strip_option))]
19    pub until_id: Option<Id<NoteFavorite>>,
20}
21
22impl misskey_core::Request for Request {
23    type Response = Vec<NoteFavorite>;
24    const ENDPOINT: &'static str = "i/favorites";
25}
26
27impl_pagination!(Request, NoteFavorite);
28
29#[cfg(test)]
30mod tests {
31    use super::Request;
32    use crate::test::{ClientExt, TestClient};
33
34    #[tokio::test]
35    async fn request() {
36        let client = TestClient::new();
37        client.test(Request::default()).await;
38    }
39
40    #[tokio::test]
41    async fn request_with_limit() {
42        let client = TestClient::new();
43        client
44            .test(Request {
45                limit: Some(100),
46                since_id: None,
47                until_id: None,
48            })
49            .await;
50    }
51
52    #[tokio::test]
53    async fn request_paginate() {
54        let client = TestClient::new();
55        let note = client.admin.create_note(Some("test"), None, None).await;
56        client
57            .user
58            .test(crate::endpoint::notes::favorites::create::Request { note_id: note.id })
59            .await;
60
61        let favorites = client
62            .test(Request {
63                limit: None,
64                since_id: None,
65                until_id: None,
66            })
67            .await;
68
69        client
70            .test(Request {
71                limit: None,
72                since_id: Some(favorites[0].id.clone()),
73                until_id: Some(favorites[0].id.clone()),
74            })
75            .await;
76    }
77}