Skip to content

Commit b4ad54f

Browse files
nathanjclarkoddgrd
andauthored
feat: added updated user usage structs (#2057)
* feat: added upated user usage structs * fix: generate types * feat: implement eq/partialeq to simplify tests --------- Co-authored-by: oddgrd <[email protected]>
1 parent e719915 commit b4ad54f

File tree

3 files changed

+99
-4
lines changed

3 files changed

+99
-4
lines changed

common/src/models/project.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub enum ComputeTier {
117117
}
118118

119119
/// Sub-Response for the /user/me/usage backend endpoint
120-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
120+
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
121121
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
122122
#[typeshare::typeshare]
123123
pub struct ProjectUsageResponse {
@@ -126,10 +126,13 @@ pub struct ProjectUsageResponse {
126126

127127
/// Show the VCPU used by this project on the container platform.
128128
pub vcpu: ProjectUsageVCPU,
129+
130+
/// Daily usage breakdown for this project
131+
pub daily: Vec<ProjectUsageDaily>,
129132
}
130133

131134
/// Build Minutes subquery for the [`ProjectUsageResponse`] struct
132-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
135+
#[derive(Debug, Default, Deserialize, Serialize, Clone, Eq, PartialEq)]
133136
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
134137
#[typeshare::typeshare]
135138
pub struct ProjectUsageBuild {
@@ -141,7 +144,7 @@ pub struct ProjectUsageBuild {
141144
}
142145

143146
/// VCPU subquery for the [`ProjectUsageResponse`] struct
144-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
147+
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
145148
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
146149
#[typeshare::typeshare]
147150
pub struct ProjectUsageVCPU {
@@ -151,3 +154,21 @@ pub struct ProjectUsageVCPU {
151154
/// Used VCPU hours beyond the included reserved VCPU hours for a project.
152155
pub billable_hours: f32,
153156
}
157+
158+
// Add this new struct for daily usage data
159+
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
160+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
161+
#[typeshare::typeshare]
162+
pub struct ProjectUsageDaily {
163+
pub avg_cpu_utilised: f32,
164+
pub avg_mem_utilised: f32,
165+
pub billable_vcpu_hours: f32,
166+
pub build_minutes: u32,
167+
pub isodate: chrono::NaiveDate,
168+
pub max_cpu_reserved: f32,
169+
pub max_mem_reserved: f32,
170+
pub min_cpu_reserved: f32,
171+
pub min_mem_reserved: f32,
172+
pub reserved_vcpu_hours: f32,
173+
pub runtime_minutes: u32,
174+
}

common/src/models/user.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub struct UpdateAccountTierRequest {
225225
}
226226

227227
/// Sub-Response for the /user/me/usage backend endpoint
228-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
228+
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
229229
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
230230
#[typeshare::typeshare]
231231
pub struct UserBillingCycle {
@@ -238,6 +238,39 @@ pub struct UserBillingCycle {
238238
pub end: NaiveDate,
239239
}
240240

241+
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
242+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
243+
#[typeshare::typeshare]
244+
pub struct UserUsageCustomDomains {
245+
pub used: u32,
246+
pub limit: u32,
247+
}
248+
249+
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
250+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
251+
#[typeshare::typeshare]
252+
pub struct UserUsageProjects {
253+
pub used: u32,
254+
pub limit: u32,
255+
}
256+
257+
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
258+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
259+
#[typeshare::typeshare]
260+
pub struct UserUsageTeamMembers {
261+
pub used: u32,
262+
pub limit: u32,
263+
}
264+
265+
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
266+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
267+
#[typeshare::typeshare]
268+
pub struct UserOverviewResponse {
269+
pub custom_domains: UserUsageCustomDomains,
270+
pub projects: UserUsageProjects,
271+
pub team_members: Option<UserUsageTeamMembers>,
272+
}
273+
241274
/// Response for the /user/me/usage backend endpoint
242275
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
243276
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
@@ -246,6 +279,8 @@ pub struct UserUsageResponse {
246279
/// Billing cycle for user, will be None if no usage data exists for user.
247280
pub billing_cycle: Option<UserBillingCycle>,
248281

282+
/// User overview information including project and domain counts
283+
pub user: Option<UserOverviewResponse>,
249284
/// HashMap of project related metrics for this cycle keyed by project_id. Will be empty
250285
/// if no project usage data exists for user.
251286
pub projects: HashMap<String, ProjectUsageResponse>,

common/types.ts

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)