modio/request/mods/comments/
update_mod_comment_karma.rs

1use std::future::IntoFuture;
2
3use serde_derive::Serialize;
4
5use crate::client::Client;
6use crate::request::{Output, RequestBuilder, Route};
7use crate::response::ResponseFuture;
8use crate::types::id::{CommentId, GameId, ModId};
9use crate::types::mods::Comment;
10
11/// Update the Karma rating in single increments or decrements for a mod comment.
12pub struct UpdateModCommentKarma<'a> {
13    http: &'a Client,
14    game_id: GameId,
15    mod_id: ModId,
16    comment_id: CommentId,
17    fields: UpdateModCommentKarmaFields,
18}
19
20#[derive(Serialize)]
21struct UpdateModCommentKarmaFields {
22    karma: i8,
23}
24
25impl<'a> UpdateModCommentKarma<'a> {
26    pub(crate) const fn new(
27        http: &'a Client,
28        game_id: GameId,
29        mod_id: ModId,
30        comment_id: CommentId,
31    ) -> Self {
32        Self {
33            http,
34            game_id,
35            mod_id,
36            comment_id,
37            fields: UpdateModCommentKarmaFields { karma: 1 },
38        }
39    }
40
41    pub const fn positive(mut self) -> Self {
42        self.fields.karma = 1;
43        self
44    }
45
46    pub const fn negative(mut self) -> Self {
47        self.fields.karma = -1;
48        self
49    }
50}
51
52impl IntoFuture for UpdateModCommentKarma<'_> {
53    type Output = Output<Comment>;
54    type IntoFuture = ResponseFuture<Comment>;
55
56    fn into_future(self) -> Self::IntoFuture {
57        let route = Route::UpdateModCommentKarma {
58            game_id: self.game_id,
59            mod_id: self.mod_id,
60            comment_id: self.comment_id,
61        };
62        match RequestBuilder::from_route(&route).form(&self.fields) {
63            Ok(req) => self.http.request(req),
64            Err(err) => ResponseFuture::failed(err),
65        }
66    }
67}