Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions apps/labrinth/src/routes/internal/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
pub user_id: Option<ariadne::ids::UserId>,
}

#[derive(Serialize)]
struct UserSubscriptionWithNextChargeTaxAmount {
#[serde(flatten)]
pub subscription: UserSubscription,
pub next_charge_tax_amount: Option<i64>,
}

#[get("subscriptions")]
/// List subscriptions.
#[utoipa::path(
context_path = "/billing",
Expand All @@ -114,7 +122,7 @@
responses((status = OK, body = serde_json::Value))
)]
#[get("/subscriptions")]
pub async fn subscriptions(

Check failure on line 125 in apps/labrinth/src/routes/internal/billing.rs

View workflow job for this annotation

GitHub Actions / Lint and Test

the trait bound `subscriptions: Handler<_>` is not satisfied
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
Expand All @@ -131,7 +139,7 @@
.await?
.1;

let subscriptions =
let db_subscriptions =
user_subscription_item::DBUserSubscription::get_all_user(
if let Some(user_id) = query.user_id {
if user.role.is_admin() {
Expand All @@ -147,10 +155,20 @@
},
&**pool,
)
.await?
.into_iter()
.map(UserSubscription::from)
.collect::<Vec<_>>();
.await?;

let mut subscriptions = Vec::with_capacity(db_subscriptions.len());
for subscription in db_subscriptions {
let next_charge_tax_amount =
DBCharge::get_open_subscription(subscription.id, &**pool)
.await?
.map(|charge| charge.tax_amount);

subscriptions.push(UserSubscriptionWithNextChargeTaxAmount {
subscription: UserSubscription::from(subscription),
next_charge_tax_amount,
});
}

Ok(HttpResponse::Ok().json(subscriptions))
}
Expand Down
1 change: 1 addition & 0 deletions packages/api-client/src/modules/labrinth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export namespace Labrinth {
status: SubscriptionStatus
created: string
metadata?: SubscriptionMetadata
next_charge_tax_amount?: number | null
}

export type SubscriptionMetadata =
Expand Down
Loading