modio/request/mods/
submit_mod_rating.rs1use 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::{GameId, ModId};
9use crate::types::Message;
10
11pub struct SubmitModRating<'a> {
13 http: &'a Client,
14 game_id: GameId,
15 mod_id: ModId,
16 fields: AddModRatingFields,
17}
18
19#[derive(Serialize)]
20struct AddModRatingFields {
21 rating: i8,
22}
23
24impl<'a> SubmitModRating<'a> {
25 pub(crate) const fn new(http: &'a Client, game_id: GameId, mod_id: ModId) -> Self {
26 Self {
27 http,
28 game_id,
29 mod_id,
30 fields: AddModRatingFields { rating: 1 },
31 }
32 }
33
34 pub const fn positive(mut self) -> Self {
35 self.fields.rating = 1;
36 self
37 }
38
39 pub const fn negative(mut self) -> Self {
40 self.fields.rating = -1;
41 self
42 }
43
44 pub const fn reset(mut self) -> Self {
45 self.fields.rating = 0;
46 self
47 }
48}
49
50impl IntoFuture for SubmitModRating<'_> {
51 type Output = Output<Message>;
52 type IntoFuture = ResponseFuture<Message>;
53
54 fn into_future(self) -> Self::IntoFuture {
55 let route = Route::RateMod {
56 game_id: self.game_id,
57 mod_id: self.mod_id,
58 };
59 match RequestBuilder::from_route(&route).form(&self.fields) {
60 Ok(req) => self.http.request(req),
61 Err(err) => ResponseFuture::failed(err),
62 }
63 }
64}