6ac118ae70
Daemon, StartOS wrapper, admin SPA, public buy/thank-you pages, discount codes, free-license redemption, Apply-discount UX, self-licensing, and v0.1.0 release notes.
26 lines
690 B
Rust
26 lines
690 B
Rust
//! Public product endpoints.
|
|
|
|
use crate::api::AppState;
|
|
use crate::db::repo;
|
|
use crate::error::{AppError, AppResult};
|
|
use axum::{
|
|
extract::{Path, State},
|
|
Json,
|
|
};
|
|
use serde_json::{json, Value};
|
|
|
|
pub async fn list(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
|
let products = repo::list_products(&state.db, true).await?;
|
|
Ok(Json(json!({ "products": products })))
|
|
}
|
|
|
|
pub async fn get(
|
|
State(state): State<AppState>,
|
|
Path(slug): Path<String>,
|
|
) -> AppResult<Json<Value>> {
|
|
let product = repo::get_product_by_slug(&state.db, &slug)
|
|
.await?
|
|
.ok_or_else(|| AppError::NotFound(format!("product '{slug}'")))?;
|
|
Ok(Json(json!(product)))
|
|
}
|