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
// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;
/// Optional query parameters for `ListTimeTracks`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListTimeTracksParams {
pub page: Option<String>,
pub category_id: Option<i64>,
}
pub struct TimeTracks<'a> {
client: &'a Client,
}
impl<'a> TimeTracks<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
/// The client this service sends through.
pub fn client(&self) -> &'a Client {
self.client
}
/// Record a finished stretch of time.
///
/// JSON callers send the fields flat; Rails wraps them into calendar_time_track itself.
pub async fn create(
&self,
body: &TimeTrackRequestContent,
) -> Result<CreateTimeTrackResponseContent, Error> {
let mut operation = self.client.operation(&routes::CREATE_TIME_TRACK, &[]);
operation.json(body)?;
self.client.send(operation).await
}
/// Delete a time track. The id is the recording's.
pub async fn delete(&self, time_track_id: i64) -> Result<(), Error> {
let mut operation = self
.client
.operation(&routes::DELETE_TIME_TRACK, &[&time_track_id]);
operation.resource_id(time_track_id);
self.client.send_unit(operation).await
}
/// Get the ongoing time track (404 = no active track; see ADR-004)
pub async fn get_ongoing(&self) -> Result<Option<GetOngoingTimeTrackResponseContent>, Error> {
let operation = self.client.operation(&routes::GET_ONGOING_TIME_TRACK, &[]);
self.client.send_optional(operation).await
}
/// List tracked time — completed tracks only, newest-ended first.
///
/// A running track is not here; read that with GetOngoingTimeTrack. The next page, if
/// any, is a Link header, and the last page carries none, so a nil Link is the end of
/// the list rather than an error.
///
/// category_id narrows the list to one category and 404s if the calendar has no
/// category by that id.
///
/// The calendar's categories come back alongside the tracks, so showing or applying the
/// filter does not need ListTimeTrackCategories as well.
pub async fn list(
&self,
params: &ListTimeTracksParams,
) -> Result<Page<ListTimeTracksResponseContent>, Error> {
let mut operation = self.client.operation(&routes::LIST_TIME_TRACKS, &[]);
operation.query_optional("page", params.page.as_ref());
operation.query_optional("category_id", params.category_id.as_ref());
self.client.send_page(operation).await
}
/// List the calendar's time track categories, alphabetically
pub async fn list_categories(&self) -> Result<ListTimeTrackCategoriesResponseContent, Error> {
let operation = self
.client
.operation(&routes::LIST_TIME_TRACK_CATEGORIES, &[]);
self.client.send(operation).await
}
/// Start a new time track. Takes no body: haystack's
/// Calendar::OngoingTimeTracksController#create ignores request parameters and
/// starts a track with defaults; use UpdateTimeTrack to set notes and category_title,
/// which also stops the track.
pub async fn start(&self) -> Result<StartTimeTrackResponseContent, Error> {
let operation = self.client.operation(&routes::START_TIME_TRACK, &[]);
self.client.send(operation).await
}
/// Update a time track (stop by setting ends_at to current time).
///
/// Every update completes the track, whether or not ends_at is sent, so this cannot
/// be used to adjust a running track: it stops it.
///
/// Only the fields sent are written, so a partial update leaves the rest of the track
/// alone. A starts_at or ends_at the server cannot parse is a 400, not a 422.
pub async fn update(
&self,
time_track_id: i64,
body: &UpdateTimeTrackRequestContent,
) -> Result<UpdateTimeTrackResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::UPDATE_TIME_TRACK, &[&time_track_id]);
operation.resource_id(time_track_id);
operation.json(body)?;
self.client.send(operation).await
}
}