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
23    pub(super) nodes: Vec<TimeLog>,
24    /// Pagination for the GitLab API
25    pub(super) page_info: PageInfo,
26    /// Total Time spent on the project
27    #[serde_as(as = "DurationSeconds<String>")]
28    pub(super) total_spent_time: Duration,
29}
30
31/// Information to aid in the pagination of the GitLab API.
32#[derive(Debug, Deserialize)]
33#[serde(rename_all = "camelCase")]
34pub(super) struct PageInfo {
35    /// When paginating forwards, are there more items?
36    pub(super) has_next_page: bool,
37    /// When paginating forwards, the cursor to continue.
38    pub(super) end_cursor: Option<String>,
39}
40
41/// The top-level node of a GitLab API response.
42#[derive(Debug, Deserialize)]
43pub(super) struct ApiResponse {
44    /// The response data.
45    pub(super) data: Data,
46    /// Possible GraphQL errors that occurred in the query.
47    pub(super) errors: Option<GraphQlErrors>,
48}
49
50/// Response data of the GitLab API.
51#[derive(Debug, Deserialize)]
52pub(super) struct Data {
53    /// The data of the project if it exists and is accessed with the right permissions.
54    pub(super) project: Option<Project>,
55}
56
57/// A list of GraphQL errors that occurred during the query.
58#[derive(Debug, Deserialize)]
59pub(super) struct GraphQlErrors {
60    pub(super) errors: Vec<GraphQlError>,
61}
62
63/// The actual GraphQL error.
64#[derive(Debug, Deserialize)]
65pub(super) struct GraphQlError {
66    pub(super) message: String,
67}