Skip to content

Commit

Permalink
fix(api/accounting/server_cost): correct calc_for_server and time args
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro-Alessio Gierens <[email protected]>
  • Loading branch information
gierens committed Jan 28, 2025
1 parent 3b921c0 commit 2cd821b
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions api/src/routes/accounting/server_cost/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ async fn get_flavor_price_periods(
*current_prices
.get_mut(&UserClass::from_u32(price.user_class)?)
.unwrap()
.get_mut(&price.flavor_name)
.unwrap() = price.unit_price;
.entry(price.flavor_name.clone())
.or_insert(0.0) = price.unit_price;
// .get_mut(&price.flavor_name)
// .unwrap() = price.unit_price;
i += 1;
}

Expand All @@ -144,8 +146,10 @@ async fn get_flavor_price_periods(
*current_prices
.get_mut(&UserClass::from_u32(price.user_class)?)
.unwrap()
.get_mut(&price.flavor_name)
.unwrap() = price.unit_price;
.entry(price.flavor_name.clone())
.or_insert(0.0) = price.unit_price;
// .get_mut(&price.flavor_name)
// .unwrap() = price.unit_price;
} else {
periods.insert(current_time, current_prices.clone());
current_time = prices.get(i).unwrap().start_time.to_utc();
Expand Down Expand Up @@ -275,8 +279,8 @@ pub enum ServerCostForUser {
pub async fn calculate_server_cost_for_user(
transaction: &mut Transaction<'_, MySql>,
user_id: u64,
begin: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
begin: DateTime<Utc>,
end: DateTime<Utc>,
detail: Option<bool>,
) -> Result<ServerCostForUser, UnexpectedOnlyError> {
todo!()
Expand All @@ -292,8 +296,8 @@ pub enum ServerCostForProject {
pub async fn calculate_server_cost_for_project(
transaction: &mut Transaction<'_, MySql>,
project_id: u64,
begin: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
begin: DateTime<Utc>,
end: DateTime<Utc>,
detail: Option<bool>,
) -> Result<ServerCostForProject, UnexpectedOnlyError> {
todo!()
Expand All @@ -308,8 +312,8 @@ pub enum ServerCostForAll {

pub async fn calculate_server_cost_for_all(
transaction: &mut Transaction<'_, MySql>,
begin: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
begin: DateTime<Utc>,
end: DateTime<Utc>,
detail: Option<bool>,
) -> Result<ServerCostForAll, UnexpectedOnlyError> {
todo!()
Expand All @@ -324,7 +328,7 @@ pub enum ServerCost {
All(ServerCostForAll),
}

#[tracing::instrument(name = "server_consumption")]
#[tracing::instrument(name = "server_cost")]
pub async fn server_cost(
user: ReqData<User>,
// TODO: not necessary?
Expand All @@ -349,8 +353,8 @@ pub async fn server_cost(
ServerCost::All(
calculate_server_cost_for_all(
&mut transaction,
Some(begin.into()),
Some(end.into()),
begin.into(),
end.into(),
params.detail,
)
.await?,
Expand All @@ -360,8 +364,8 @@ pub async fn server_cost(
calculate_server_cost_for_project(
&mut transaction,
project_id as u64,
Some(begin.into()),
Some(end.into()),
begin.into(),
end.into(),
params.detail,
)
.await?,
Expand All @@ -371,8 +375,8 @@ pub async fn server_cost(
calculate_server_cost_for_user(
&mut transaction,
user_id as u64,
Some(begin.into()),
Some(end.into()),
begin.into(),
end.into(),
params.detail,
)
.await?,
Expand All @@ -382,8 +386,8 @@ pub async fn server_cost(
calculate_server_cost_for_server(
&mut transaction,
server_id.as_str(),
Some(begin.into()),
Some(end.into()),
begin.into(),
end.into(),
None,
)
.await?,
Expand All @@ -393,8 +397,8 @@ pub async fn server_cost(
calculate_server_cost_for_user(
&mut transaction,
user.id as u64,
Some(begin.into()),
Some(end.into()),
begin.into(),
end.into(),
params.detail,
)
.await?,
Expand Down

0 comments on commit 2cd821b

Please sign in to comment.