hey_sdk/generated/services/
time_tracks.rs1#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
4
5use crate::client::Client;
6use crate::error::Error;
7use crate::generated::routes;
8use crate::generated::types::*;
9use crate::pagination::Page;
10
11#[derive(Debug, Clone, Default, PartialEq)]
13pub struct ListTimeTracksParams {
14 pub page: Option<String>,
15 pub category_id: Option<i64>,
16}
17
18pub struct TimeTracks<'a> {
19 client: &'a Client,
20}
21
22impl<'a> TimeTracks<'a> {
23 pub(crate) fn new(client: &'a Client) -> Self {
24 Self { client }
25 }
26
27 pub fn client(&self) -> &'a Client {
29 self.client
30 }
31
32 pub async fn create(
36 &self,
37 body: &TimeTrackRequestContent,
38 ) -> Result<CreateTimeTrackResponseContent, Error> {
39 let mut operation = self.client.operation(&routes::CREATE_TIME_TRACK, &[]);
40 operation.json(body)?;
41 self.client.send(operation).await
42 }
43
44 pub async fn delete(&self, time_track_id: i64) -> Result<(), Error> {
46 let mut operation = self
47 .client
48 .operation(&routes::DELETE_TIME_TRACK, &[&time_track_id]);
49 operation.resource_id(time_track_id);
50 self.client.send_unit(operation).await
51 }
52
53 pub async fn get_ongoing(&self) -> Result<Option<GetOngoingTimeTrackResponseContent>, Error> {
55 let operation = self.client.operation(&routes::GET_ONGOING_TIME_TRACK, &[]);
56 self.client.send_optional(operation).await
57 }
58
59 pub async fn list(
71 &self,
72 params: &ListTimeTracksParams,
73 ) -> Result<Page<ListTimeTracksResponseContent>, Error> {
74 let mut operation = self.client.operation(&routes::LIST_TIME_TRACKS, &[]);
75 operation.query_optional("page", params.page.as_ref());
76 operation.query_optional("category_id", params.category_id.as_ref());
77 self.client.send_page(operation).await
78 }
79
80 pub async fn list_categories(&self) -> Result<ListTimeTrackCategoriesResponseContent, Error> {
82 let operation = self
83 .client
84 .operation(&routes::LIST_TIME_TRACK_CATEGORIES, &[]);
85 self.client.send(operation).await
86 }
87
88 pub async fn start(&self) -> Result<StartTimeTrackResponseContent, Error> {
93 let operation = self.client.operation(&routes::START_TIME_TRACK, &[]);
94 self.client.send(operation).await
95 }
96
97 pub async fn update(
105 &self,
106 time_track_id: i64,
107 body: &UpdateTimeTrackRequestContent,
108 ) -> Result<UpdateTimeTrackResponseContent, Error> {
109 let mut operation = self
110 .client
111 .operation(&routes::UPDATE_TIME_TRACK, &[&time_track_id]);
112 operation.resource_id(time_track_id);
113 operation.json(body)?;
114 self.client.send(operation).await
115 }
116}