@@ -169,7 +169,9 @@ impl Usage {
169
169
} )
170
170
. collect ( ) ;
171
171
172
- let total_cost = self . get_cost ( organization, user, start, end, now) . await ?;
172
+ let total_cost = self
173
+ . get_cost ( organization, user, None , start, end, now)
174
+ . await ?;
173
175
Ok ( UsageResult {
174
176
total_items : items_and_pages. number_of_items ,
175
177
num_pages : items_and_pages. number_of_pages ,
@@ -184,6 +186,7 @@ impl Usage {
184
186
& self ,
185
187
organization : Uuid ,
186
188
user : Option < Uuid > ,
189
+ cost_per_second : Option < i32 > ,
187
190
start : DateTime < FixedOffset > ,
188
191
end : DateTime < FixedOffset > ,
189
192
now : DateTime < FixedOffset > ,
@@ -196,6 +199,9 @@ impl Usage {
196
199
if let Some ( user) = user {
197
200
query = query. filter ( entities:: usage:: Column :: UserId . eq ( user) ) ;
198
201
}
202
+ if let Some ( cost_per_second) = cost_per_second {
203
+ query = query. filter ( entities:: usage:: Column :: CostPerSecond . eq ( cost_per_second) ) ;
204
+ }
199
205
let fixed_cost: Vec < Option < i64 > > = query
200
206
. select_only ( )
201
207
. column_as ( entities:: usage:: Column :: TotalCost . sum ( ) , "cost" )
@@ -228,6 +234,9 @@ impl Usage {
228
234
if let Some ( user) = user {
229
235
query = query. filter ( entities:: usage:: Column :: UserId . eq ( user) ) ;
230
236
}
237
+ if let Some ( cost_per_second) = cost_per_second {
238
+ query = query. filter ( entities:: usage:: Column :: CostPerSecond . eq ( cost_per_second) ) ;
239
+ }
231
240
232
241
let usages = query. all ( & self . db . conn ) . await ?;
233
242
@@ -256,6 +265,7 @@ impl Usage {
256
265
& self ,
257
266
organization : Uuid ,
258
267
user : Option < Uuid > ,
268
+ cost_per_second : Option < i32 > ,
259
269
date : DateTime < FixedOffset > ,
260
270
now : Option < DateTime < FixedOffset > > ,
261
271
) -> Result < usize > {
@@ -268,6 +278,7 @@ impl Usage {
268
278
self . get_cost (
269
279
organization,
270
280
user,
281
+ cost_per_second,
271
282
day_start,
272
283
day_end,
273
284
now. unwrap_or_else ( || Utc :: now ( ) . into ( ) ) ,
@@ -279,6 +290,7 @@ impl Usage {
279
290
& self ,
280
291
organization : Uuid ,
281
292
user : Option < Uuid > ,
293
+ cost_per_second : Option < i32 > ,
282
294
date : DateTime < FixedOffset > ,
283
295
now : Option < DateTime < FixedOffset > > ,
284
296
) -> Result < usize > {
@@ -305,6 +317,7 @@ impl Usage {
305
317
self . get_cost (
306
318
organization,
307
319
user,
320
+ cost_per_second,
308
321
month_start,
309
322
month_end,
310
323
now. unwrap_or_else ( || Utc :: now ( ) . into ( ) ) ,
@@ -414,6 +427,7 @@ pub mod tests {
414
427
. get_daily_cost (
415
428
organization,
416
429
Some ( user. id ) ,
430
+ None ,
417
431
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
418
432
None ,
419
433
)
@@ -436,6 +450,7 @@ pub mod tests {
436
450
. get_daily_cost (
437
451
organization,
438
452
Some ( user. id ) ,
453
+ None ,
439
454
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
440
455
None ,
441
456
)
@@ -458,6 +473,7 @@ pub mod tests {
458
473
. get_daily_cost (
459
474
organization,
460
475
Some ( user. id ) ,
476
+ None ,
461
477
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
462
478
Some ( Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 15 , 1 , 0 ) . unwrap ( ) . into ( ) ) ,
463
479
)
@@ -470,6 +486,7 @@ pub mod tests {
470
486
. get_daily_cost (
471
487
organization,
472
488
Some ( user. id ) ,
489
+ None ,
473
490
Utc . with_ymd_and_hms ( 2024 , 1 , 30 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
474
491
Some ( Utc . with_ymd_and_hms ( 2024 , 1 , 30 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ) ,
475
492
)
@@ -492,6 +509,7 @@ pub mod tests {
492
509
. get_daily_cost (
493
510
organization,
494
511
Some ( user. id ) ,
512
+ None ,
495
513
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
496
514
Some ( Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 15 , 1 , 0 ) . unwrap ( ) . into ( ) ) ,
497
515
)
@@ -514,6 +532,7 @@ pub mod tests {
514
532
. get_daily_cost (
515
533
organization,
516
534
Some ( user. id ) ,
535
+ None ,
517
536
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
518
537
Some ( Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 15 , 1 , 0 ) . unwrap ( ) . into ( ) ) ,
519
538
)
@@ -561,6 +580,7 @@ pub mod tests {
561
580
. get_monthly_cost (
562
581
organization,
563
582
Some ( user. id ) ,
583
+ None ,
564
584
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
565
585
None ,
566
586
)
@@ -583,6 +603,7 @@ pub mod tests {
583
603
. get_monthly_cost (
584
604
organization,
585
605
Some ( user. id ) ,
606
+ None ,
586
607
Utc . with_ymd_and_hms ( 2024 , 1 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
587
608
None ,
588
609
)
@@ -595,6 +616,7 @@ pub mod tests {
595
616
. get_monthly_cost (
596
617
organization,
597
618
Some ( user. id ) ,
619
+ None ,
598
620
Utc . with_ymd_and_hms ( 2023 , 12 , 29 , 1 , 0 , 0 ) . unwrap ( ) . into ( ) ,
599
621
None ,
600
622
)
0 commit comments