Skip to main content

hey_sdk/generated/services/
time_tracks.rs

1// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3#![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/// Optional query parameters for `ListTimeTracks`.
12#[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    /// The client this service sends through.
28    pub fn client(&self) -> &'a Client {
29        self.client
30    }
31
32    /// Record a finished stretch of time.
33    ///
34    /// JSON callers send the fields flat; Rails wraps them into calendar_time_track itself.
35    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    /// Delete a time track. The id is the recording's.
45    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    /// Get the ongoing time track (404 = no active track; see ADR-004)
54    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    /// List tracked time — completed tracks only, newest-ended first.
60    ///
61    /// A running track is not here; read that with GetOngoingTimeTrack. The next page, if
62    /// any, is a Link header, and the last page carries none, so a nil Link is the end of
63    /// the list rather than an error.
64    ///
65    /// category_id narrows the list to one category and 404s if the calendar has no
66    /// category by that id.
67    ///
68    /// The calendar's categories come back alongside the tracks, so showing or applying the
69    /// filter does not need ListTimeTrackCategories as well.
70    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    /// List the calendar's time track categories, alphabetically
81    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    /// Start a new time track. Takes no body: haystack's
89    /// Calendar::OngoingTimeTracksController#create ignores request parameters and
90    /// starts a track with defaults; use UpdateTimeTrack to set notes and category_title,
91    /// which also stops the track.
92    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    /// Update a time track (stop by setting ends_at to current time).
98    ///
99    /// Every update completes the track, whether or not ends_at is sent, so this cannot
100    /// be used to adjust a running track: it stops it.
101    ///
102    /// Only the fields sent are written, so a partial update leaves the rest of the track
103    /// alone. A starts_at or ends_at the server cannot parse is a 400, not a 422.
104    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}