Skip to main content

hevy/models/
routine_folder.rs

1use serde::{Deserialize, Serialize};
2
3/// A folder used to organize [`crate::Routine`]s.
4#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5pub struct RoutineFolder {
6    /// The routine folder ID.
7    pub id: i64,
8    /// The routine folder index, describing the order of the folder in the list.
9    #[serde(default)]
10    pub index: i64,
11    /// The routine folder title.
12    #[serde(default)]
13    pub title: String,
14    /// ISO 8601 timestamp of when the folder was last updated.
15    #[serde(default)]
16    pub updated_at: String,
17    /// ISO 8601 timestamp of when the folder was created.
18    #[serde(default)]
19    pub created_at: String,
20}
21
22/// A page of [`RoutineFolder`]s, as returned by [`crate::HevyClient::list_routine_folders`].
23#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
24pub struct RoutineFoldersPage {
25    /// The current page number.
26    pub page: u32,
27    /// The total number of pages available.
28    pub page_count: u32,
29    /// The routine folders on this page.
30    #[serde(default)]
31    pub routine_folders: Vec<RoutineFolder>,
32}
33
34/// The routine folder fields accepted when creating a new folder.
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct NewRoutineFolder {
37    /// The title of the routine folder.
38    pub title: String,
39}
40
41impl NewRoutineFolder {
42    /// Creates a new routine folder payload with the given title.
43    pub fn new(title: impl Into<String>) -> Self {
44        Self { title: title.into() }
45    }
46}
47
48/// The request body used to create a new routine folder.
49///
50/// The folder will be created at index 0, and all other folders will have
51/// their indexes incremented.
52#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
53pub struct CreateRoutineFolderRequest {
54    /// The routine folder to create.
55    pub routine_folder: NewRoutineFolder,
56}
57
58impl CreateRoutineFolderRequest {
59    /// Wraps a [`NewRoutineFolder`] in the request body envelope expected by the API.
60    pub fn new(routine_folder: NewRoutineFolder) -> Self {
61        Self { routine_folder }
62    }
63}