Skip to content

Commit 8fa79e6

Browse files
authored
feat: Add Project Usage types for User Visualisation (#2031)
* feat: Add Project Usage types for User Visualisation * fix: Add typeshare types for project usage * fix: Remove billable cycle * feat: Create UserUsageResponse
1 parent 2c3e0d3 commit 8fa79e6

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

common/src/models/project.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,39 @@ pub enum ComputeTier {
115115
#[strum(default, to_string = "Unknown: {0}")]
116116
Unknown(String),
117117
}
118+
119+
/// Sub-Response for the /user/me/usage backend endpoint
120+
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
121+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
122+
#[typeshare::typeshare]
123+
pub struct ProjectUsageResponse {
124+
/// Show the build minutes clocked against this Project.
125+
pub build_minutes: ProjectUsageBuild,
126+
127+
/// Show the VCPU used by this project on the container platform.
128+
pub vcpu: ProjectUsageVCPU,
129+
}
130+
131+
/// Build Minutes subquery for the [`ProjectUsageResponse`] struct
132+
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
133+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
134+
#[typeshare::typeshare]
135+
pub struct ProjectUsageBuild {
136+
/// Number of build minutes used by this project.
137+
pub used: u32,
138+
139+
/// Limit of build minutes for this project, before additional charges are liable.
140+
pub limit: u32,
141+
}
142+
143+
/// VCPU subquery for the [`ProjectUsageResponse`] struct
144+
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
145+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
146+
#[typeshare::typeshare]
147+
pub struct ProjectUsageVCPU {
148+
/// The VCPU reserved for this project
149+
pub reserved: f32,
150+
151+
/// Cost accrued from VCPU usage for this project
152+
pub billable_hours: f32,
153+
}

common/src/models/user.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
use std::collections::HashMap;
12
#[cfg(feature = "display")]
23
use std::fmt::Write;
34

4-
use chrono::{DateTime, Utc};
5+
use chrono::{DateTime, NaiveDate, Utc};
56
#[cfg(feature = "display")]
67
use crossterm::style::Stylize;
78
use serde::{Deserialize, Serialize};
89
use strum::{EnumString, IntoStaticStr};
910

11+
use super::project::ProjectUsageResponse;
12+
1013
#[derive(Debug, Deserialize, Serialize)]
1114
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1215
#[typeshare::typeshare]
@@ -220,3 +223,21 @@ pub struct CreateAccountRequest {
220223
pub struct UpdateAccountTierRequest {
221224
pub account_tier: AccountTier,
222225
}
226+
227+
/// Response for the /user/me/usage backend endpoint
228+
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
229+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
230+
#[typeshare::typeshare]
231+
pub struct UserUsageResponse {
232+
/// Billing cycle start, or monthly from user creation
233+
/// depending on the account tier
234+
pub start: NaiveDate,
235+
236+
/// Billing cycle end, or end of month from user creation
237+
/// depending on the account tier
238+
pub end: NaiveDate,
239+
240+
/// HashMap of project related metrics for this cycle
241+
/// keyed by project_id
242+
pub projects: HashMap<String, ProjectUsageResponse>,
243+
}

common/types.ts

Lines changed: 43 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)