schemas_v1_api_cost - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/schemas/v1/api/cost.rs
Cost management module for handling cost tracking and analysis operations.
This module provides a REST API for managing cost-related entities, including:
- Resource types management
- Cost metrics tracking and analysis
- Cost projections and forecasting
- Budget management
- Resource pricing management
- Cost allocation tagging
- struct CreateResourceTypeRequest
- struct UpdateResourceTypeRequest
- struct CreateCostMetricRequest
- struct CostMetricFilter
- struct CreateCostBudgetRequest
- struct UpdateCostBudgetRequest
- struct CreateCostProjectionRequest
- struct CreateResourcePricingRequest
- struct UpdateResourcePricingRequest
- struct CreateCostAllocationTagRequest
- struct CostAnalysisByDimensionRequest
- struct CostOverTimeRequest
- async fn list_resource_types
- async fn count_resource_types
- async fn get_resource_type
- async fn create_resource_type
- async fn update_resource_type
- async fn delete_resource_type
- async fn list_cost_metrics
- async fn get_cost_metric
- async fn create_cost_metric
- async fn delete_cost_metric
- async fn analyze_costs_by_dimension
- async fn analyze_cost_over_time
- async fn list_cost_budgets
- async fn get_cost_budget
- async fn create_cost_budget
- async fn update_cost_budget
- async fn delete_cost_budget
- async fn list_cost_projections
- async fn get_cost_projection
- async fn create_cost_projection
- async fn delete_cost_projection
- async fn list_resource_pricing
- async fn get_resource_pricing
- async fn create_resource_pricing
- async fn update_resource_pricing
- async fn delete_resource_pricing
- async fn get_cost_allocation_tags
- async fn create_cost_allocation_tag
- async fn delete_cost_allocation_tag
pub struct CreateResourceTypeRequest {
/// Name of the resource type
name: String,
/// Category of the resource
category: String,
/// Unit of measurement (e.g., 'vCPU-hour', 'GB-month')
unit_of_measurement: String,
/// Optional description of the resource type
description: Option<String>,
}
Request data for creating a new resource type.
pub struct UpdateResourceTypeRequest {
/// New name for the resource type
name: Option<String>,
/// New category for the resource
category: Option<String>,
/// New unit of measurement
unit_of_measurement: Option<String>,
/// New description of the resource type
description: Option<String>,
}
Request data for updating a resource type.
pub struct CreateCostMetricRequest {
/// Resource type ID
resource_type_id: i32,
/// Provider ID
provider_id: Option<i64>,
/// Region ID
region_id: Option<i64>,
/// Application ID
app_id: Option<i64>,
/// Worker ID
worker_id: Option<i64>,
/// Organization ID
org_id: Option<i64>,
/// Start time of the usage period
start_time: DateTime<Utc>,
/// End time of the usage period
end_time: DateTime<Utc>,
/// Amount of resource used
usage_quantity: f64,
/// Cost per unit
unit_cost: f64,
/// Currency code (e.g., 'USD')
currency: String,
/// Total cost for this usage
total_cost: f64,
/// Discount percentage applied
discount_percentage: Option<f64>,
/// Reason for the discount
discount_reason: Option<String>,
/// Billing period (e.g., '2025-05')
billing_period: Option<String>,
}
Request data for creating a new cost metric.
pub struct CostMetricFilter {
/// Filter by resource type ID
resource_type_id: Option<i32>,
/// Filter by provider ID
provider_id: Option<i64>,
/// Filter by application ID
app_id: Option<i64>,
/// Filter by start date
start_date: Option<DateTime<Utc>>,
/// Filter by end date
end_date: Option<DateTime<Utc>>,
/// Filter by billing period
billing_period: Option<String>,
}
Request data for filtering cost metrics.
pub struct CreateCostBudgetRequest {
/// Organization ID
org_id: i64,
/// Application ID (optional)
app_id: Option<i64>,
/// Budget name
budget_name: String,
/// Budget amount
budget_amount: f64,
/// Currency code (e.g., 'USD')
currency: String,
/// Budget period type
budget_period: String,
/// Start date of the budget period
period_start: DateTime<Utc>,
/// End date of the budget period
period_end: DateTime<Utc>,
/// Alert threshold percentage
alert_threshold_percentage: f64,
/// Contacts to alert when threshold is reached (JSON)
alert_contacts: String,
}
Request data for creating a new cost budget.
pub struct UpdateCostBudgetRequest {
/// New budget name
budget_name: Option<String>,
/// New budget amount
budget_amount: Option<f64>,
/// New alert threshold percentage
alert_threshold_percentage: Option<f64>,
/// New contacts to alert when threshold is reached (JSON)
alert_contacts: Option<String>,
/// Whether the budget is active
is_active: Option<bool>,
}
Request data for updating a cost budget.
pub struct CreateCostProjectionRequest {
/// Organization ID
org_id: i64,
/// Application ID (optional)
app_id: Option<i64>,
/// Projection period type (e.g., 'monthly', 'quarterly')
projection_period: String,
/// Start date of the projection period
start_date: DateTime<Utc>,
/// End date of the projection period
end_date: DateTime<Utc>,
/// Projected cost amount
projected_cost: f64,
/// Currency code (e.g., 'USD')
currency: String,
/// Projection model used (e.g., 'linear', 'average_30d')
projection_model: String,
/// Confidence level of the projection
confidence_level: Option<f64>,
/// Additional metadata about the projection (JSON)
metadata: Option<String>,
}
Request data for creating a new cost projection.
pub struct CreateResourcePricingRequest {
/// Resource type ID
resource_type_id: i32,
/// Provider ID
provider_id: i64,
/// Region ID (optional)
region_id: Option<i64>,
/// Tier name (e.g., 'standard', 'premium')
tier_name: String,
/// Price per unit
unit_price: f64,
/// Currency code (e.g., 'USD')
currency: String,
/// When this pricing becomes effective
effective_from: DateTime<Utc>,
/// When this pricing expires (optional)
effective_to: Option<DateTime<Utc>>,
/// Pricing model (e.g., 'on-demand', 'reserved')
pricing_model: String,
/// Commitment period (e.g., '1-year', '3-year')
commitment_period: Option<String>,
/// Volume discount tiers (JSON)
volume_discount_tiers: Option<String>,
}
Request data for creating a new resource pricing entry.
pub struct UpdateResourcePricingRequest {
/// New price per unit
unit_price: Option<f64>,
/// New expiration date
effective_to: Option<DateTime<Utc>>,
/// New volume discount tiers (JSON)
volume_discount_tiers: Option<String>,
}
Request data for updating a resource pricing entry.
pub struct CreateCostAllocationTagRequest {
/// Tag key
tag_key: String,
/// Tag value
tag_value: String,
/// Resource ID
resource_id: i64,
/// Resource type
resource_type: String,
}
Request data for creating a new cost allocation tag.
pub struct CostAnalysisByDimensionRequest {
/// Dimension to group by
dimension: String,
/// Start date for analysis
start_date: DateTime<Utc>,
/// End date for analysis
end_date: DateTime<Utc>,
/// Maximum number of results to return
limit: i64,
}
Request data for aggregate cost analysis by dimension.
pub struct CostOverTimeRequest {
/// Application ID to analyze
app_id: i64,
/// Time interval ('day', 'week', 'month')
interval: String,
/// Start date for analysis
start_date: DateTime<Utc>,
/// End date for analysis
end_date: DateTime<Utc>,
}
Request data for cost analysis over time.
pub async fn list_resource_types(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List all resource types with pagination support.
pub async fn count_resource_types(
platform_id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<i64>, (Status, Json<Value>)> {
// ... function body
}
Count the total number of resource types.
pub async fn get_resource_type(
platform_id: i64,
id: i32,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourceType>, (Status, Json<Value>)> {
// ... function body
}
Get a specific resource type by ID.
pub async fn create_resource_type(
platform_id: i64,
request: Json<CreateResourceTypeRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourceType>, (Status, Json<Value>)> {
// ... function body
}
Create a new resource type.
pub async fn update_resource_type(
platform_id: i64,
id: i32,
request: Json<UpdateResourceTypeRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourceType>, (Status, Json<Value>)> {
// ... function body
}
Update an existing resource type.
pub async fn delete_resource_type(
platform_id: i64,
id: i32,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a resource type.
pub async fn list_cost_metrics(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
resource_type_id: Option<i32>,
provider_id: Option<i64>,
app_id: Option<i64>,
start_date: Option<String>,
end_date: Option<String>,
billing_period: Option<String>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List cost metrics with pagination and filtering support.
pub async fn get_cost_metric(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostMetricWithType>, (Status, Json<Value>)> {
// ... function body
}
Get a specific cost metric by ID.
pub async fn create_cost_metric(
platform_id: i64,
request: Json<CreateCostMetricRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostMetric>, (Status, Json<Value>)> {
// ... function body
}
Create a new cost metric.
pub async fn delete_cost_metric(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a cost metric.
pub async fn analyze_costs_by_dimension(
platform_id: i64,
request: Json<CostAnalysisByDimensionRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Vec<(String, f64)>>, (Status, Json<Value>)> {
// ... function body
}
Get cost analysis by dimension (app, provider, resource_type, etc.)
pub async fn analyze_cost_over_time(
platform_id: i64,
request: Json<CostOverTimeRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Vec<(DateTime<Utc>, f64)>>, (Status, Json<Value>)> {
// ... function body
}
Get application cost over time
pub async fn list_cost_budgets(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List all cost budgets with pagination support.
pub async fn get_cost_budget(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostBudget>, (Status, Json<Value>)> {
// ... function body
}
Get a specific cost budget by ID.
pub async fn create_cost_budget(
platform_id: i64,
request: Json<CreateCostBudgetRequest>,
db_manager: &State<Arc<DatabaseManager>>,
user: User,
) -> Result<Json<CostBudget>, (Status, Json<Value>)> {
// ... function body
}
Create a new cost budget.
pub async fn update_cost_budget(
platform_id: i64,
id: i64,
request: Json<UpdateCostBudgetRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostBudget>, (Status, Json<Value>)> {
// ... function body
}
Update an existing cost budget.
pub async fn delete_cost_budget(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a cost budget.
pub async fn list_cost_projections(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List all cost projections with pagination support.
pub async fn get_cost_projection(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostProjection>, (Status, Json<Value>)> {
// ... function body
}
Get a specific cost projection by ID.
pub async fn create_cost_projection(
platform_id: i64,
request: Json<CreateCostProjectionRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostProjection>, (Status, Json<Value>)> {
// ... function body
}
Create a new cost projection.
pub async fn delete_cost_projection(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a cost projection.
pub async fn list_resource_pricing(
platform_id: i64,
page: Option<i64>,
per_page: Option<i64>,
resource_type_id: Option<i32>,
provider_id: Option<i64>,
region_id: Option<i64>,
pricing_model: Option<String>,
tier_name: Option<String>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
List resource pricing with pagination and filtering support.
pub async fn get_resource_pricing(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourcePricing>, (Status, Json<Value>)> {
// ... function body
}
Get a specific resource pricing entry by ID.
pub async fn create_resource_pricing(
platform_id: i64,
request: Json<CreateResourcePricingRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourcePricing>, (Status, Json<Value>)> {
// ... function body
}
Create a new resource pricing entry.
pub async fn update_resource_pricing(
platform_id: i64,
id: i64,
request: Json<UpdateResourcePricingRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<ResourcePricing>, (Status, Json<Value>)> {
// ... function body
}
Update an existing resource pricing entry.
pub async fn delete_resource_pricing(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a resource pricing entry.
pub async fn get_cost_allocation_tags(
platform_id: i64,
resource_id: i64,
resource_type: String,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Vec<CostAllocationTag>>, (Status, Json<Value>)> {
// ... function body
}
Get cost allocation tags for a specific resource.
pub async fn create_cost_allocation_tag(
platform_id: i64,
request: Json<CreateCostAllocationTagRequest>,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<CostAllocationTag>, (Status, Json<Value>)> {
// ... function body
}
Create a new cost allocation tag.
pub async fn delete_cost_allocation_tag(
platform_id: i64,
id: i64,
db_manager: &State<Arc<DatabaseManager>>,
) -> Result<Json<Value>, (Status, Json<Value>)> {
// ... function body
}
Delete a cost allocation tag.