rosu_v2/request/
comments.rs1use crate::{
2 model::comments::{CommentBundle, CommentSort},
3 request::{serialize::maybe_comment_sort, Query, Request},
4 routing::Route,
5 Osu,
6};
7
8use serde::Serialize;
9
10#[must_use = "requests must be configured and executed"]
13#[derive(Serialize)]
14pub struct GetComments<'a> {
15 #[serde(skip)]
16 osu: &'a Osu,
17 commentable_type: Option<String>,
18 commentable_id: Option<u32>,
19 parent_id: Option<u32>,
20 #[serde(serialize_with = "maybe_comment_sort")]
21 sort: Option<CommentSort>,
22 #[serde(rename = "cursor_string")]
23 cursor: Option<&'a str>,
24}
25
26impl<'a> GetComments<'a> {
27 pub(crate) const fn new(osu: &'a Osu) -> Self {
28 Self {
29 osu,
30 commentable_type: None,
31 commentable_id: None,
32 parent_id: None,
33 sort: None,
34 cursor: None,
35 }
36 }
37
38 #[inline]
40 pub const fn sort_new(mut self) -> Self {
41 self.sort = Some(CommentSort::New);
42
43 self
44 }
45
46 #[inline]
48 pub const fn sort_top(mut self) -> Self {
49 self.sort = Some(CommentSort::Top);
50
51 self
52 }
53
54 #[inline]
56 pub const fn sort_old(mut self) -> Self {
57 self.sort = Some(CommentSort::Old);
58
59 self
60 }
61
62 #[inline]
64 pub const fn parent(mut self, parent_id: u32) -> Self {
65 self.parent_id = Some(parent_id);
66
67 self
68 }
69
70 #[inline]
72 pub const fn commentable_id(mut self, commentable_id: u32) -> Self {
73 self.commentable_id = Some(commentable_id);
74
75 self
76 }
77
78 #[inline]
80 pub fn commentable_type(mut self, commentable_type: impl Into<String>) -> Self {
81 self.commentable_type = Some(commentable_type.into());
82
83 self
84 }
85
86 #[inline]
87 pub(crate) const fn cursor(mut self, cursor: &'a str) -> Self {
88 self.cursor = Some(cursor);
89
90 self
91 }
92}
93
94into_future! {
95 |self: GetComments<'_>| -> CommentBundle {
96 Request::with_query(Route::GetComments, Query::encode(&self))
97 }
98}