gitdataai/libs/api/user/billing.rs

60 lines
1.9 KiB
Rust

use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;
#[utoipa::path(
get,
path = "/api/users/me/billing",
responses(
(status = 200, description = "Get user billing", body = ApiResponse<service::user::billing::UserBillingResponse>),
(status = 401, description = "Unauthorized"),
),
tag = "User"
)]
pub async fn user_billing(
service: web::Data<AppService>,
session: Session,
) -> Result<HttpResponse, ApiError> {
let resp = service.user_billing_current(&session).await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
get,
path = "/api/users/me/billing/errors",
responses(
(status = 200, description = "Get user billing errors", body = ApiResponse<service::user::billing::UserBillingErrorsResponse>),
(status = 401, description = "Unauthorized"),
),
tag = "User"
)]
pub async fn user_billing_errors(
service: web::Data<AppService>,
session: Session,
) -> Result<HttpResponse, ApiError> {
let resp = service.user_billing_errors(&session).await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
get,
path = "/api/users/me/billing/history",
params(("page" = Option<u64>, Query), ("per_page" = Option<u64>, Query)),
responses(
(status = 200, description = "Get user billing history", body = ApiResponse<service::user::billing::UserBillingHistoryResponse>),
(status = 401, description = "Unauthorized"),
),
tag = "User"
)]
pub async fn user_billing_history(
service: web::Data<AppService>,
session: Session,
query: web::Query<service::user::billing::UserBillingHistoryQuery>,
) -> Result<HttpResponse, ApiError> {
let resp = service
.user_billing_history(&session, query.into_inner())
.await?;
Ok(ApiResponse::ok(resp).to_response())
}