summaryrefslogtreecommitdiffstats
path: root/librepology/src/v1/api/request_builder.rs
blob: 952ca48f3053f12e0746f46b3bf197f73493d3cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use crate::v1::api::ApiClient;

#[derive(Debug)]
pub struct ProjectRequestBuilder<'a>(pub(super) &'a ApiClient);

impl<'a> ProjectRequestBuilder<'a> {
    pub fn with_name(self, name: String) -> ProjectRequestBuilderWithName<'a> {
        ProjectRequestBuilderWithName(self.0, name)
    }

    pub fn filtered(self) -> ProjectRequestFilteredBuilder<'a> {
        ProjectRequestFilteredBuilder {
            client: self.0,
            search: None,
            maintainer: None,
            category: None,
            in_repo_filter: None,
            not_in_repo_filter: None,
            repos_filter: None,
            families_filter: None,
            repos_newest: None,
            families_newest: None,
            newest: None,
            outdated: None,
            problematic: None,
        }
    }
}


#[derive(Debug)]
pub struct ProjectRequestBuilderWithName<'a>(pub(super) &'a ApiClient, pub(super) String);

#[derive(Debug)]
pub struct ProjectRequestFilteredBuilder<'a> {
    pub(super) client: &'a ApiClient,

    // From the API documentation:

    pub(super) search: Option<String>,
    pub(super) maintainer: Option<String>,
    pub(super) category: Option<String>,
    pub(super) in_repo_filter: Option<String>,
    pub(super) not_in_repo_filter: Option<String>,
    pub(super) repos_filter: Option<NumberOrRange>,
    pub(super) families_filter: Option<usize>,
    pub(super) repos_newest: Option<bool>,
    pub(super) families_newest: Option<bool>,
    pub(super) newest: Option<bool>,
    pub(super) outdated: Option<bool>,
    pub(super) problematic: Option<bool>,
}

impl<'a> ProjectRequestFilteredBuilder<'a> {
    pub fn with_search(mut self, opt: Option<String>) -> Self {
        self.search = opt;
        self
    }

    pub fn with_maintainer(mut self, opt: Option<String>) -> Self {
        self.maintainer = opt;
        self
    }

    pub fn with_category(mut self, opt: Option<String>) -> Self {
        self.category = opt;
        self
    }

    pub fn with_in_repo_filter(mut self, opt: Option<String>) -> Self {
        self.in_repo_filter = opt;
        self
    }

    pub fn with_not_in_repo_filter(mut self, opt: Option<String>) -> Self {
        self.not_in_repo_filter = opt;
        self
    }

    pub fn with_repos_filter(mut self, opt: Option<NumberOrRange>) -> Self {
        self.repos_filter = opt;
        self
    }

    pub fn with_families_filter(mut self, opt: Option<usize>) -> Self {
        self.families_filter = opt;
        self
    }

    pub fn with_repos_newest(mut self, opt: Option<bool>) -> Self {
        self.repos_newest = opt;
        self
    }

    pub fn with_families_newest(mut self, opt: Option<bool>) -> Self {
        self.families_newest = opt;
        self
    }

    pub fn with_newest(mut self, opt: Option<bool>) -> Self {
        self.newest = opt;
        self
    }

    pub fn with_outdated(mut self, opt: Option<bool>) -> Self {
        self.outdated = opt;
        self
    }

    pub fn with_problematic(mut self, opt: Option<bool>) -> Self {
        self.problematic = opt;
        self
    }

}

#[derive(Debug)]
pub enum NumberOrRange {
    Number(usize),
    Range(Option<usize>, Option<usize>),
}



#[derive(Debug)]
pub struct ProblemsRequestBuilder<'a>(pub(super) &'a ApiClient);

impl<'a> ProblemsRequestBuilder<'a> {
    pub fn for_maintainer(self, name: String) -> ProblemsForMaintainerRequestBuilder<'a> {
        ProblemsForMaintainerRequestBuilder(self.0, name)
    }

    pub fn for_repo(self, name: String) -> ProblemsForRepoRequestBuilder<'a> {
        ProblemsForRepoRequestBuilder(self.0, name)
    }
}

#[derive(Debug)]
pub struct ProblemsForMaintainerRequestBuilder<'a>(&'a ApiClient, String);

#[derive(Debug)]
pub struct ProblemsForRepoRequestBuilder<'a>(pub(super) &'a ApiClient, pub(super) String);

impl<'a> ProblemsForMaintainerRequestBuilder<'a> {
    pub fn for_repo(self, repo: String) -> ProblemsForMaintainerAndRepoRequestBuilder<'a> {
        ProblemsForMaintainerAndRepoRequestBuilder {
            client: self.0,
            maintainer: self.1,
            repo,
        }
    }
}

#[derive(Debug)]
pub struct ProblemsForMaintainerAndRepoRequestBuilder<'a> {
    pub(super) client: &'a ApiClient,
    pub(super) maintainer: String,
    pub(super) repo: String,
}