#[allow(clippy::wildcard_imports)]
use super::*;
#[derive(Deserialize)]
pub(crate) struct RegistryNamespaceBody {
namespace: String,
#[serde(default)]
org_id: Option<String>,
}
pub(crate) async fn put_account_registry_namespace(
State(state): State<AppState>,
headers: HeaderMap,
Json(body): Json<RegistryNamespaceBody>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"PUT",
format!("/api/billing/registry/{user_id}/namespace"),
Some(json!({ "namespace": body.namespace, "org_id": body.org_id })),
)
.await?;
finish(status, json)
}
pub(crate) async fn get_account_registry(
State(state): State<AppState>,
headers: HeaderMap,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"GET",
format!("/api/billing/registry/{user_id}"),
None,
)
.await?;
finish(status, json)
}
#[derive(Deserialize, Default)]
pub(crate) struct RegistryTokenBody {
#[serde(default)]
label: Option<String>,
#[serde(default)]
scope: Option<String>,
}
pub(crate) async fn post_account_registry_token(
State(state): State<AppState>,
headers: HeaderMap,
Json(body): Json<RegistryTokenBody>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"POST",
format!("/api/billing/registry/{user_id}/tokens"),
Some(json!({ "label": body.label, "scope": body.scope })),
)
.await?;
finish(status, json)
}
pub(crate) async fn delete_account_registry_token(
State(state): State<AppState>,
headers: HeaderMap,
Path(token_id): Path<i64>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"DELETE",
format!("/api/billing/registry/{user_id}/tokens/{token_id}"),
None,
)
.await?;
finish(status, json)
}
#[derive(Deserialize)]
pub(crate) struct RegistryPriceBody {
name: String,
#[serde(default)]
price_cents: Option<i32>,
}
pub(crate) async fn put_account_registry_price(
State(state): State<AppState>,
headers: HeaderMap,
Json(body): Json<RegistryPriceBody>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"PUT",
format!("/api/billing/registry/{user_id}/price"),
Some(json!({ "name": body.name, "price_cents": body.price_cents })),
)
.await?;
finish(status, json)
}
#[derive(Deserialize)]
pub(crate) struct RegistryBuyBody {
namespace: String,
name: String,
}
pub(crate) async fn post_account_registry_buy(
State(state): State<AppState>,
headers: HeaderMap,
Json(body): Json<RegistryBuyBody>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"POST",
format!("/api/billing/registry/{user_id}/buy"),
Some(json!({
"namespace": body.namespace,
"name": body.name,
"email": email,
})),
)
.await?;
finish(status, json)
}
#[derive(Deserialize)]
pub(crate) struct RegistryDomainBody {
domain: String,
}
pub(crate) async fn post_account_registry_domain(
State(state): State<AppState>,
headers: HeaderMap,
Json(body): Json<RegistryDomainBody>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"POST",
format!("/api/billing/registry/{user_id}/domains"),
Some(json!({ "domain": body.domain })),
)
.await?;
finish(status, json)
}
pub(crate) async fn post_account_registry_domain_verify(
State(state): State<AppState>,
headers: HeaderMap,
Path(domain_id): Path<i64>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"POST",
format!("/api/billing/registry/{user_id}/domains/{domain_id}/verify"),
None,
)
.await?;
finish(status, json)
}
pub(crate) async fn delete_account_registry_domain(
State(state): State<AppState>,
headers: HeaderMap,
Path(domain_id): Path<i64>,
) -> Result<Json<Value>, (StatusCode, String)> {
let (user_id, _email) = auth_user(&state, &headers).await?;
let (status, json) = billing_forward(
&state.cfg,
"DELETE",
format!("/api/billing/registry/{user_id}/domains/{domain_id}"),
None,
)
.await?;
finish(status, json)
}