gitdataai/libs/api/project/billing.rs
2026-04-14 19:02:01 +08:00

54 lines
1.8 KiB
Rust

use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;
#[utoipa::path(
get,
path = "/api/projects/{project_name}/billing",
params(("project_name" = String, Path)),
responses(
(status = 200, description = "Get project billing", body = ApiResponse<service::project::billing::ProjectBillingCurrentResponse>),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Project"
)]
pub async fn project_billing(
service: web::Data<AppService>,
session: Session,
path: web::Path<String>,
) -> Result<HttpResponse, ApiError> {
let project_name = path.into_inner();
let resp = service
.project_billing_current(&session, project_name)
.await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
get,
path = "/api/projects/{project_name}/billing/history",
params(("project_name" = String, Path)),
responses(
(status = 200, description = "Get project billing history", body = ApiResponse<service::project::billing::ProjectBillingHistoryResponse>),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Project"
)]
pub async fn project_billing_history(
service: web::Data<AppService>,
session: Session,
path: web::Path<String>,
query: web::Query<service::project::billing::ProjectBillingHistoryQuery>,
) -> Result<HttpResponse, ApiError> {
let project_name = path.into_inner();
let resp = service
.project_billing_history(&session, project_name, query.into_inner())
.await?;
Ok(ApiResponse::ok(resp).to_response())
}