1use pib_service_api_types::{
7 Index, Pagination,
8 body::{
9 Body, NewBody,
10 by_id::{
11 meeting::{
12 Meeting, NewMeeting,
13 by_id::agenda_item::{AgendaItem, NewAgendaItem},
14 },
15 organization::{NewOrganization, Organization},
16 permission::{NewPermission, Permission},
17 person::{NewPerson, Person},
18 },
19 },
20 config::Config,
21 me::profile::{Profile, UpdateProfile},
22 user::User,
23};
24use pib_service_core_types::{
25 AgendaItemId, BodyId, BodyPermissionId, DataPage, MeetingId, OrganizationId, PersonId, UserId,
26};
27
28mod requests {
29 pub(super) use pib_client_requests::{
30 body::{
31 self,
32 by_id::{
33 meeting::{self, by_id::agenda_item},
34 organization, permission, person,
35 },
36 },
37 config, get, me, user,
38 };
39}
40
41mod types {
42 pub(super) use pib_service_api_types::{
43 body::{
44 self,
45 by_id::{
46 meeting::{self, by_id::agenda_item},
47 organization, permission, person,
48 },
49 },
50 me, user,
51 };
52}
53
54#[async_trait::async_trait(?Send)]
55pub trait PibClient: Clone {
56 type ClientError: std::error::Error;
57
58 async fn get(&self) -> Result<Index, Self::ClientError>;
59
60 async fn config_get(&self) -> Result<Config, Self::ClientError>;
61
62 async fn user_get(&self, pagination: Pagination) -> Result<DataPage<User>, Self::ClientError>;
63
64 async fn user_by_id_get(&self, user_id: UserId) -> Result<User, Self::ClientError>;
65
66 async fn body_get(&self, pagination: Pagination) -> Result<DataPage<Body>, Self::ClientError>;
67
68 async fn body_post(&self, new_body: NewBody) -> Result<Body, Self::ClientError>;
69
70 async fn body_by_id_get(&self, body_id: BodyId) -> Result<Body, Self::ClientError>;
71
72 async fn body_by_id_permission_get(
73 &self,
74 body_id: BodyId,
75 pagination: Pagination,
76 ) -> Result<DataPage<Permission>, Self::ClientError>;
77
78 async fn body_by_id_permission_post(
79 &self,
80 body_id: BodyId,
81 new_permission: NewPermission,
82 ) -> Result<Permission, Self::ClientError>;
83
84 async fn body_by_id_permission_by_id_get(
85 &self,
86 body_id: BodyId,
87 permission_id: BodyPermissionId,
88 ) -> Result<Permission, Self::ClientError>;
89
90 async fn body_by_id_meeting_get(
91 &self,
92 body_id: BodyId,
93 pagination: Pagination,
94 ) -> Result<DataPage<Meeting>, Self::ClientError>;
95
96 async fn body_by_id_meeting_post(
97 &self,
98 body_id: BodyId,
99 new_meeting: NewMeeting,
100 ) -> Result<Meeting, Self::ClientError>;
101
102 async fn body_by_id_meeting_by_id_get(
103 &self,
104 body_id: BodyId,
105 meeting_id: MeetingId,
106 ) -> Result<Meeting, Self::ClientError>;
107
108 async fn body_by_id_meeting_by_id_agenda_item_get(
109 &self,
110 body_id: BodyId,
111 meeting_id: MeetingId,
112 pagination: Pagination,
113 ) -> Result<DataPage<AgendaItem>, Self::ClientError>;
114
115 async fn body_by_id_meeting_by_id_agenda_item_post(
116 &self,
117 body_id: BodyId,
118 meeting_id: MeetingId,
119 new_agenda_item: NewAgendaItem,
120 ) -> Result<AgendaItem, Self::ClientError>;
121
122 async fn body_by_id_meeting_by_id_agenda_item_by_id_get(
123 &self,
124 body_id: BodyId,
125 meeting_id: MeetingId,
126 agenda_item_id: AgendaItemId,
127 ) -> Result<AgendaItem, Self::ClientError>;
128
129 async fn body_by_id_organization_get(
130 &self,
131 body_id: BodyId,
132 pagination: Pagination,
133 ) -> Result<DataPage<Organization>, Self::ClientError>;
134
135 async fn body_by_id_organization_post(
136 &self,
137 body_id: BodyId,
138 payload: NewOrganization,
139 ) -> Result<Organization, Self::ClientError>;
140
141 async fn body_by_id_organization_by_id_get(
142 &self,
143 body_id: BodyId,
144 organization_id: OrganizationId,
145 ) -> Result<Organization, Self::ClientError>;
146
147 async fn body_by_id_person_get(
148 &self,
149 body_id: BodyId,
150 pagination: Pagination,
151 ) -> Result<DataPage<Person>, Self::ClientError>;
152
153 async fn body_by_id_person_post(
154 &self,
155 body_id: BodyId,
156 new_person: NewPerson,
157 ) -> Result<Person, Self::ClientError>;
158
159 async fn body_by_id_person_by_id_get(
160 &self,
161 body_id: BodyId,
162 person_id: PersonId,
163 ) -> Result<Person, Self::ClientError>;
164
165 async fn me_profile_get(&self) -> Result<Profile, Self::ClientError>;
166
167 async fn me_profile_patch(
168 &self,
169 update_profile: UpdateProfile,
170 ) -> Result<Profile, Self::ClientError>;
171}
172
173#[async_trait::async_trait(?Send)]
174impl<C: http_request_derive_client::Client + Clone> PibClient for C {
175 type ClientError = C::ClientError;
176
177 async fn get(&self) -> Result<Index, Self::ClientError> {
178 let response = self.execute(requests::get::Request).await?;
179 Ok(response.0.0)
180 }
181
182 async fn config_get(&self) -> Result<Config, Self::ClientError> {
183 let response = self.execute(requests::config::get::Request).await?;
184 Ok(response.0.0)
185 }
186
187 async fn user_get(
188 &self,
189 pagination: Pagination,
190 ) -> Result<DataPage<types::user::User>, Self::ClientError> {
191 let response = self
192 .execute(requests::user::get::Request { pagination })
193 .await?;
194 Ok(response.0.0)
195 }
196
197 async fn user_by_id_get(
198 &self,
199 user_id: UserId,
200 ) -> Result<types::user::User, Self::ClientError> {
201 let response = self
202 .execute(requests::user::by_id::get::Request { user_id })
203 .await?;
204 Ok(response.0.0)
205 }
206
207 async fn body_get(
208 &self,
209 pagination: Pagination,
210 ) -> Result<DataPage<types::body::Body>, Self::ClientError> {
211 let response = self
212 .execute(requests::body::get::Request { pagination })
213 .await?;
214 Ok(response.0.0)
215 }
216
217 async fn body_post(
218 &self,
219 new_body: types::body::NewBody,
220 ) -> Result<types::body::Body, Self::ClientError> {
221 Ok(self
222 .execute(requests::body::post::Request {
223 payload: types::body::post::RequestBody(new_body),
224 })
225 .await?
226 .0
227 .0)
228 }
229
230 async fn body_by_id_get(
231 &self,
232 body_id: BodyId,
233 ) -> Result<types::body::Body, Self::ClientError> {
234 let response = self
235 .execute(requests::body::by_id::get::Request { body_id })
236 .await?;
237 Ok(response.0.0)
238 }
239
240 async fn body_by_id_permission_get(
241 &self,
242 body_id: BodyId,
243 pagination: Pagination,
244 ) -> Result<DataPage<Permission>, Self::ClientError> {
245 Ok(self
246 .execute(requests::permission::get::Request {
247 body_id,
248 pagination,
249 })
250 .await?
251 .0
252 .0)
253 }
254
255 async fn body_by_id_permission_post(
256 &self,
257 body_id: BodyId,
258 new_permission: NewPermission,
259 ) -> Result<Permission, Self::ClientError> {
260 Ok(self
261 .execute(requests::permission::post::Request {
262 body_id,
263 payload: types::permission::post::RequestBody(new_permission),
264 })
265 .await?
266 .0
267 .0)
268 }
269
270 async fn body_by_id_permission_by_id_get(
271 &self,
272 body_id: BodyId,
273 permission_id: BodyPermissionId,
274 ) -> Result<types::permission::Permission, Self::ClientError> {
275 let response = self
276 .execute(requests::permission::by_id::get::Request {
277 body_id,
278 permission_id,
279 })
280 .await?;
281 Ok(response.0.0)
282 }
283
284 async fn body_by_id_meeting_get(
285 &self,
286 body_id: BodyId,
287 pagination: Pagination,
288 ) -> Result<DataPage<types::meeting::Meeting>, Self::ClientError> {
289 Ok(self
290 .execute(requests::meeting::get::Request {
291 body_id,
292 pagination,
293 })
294 .await?
295 .0
296 .0)
297 }
298
299 async fn body_by_id_meeting_post(
300 &self,
301 body_id: BodyId,
302 new_meeting: types::meeting::NewMeeting,
303 ) -> Result<types::meeting::Meeting, Self::ClientError> {
304 Ok(self
305 .execute(requests::meeting::post::Request {
306 body_id,
307 payload: types::meeting::post::RequestBody(new_meeting),
308 })
309 .await?
310 .0
311 .0)
312 }
313
314 async fn body_by_id_meeting_by_id_get(
315 &self,
316 body_id: BodyId,
317 meeting_id: MeetingId,
318 ) -> Result<types::meeting::Meeting, Self::ClientError> {
319 let response = self
320 .execute(requests::meeting::by_id::get::Request {
321 body_id,
322 meeting_id,
323 })
324 .await?;
325 Ok(response.0.0)
326 }
327
328 async fn body_by_id_meeting_by_id_agenda_item_get(
329 &self,
330 body_id: BodyId,
331 meeting_id: MeetingId,
332 pagination: Pagination,
333 ) -> Result<DataPage<types::agenda_item::AgendaItem>, Self::ClientError> {
334 let response = self
335 .execute(requests::agenda_item::get::Request {
336 body_id,
337 meeting_id,
338 pagination,
339 })
340 .await?;
341 Ok(response.0.0)
342 }
343
344 async fn body_by_id_meeting_by_id_agenda_item_post(
345 &self,
346 body_id: BodyId,
347 meeting_id: MeetingId,
348 new_agenda_item: types::agenda_item::NewAgendaItem,
349 ) -> Result<types::agenda_item::AgendaItem, Self::ClientError> {
350 Ok(self
351 .execute(requests::agenda_item::post::Request {
352 body_id,
353 meeting_id,
354 payload: types::agenda_item::post::RequestBody(new_agenda_item),
355 })
356 .await?
357 .0
358 .0)
359 }
360
361 async fn body_by_id_meeting_by_id_agenda_item_by_id_get(
362 &self,
363 body_id: BodyId,
364 meeting_id: MeetingId,
365 agenda_item_id: AgendaItemId,
366 ) -> Result<types::agenda_item::AgendaItem, Self::ClientError> {
367 let response = self
368 .execute(requests::agenda_item::by_id::get::Request {
369 body_id,
370 meeting_id,
371 agenda_item_id,
372 })
373 .await?;
374 Ok(response.0.0)
375 }
376
377 async fn body_by_id_organization_get(
378 &self,
379 body_id: BodyId,
380 pagination: Pagination,
381 ) -> Result<DataPage<types::organization::Organization>, Self::ClientError> {
382 Ok(self
383 .execute(requests::organization::get::Request {
384 body_id,
385 pagination,
386 })
387 .await?
388 .0
389 .0)
390 }
391
392 async fn body_by_id_organization_post(
393 &self,
394 body_id: BodyId,
395 new_organization: types::organization::NewOrganization,
396 ) -> Result<types::organization::Organization, Self::ClientError> {
397 Ok(self
398 .execute(requests::organization::post::Request {
399 body_id,
400 payload: types::organization::post::RequestBody(new_organization),
401 })
402 .await?
403 .0
404 .0)
405 }
406
407 async fn body_by_id_organization_by_id_get(
408 &self,
409 body_id: BodyId,
410 organization_id: OrganizationId,
411 ) -> Result<types::organization::Organization, Self::ClientError> {
412 let response = self
413 .execute(requests::organization::by_id::get::Request {
414 body_id,
415 organization_id,
416 })
417 .await?;
418 Ok(response.0.0)
419 }
420
421 async fn body_by_id_person_get(
422 &self,
423 body_id: BodyId,
424 pagination: Pagination,
425 ) -> Result<DataPage<types::person::Person>, Self::ClientError> {
426 Ok(self
427 .execute(requests::person::get::Request {
428 body_id,
429 pagination,
430 })
431 .await?
432 .0
433 .0)
434 }
435
436 async fn body_by_id_person_post(
437 &self,
438 body_id: BodyId,
439 new_person: types::person::NewPerson,
440 ) -> Result<types::person::Person, Self::ClientError> {
441 Ok(self
442 .execute(requests::person::post::Request {
443 body_id,
444 payload: types::person::post::RequestBody(new_person),
445 })
446 .await?
447 .0
448 .0)
449 }
450
451 async fn body_by_id_person_by_id_get(
452 &self,
453 body_id: BodyId,
454 person_id: PersonId,
455 ) -> Result<types::person::Person, Self::ClientError> {
456 let response = self
457 .execute(requests::person::by_id::get::Request { body_id, person_id })
458 .await?;
459 Ok(response.0.0)
460 }
461
462 async fn me_profile_get(&self) -> Result<types::me::profile::Profile, Self::ClientError> {
463 Ok(self.execute(requests::me::profile::get::Request).await?.0.0)
464 }
465
466 async fn me_profile_patch(
467 &self,
468 update_profile: UpdateProfile,
469 ) -> Result<Profile, Self::ClientError> {
470 Ok(self
471 .execute(requests::me::profile::patch::Request {
472 payload: types::me::profile::patch::RequestBody(update_profile),
473 })
474 .await?
475 .0
476 .0)
477 }
478}