gitea_sdk/api/issues/comments/
list.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{error::Result, model::issues::Comment, Client};
5
6#[derive(Debug, Clone, Builder, Serialize)]
7#[build_it(into)]
8pub struct ListAllCommentsBuilder {
9    #[serde(skip)]
10    #[build_it(skip)]
11    owner: String,
12    #[serde(skip)]
13    #[build_it(skip)]
14    repo: String,
15
16    /// If provided, only comments updated since the provided time are returned.
17    since: Option<String>,
18    /// If provided, only comments updated before the provided time are returned.
19    before: Option<String>,
20    /// Page number of results to return (1-based).
21    page: Option<i64>,
22    /// Page size of results
23    limit: Option<i64>,
24}
25
26#[derive(Debug, Clone, Builder, Serialize)]
27#[build_it(into)]
28pub struct ListCommentsBuilder {
29    #[serde(skip)]
30    #[build_it(skip)]
31    owner: String,
32    #[serde(skip)]
33    #[build_it(skip)]
34    repo: String,
35    #[serde(skip)]
36    #[build_it(skip)]
37    issue: i64,
38
39    /// If provided, only comments updated since the provided time are returned.
40    since: Option<String>,
41    /// If provided, only comments updated before the provided time are returned.
42    before: Option<String>,
43    /// Page number of results to return (1-based).
44    page: Option<i64>,
45    /// Page size of results
46    limit: Option<i64>,
47}
48
49impl ListAllCommentsBuilder {
50    pub fn new(owner: &str, repo: &str) -> Self {
51        Self {
52            owner: owner.to_string(),
53            repo: repo.to_string(),
54            since: None,
55            before: None,
56            page: None,
57            limit: None,
58        }
59    }
60
61    /// Sends the request to list a repository's comments.
62    pub async fn send(&self, client: &Client) -> Result<Vec<Comment>> {
63        let owner = &self.owner;
64        let repo = &self.repo;
65        let req = client
66            .get(format!("repos/{owner}/{repo}/issues/comments"))
67            .query(self)
68            .build()?;
69        let res = client.make_request(req).await?;
70        client.parse_response(res).await
71    }
72}
73
74impl ListCommentsBuilder {
75    pub fn new(owner: &str, repo: &str, issue: i64) -> Self {
76        Self {
77            owner: owner.to_string(),
78            repo: repo.to_string(),
79            issue,
80            since: None,
81            before: None,
82            page: None,
83            limit: None,
84        }
85    }
86
87    /// Sends the request to list an issue's comments.
88    pub async fn send(&self, client: &Client) -> Result<Vec<Comment>> {
89        let owner = &self.owner;
90        let repo = &self.repo;
91        let issue = self.issue;
92        let req = client
93            .get(format!("repos/{owner}/{repo}/issues/{issue}/comments"))
94            .query(self)
95            .build()?;
96        let res = client.make_request(req).await?;
97        client.parse_response(res).await
98    }
99}