Skip to content

Commit 9096966

Browse files
authored
feat(common): limits models (#2100)
* feat(common): limits models * clippy
1 parent c8bb693 commit 9096966

File tree

4 files changed

+90
-32
lines changed

4 files changed

+90
-32
lines changed

common/src/models/project.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,17 @@ pub struct ProjectUsageDaily {
196196
pub reserved_vcpu_hours: f32,
197197
pub runtime_minutes: u32,
198198
}
199+
200+
#[derive(Clone, Debug, Deserialize, Serialize)]
201+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
202+
#[typeshare::typeshare]
203+
pub struct ProjectLimitsResponse {
204+
/// Whether this project can be deployed or redeployed
205+
pub can_deploy: Option<bool>,
206+
/// Whether a custom domain can be added
207+
pub can_add_certificate: Option<bool>,
208+
/// Whether upgraded telemetry is enabled for new deployments
209+
pub full_telemetry_enabled: Option<bool>,
210+
/// Highest instance size available for this project
211+
pub max_compute_tier: Option<ComputeTier>,
212+
}

common/src/models/user.rs

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,37 @@ impl AccountTier {
127127
}
128128
}
129129

130+
#[cfg(test)]
131+
mod account_tier_tests {
132+
use super::*;
133+
#[test]
134+
fn deser() {
135+
assert_eq!(
136+
serde_json::from_str::<AccountTier>("\"basic\"").unwrap(),
137+
AccountTier::Basic
138+
);
139+
}
140+
#[cfg(feature = "unknown-variants")]
141+
#[test]
142+
fn unknown_deser() {
143+
assert_eq!(
144+
serde_json::from_str::<AccountTier>("\"\"").unwrap(),
145+
AccountTier::Unknown("".to_string())
146+
);
147+
assert_eq!(
148+
serde_json::from_str::<AccountTier>("\"hisshiss\"").unwrap(),
149+
AccountTier::Unknown("hisshiss".to_string())
150+
);
151+
assert!(serde_json::to_string(&AccountTier::Unknown("asdf".to_string())).is_err());
152+
}
153+
#[cfg(not(feature = "unknown-variants"))]
154+
#[test]
155+
fn not_unknown_deser() {
156+
assert!(serde_json::from_str::<AccountTier>("\"\"").is_err());
157+
assert!(serde_json::from_str::<AccountTier>("\"hisshiss\"").is_err());
158+
}
159+
}
160+
130161
#[derive(Debug, Deserialize, Serialize)]
131162
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
132163
#[typeshare::typeshare]
@@ -178,37 +209,6 @@ pub enum SubscriptionType {
178209
Unknown(String),
179210
}
180211

181-
#[cfg(test)]
182-
mod tests {
183-
use super::*;
184-
#[test]
185-
fn deser() {
186-
assert_eq!(
187-
serde_json::from_str::<AccountTier>("\"basic\"").unwrap(),
188-
AccountTier::Basic
189-
);
190-
}
191-
#[cfg(feature = "unknown-variants")]
192-
#[test]
193-
fn unknown_deser() {
194-
assert_eq!(
195-
serde_json::from_str::<AccountTier>("\"\"").unwrap(),
196-
AccountTier::Unknown("".to_string())
197-
);
198-
assert_eq!(
199-
serde_json::from_str::<AccountTier>("\"hisshiss\"").unwrap(),
200-
AccountTier::Unknown("hisshiss".to_string())
201-
);
202-
assert!(serde_json::to_string(&AccountTier::Unknown("asdf".to_string())).is_err());
203-
}
204-
#[cfg(not(feature = "unknown-variants"))]
205-
#[test]
206-
fn not_unknown_deser() {
207-
assert!(serde_json::from_str::<AccountTier>("\"\"").is_err());
208-
assert!(serde_json::from_str::<AccountTier>("\"hisshiss\"").is_err());
209-
}
210-
}
211-
212212
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
213213
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
214214
#[typeshare::typeshare]
@@ -285,3 +285,21 @@ pub struct UserUsageResponse {
285285
/// if no project usage data exists for user.
286286
pub projects: HashMap<String, ProjectUsageResponse>,
287287
}
288+
289+
#[derive(Clone, Debug, Deserialize, Serialize)]
290+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
291+
#[typeshare::typeshare]
292+
pub struct AccountLimitsResponse {
293+
/// Number of projects the user currently has
294+
pub projects_count: Option<u32>,
295+
/// Number of projects the user may have total
296+
pub projects_limit: Option<u32>,
297+
/// Number of active projects the user currently has
298+
pub active_projects_count: Option<u32>,
299+
/// Number of projects the user may have active at once
300+
pub active_projects_limit: Option<u32>,
301+
/// Number of custom domains the user currently has
302+
pub certificate_count: Option<u32>,
303+
/// Number of custom domains the user may have total
304+
pub certificate_limit: Option<u32>,
305+
}

common/types.ts

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

ifc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl InfraAttrParser {
8888
unknown_key => {
8989
return Err(syn::Error::new(
9090
key.span(),
91-
format!("Invalid macro attribute key: '{}'", unknown_key),
91+
format!("Invalid macro attribute key: '{unknown_key}'"),
9292
))
9393
}
9494
}

0 commit comments

Comments
 (0)