diff --git a/lnvps_api/src/api/routes.rs b/lnvps_api/src/api/routes.rs index 069ba2d..5f3243b 100644 --- a/lnvps_api/src/api/routes.rs +++ b/lnvps_api/src/api/routes.rs @@ -61,7 +61,8 @@ pub fn routes() -> Vec { v1_time_series, v1_custom_template_calc, v1_create_custom_vm_order, - v1_get_payment_methods + v1_get_payment_methods, + v1_payment_history ]; #[cfg(feature = "nostr-domain")] api_routes.append(&mut super::nostr_domain::routes()); @@ -870,3 +871,22 @@ async fn v1_get_payment( ApiData::ok(payment.into()) } + +/// List payment history of a VM +#[openapi(tag = "VM")] +#[get("/api/v1/vm//payments")] +async fn v1_payment_history( + auth: Nip98Auth, + db: &State>, + id: u64, +) -> ApiResult> { + let pubkey = auth.event.pubkey.to_bytes(); + let uid = db.upsert_user(&pubkey).await?; + let vm = db.get_vm(id).await?; + if vm.user_id != uid { + return ApiData::err("VM does not belong to you"); + } + + let payments = db.list_vm_payment(id).await?; + ApiData::ok(payments.into_iter().map(|i| i.into()).collect()) +}