dandanapi/structs/
method.rs

1use std::borrow::Cow;
2
3use crate::Request;
4
5use super::{
6    CommentResponse,
7    MatchRequest,
8    MatchResult,
9    RequestComments,
10    RequestEpisodes,
11    SearchEpisodesResponse,
12};
13
14pub struct Match(pub MatchRequest);
15
16impl Request for Match {
17    type Response = MatchResult;
18    type Body = MatchRequest;
19    type Params = ();
20    const PATH: &'static str = "/api/v2/match";
21    const METHOD: reqwest::Method = reqwest::Method::POST;
22
23    fn body(&self) -> Option<&Self::Body> {
24        Some(&self.0)
25    }
26}
27
28pub struct Episodes(pub RequestEpisodes);
29
30impl Request for Episodes {
31    type Response = SearchEpisodesResponse;
32    type Body = ();
33    type Params = RequestEpisodes;
34    const PATH: &'static str = "/api/v2/search/episodes";
35
36    fn params(&self) -> Option<&Self::Params> {
37        Some(&self.0)
38    }
39}
40
41pub struct Comments {
42    pub episode_id: i64,
43    pub request_comments: RequestComments,
44}
45
46impl Request for Comments {
47    type Response = CommentResponse;
48    type Body = ();
49    type Params = RequestComments;
50    const PATH: &'static str = "/api/v2/comment";
51
52    fn params(&self) -> Option<&Self::Params> {
53        Some(&self.request_comments)
54    }
55
56    fn path(&self) -> Cow<'static, str> {
57        Cow::Owned(format!("{}/{}", Self::PATH, self.episode_id))
58    }
59}