rosu_v2/request/
forum.rs

1use crate::{
2    model::forum::ForumPosts,
3    request::{Query, Request},
4    routing::Route,
5    Osu,
6};
7
8use serde::Serialize;
9
10/// Get a [`ForumPosts`] struct for a forum topic
11#[must_use = "requests must be configured and executed"]
12#[derive(Serialize)]
13pub struct GetForumPosts<'a> {
14    #[serde(skip)]
15    osu: &'a Osu,
16    #[serde(skip)]
17    topic_id: u64,
18    sort: Option<&'static str>,
19    limit: Option<usize>,
20    start: Option<u64>,
21    end: Option<u64>,
22    #[serde(rename = "cursor_string")]
23    cursor: Option<&'a str>,
24}
25
26impl<'a> GetForumPosts<'a> {
27    pub(crate) const fn new(osu: &'a Osu, topic_id: u64) -> Self {
28        Self {
29            osu,
30            topic_id,
31            sort: None,
32            limit: None,
33            start: None,
34            end: None,
35            cursor: None,
36        }
37    }
38
39    /// Maximum number of posts to be returned (20 default, 50 at most)
40    #[inline]
41    pub fn limit(mut self, limit: usize) -> Self {
42        self.limit = Some(limit.min(50));
43
44        self
45    }
46
47    /// Sort by ascending post ids. This is the default.
48    #[inline]
49    pub const fn sort_ascending(mut self) -> Self {
50        self.sort = Some("id_asc");
51
52        self
53    }
54
55    /// Sort by descending post ids
56    #[inline]
57    pub const fn sort_descending(mut self) -> Self {
58        self.sort = Some("id_desc");
59
60        self
61    }
62
63    /// First post id to be returned if sorted ascendingly.
64    /// Parameter is ignored if `cursor` is specified.
65    #[inline]
66    pub const fn start_id(mut self, start: u64) -> Self {
67        self.start = Some(start);
68
69        self
70    }
71
72    /// First post id to be returned if sorted descendingly.
73    /// Parameter is ignored if `cursor` is specified.
74    #[inline]
75    pub const fn end_id(mut self, end: u64) -> Self {
76        self.end = Some(end);
77
78        self
79    }
80
81    /// Specify a page by providing a cursor
82    #[inline]
83    pub const fn cursor(mut self, cursor: &'a str) -> Self {
84        self.cursor = Some(cursor);
85
86        self
87    }
88}
89
90into_future! {
91    |self: GetForumPosts<'_>| -> ForumPosts {
92        Request::with_query(
93            Route::GetForumPosts { topic_id: self.topic_id },
94            Query::encode(&self),
95        )
96    }
97}