gitlab_time_report/fetch_api/
api_model.rs

1//! Structs for deserializing the JSON response from the GitLab API
2
3use crate::model::TimeLog;
4use chrono::Duration;
5use serde::Deserialize;
6use serde_with::{DurationSeconds, serde_as};
7
8/// The queried GitLab repository as it appears in the GitLab API.
9#[derive(Debug, Deserialize)]
10pub(super) struct Project {
11    /// The name of the repository.
12    pub(super) name: String,
13    /// The time logs of the repository.
14    pub(super) timelogs: TimeLogs,
15}
16
17/// Time logs as they appear in the GitLab API with pagination information.
18#[serde_as]
19#[derive(Debug, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct TimeLogs {
22    /// The actual time logs. On some GraphQL errors, `nodes` exists but is empty, so `TimeLog`
23    /// needs to be wrapped in `Option`.
24    pub(super) nodes: Vec<Option<TimeLog>>,
25    /// Pagination for the GitLab API
26    pub(super) page_info: PageInfo,
27    /// Total Time spent on the project
28    #[serde_as(as = "DurationSeconds<String>")]
29    pub(super) total_spent_time: Duration,
30}
31
32/// Information to aid in the pagination of the GitLab API.
33#[derive(Debug, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub(super) struct PageInfo {
36    /// When paginating forwards, are there more items?
37    pub(super) has_next_page: bool,
38    /// When paginating forwards, the cursor to continue.
39    pub(super) end_cursor: Option<String>,
40}
41
42/// The top-level node of a GitLab API response.
43#[derive(Debug, Deserialize)]
44pub(super) struct ApiResponse {
45    /// The response data.
46    pub(super) data: Data,
47    /// Possible GraphQL errors that occurred in the query.
48    pub(super) errors: Option<Vec<GraphQlError>>,
49}
50
51/// Response data of the GitLab API.
52#[derive(Debug, Deserialize)]
53pub(super) struct Data {
54    /// The data of the project if it exists and is accessed with the right permissions.
55    pub(super) project: Option<Project>,
56}
57
58/// The actual GraphQL error.
59#[derive(Debug, Deserialize)]
60pub(super) struct GraphQlError {
61    pub(super) message: String,
62}