modio/request/mods/comments/
get_mod_comments.rs1use std::future::IntoFuture;
2
3use crate::client::Client;
4use crate::request::{Filter, Output, RequestBuilder, Route};
5use crate::response::ResponseFuture;
6use crate::types::id::{GameId, ModId};
7use crate::types::mods::Comment;
8use crate::types::List;
9use crate::util::{Paginate, Paginator};
10
11pub struct GetModComments<'a> {
13 http: &'a Client,
14 game_id: GameId,
15 mod_id: ModId,
16 filter: Option<Filter>,
17}
18
19impl<'a> GetModComments<'a> {
20 pub(crate) const fn new(http: &'a Client, game_id: GameId, mod_id: ModId) -> Self {
21 Self {
22 http,
23 game_id,
24 mod_id,
25 filter: None,
26 }
27 }
28
29 pub fn filter(mut self, filter: Filter) -> Self {
30 self.filter = Some(filter);
31 self
32 }
33}
34
35impl IntoFuture for GetModComments<'_> {
36 type Output = Output<List<Comment>>;
37 type IntoFuture = ResponseFuture<List<Comment>>;
38
39 fn into_future(self) -> Self::IntoFuture {
40 let route = Route::GetModComments {
41 game_id: self.game_id,
42 mod_id: self.mod_id,
43 };
44 let mut builder = RequestBuilder::from_route(&route);
45 if let Some(filter) = self.filter {
46 builder = builder.filter(filter);
47 }
48 match builder.empty() {
49 Ok(req) => self.http.request(req),
50 Err(err) => ResponseFuture::failed(err),
51 }
52 }
53}
54
55impl<'a> Paginate<'a> for GetModComments<'a> {
56 type Output = Comment;
57
58 fn paged(&'a self) -> Paginator<'a, Self::Output> {
59 let route = Route::GetModComments {
60 game_id: self.game_id,
61 mod_id: self.mod_id,
62 };
63 Paginator::new(self.http, route, self.filter.clone())
64 }
65}