- astro-engine: forecast module (solar return moment, slow-planet transits
with exact dates and periods, natal house ingresses, secondary
progressions, annual profection, eclipses via Swiss Ephemeris)
- horoscope-api: POST /v1/forecast, solar return chart cast for the place
of the birthday
- backend: forecasts table, /v1/charts/{id}/forecasts, /v1/forecasts/{id}
and its analyses using a new 'forecast' unit; current year of life open,
the next one 30 days before the birthday
- packages: Páros and Család include forecasts (6 000 / 11 000 Ft),
+1 éves előrejelzés add-on 2 500 Ft; Egy elemzés unchanged
- worker and prompt: forecast kind with five sections and forecast rules
(trends, no event predictions); no birth data, place or exact age sent
- frontend: /kepletek/{id}/elorejelzes with the solar return wheel, the
keys of the year, a monthly timeline, transit list and detailed forecast
- data export: forecasts added, model name removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
67 lines
2.4 KiB
Rust
67 lines
2.4 KiB
Rust
//! Packages and payments. Until Stripe is connected, `MOCK_PAYMENTS=true`
|
|
//! turns on a stand-in: "paying" grants the package right away, so the paid
|
|
//! flow can be used end to end.
|
|
|
|
use axum::Json;
|
|
use axum::extract::State;
|
|
use axum_extra::extract::WithRejection;
|
|
use serde::Deserialize;
|
|
use serde_json::{Value, json};
|
|
|
|
use super::{Body, St};
|
|
use crate::auth::AuthUser;
|
|
use crate::credits::{self, Unit};
|
|
use crate::error::{ApiError, ApiResult};
|
|
use crate::packages::{self, CATALOG, Source};
|
|
use crate::persons;
|
|
|
|
/// The package catalog (public).
|
|
pub async fn catalog() -> Json<Value> {
|
|
Json(json!({ "packages": CATALOG.iter().map(packages::Package::view).collect::<Vec<_>>() }))
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MockPayment {
|
|
/// A package id from the catalog.
|
|
package: Option<String>,
|
|
/// Shorthand: the cheapest package with one unit of this kind.
|
|
unit: Option<Unit>,
|
|
}
|
|
|
|
/// What the user has now: units left and person slots.
|
|
pub async fn holdings(state: &crate::AppState, auth: &AuthUser) -> Result<Value, ApiError> {
|
|
let mut conn = state.db.acquire().await?;
|
|
let balance = credits::balance(&mut conn, auth.id()).await?;
|
|
let persons = persons::slots(&mut conn, auth, state.config.free_person_slots).await?;
|
|
Ok(json!({
|
|
"analyses_left": balance.view(),
|
|
"persons": persons.view(),
|
|
}))
|
|
}
|
|
|
|
/// Grants a package as a (pretend) purchase.
|
|
pub async fn mock(
|
|
State(state): St,
|
|
auth: AuthUser,
|
|
WithRejection(Json(req), _): Body<MockPayment>,
|
|
) -> ApiResult<Json<Value>> {
|
|
if !state.config.mock_payments {
|
|
return Err(ApiError::NotFound("payment method"));
|
|
}
|
|
let id = match (req.package.as_deref(), req.unit) {
|
|
(Some(id), None) => id,
|
|
(None, Some(Unit::Natal)) => "single",
|
|
(None, Some(Unit::Synastry)) => "addon_synastry",
|
|
(None, Some(Unit::Forecast)) => "addon_forecast",
|
|
(None, Some(Unit::Person)) => "addon_persons",
|
|
_ => return Err(ApiError::BadRequest("give either package or unit".into())),
|
|
};
|
|
let package = packages::find(id).ok_or(ApiError::NotFound("package"))?;
|
|
let mut tx = state.db.begin().await?;
|
|
packages::grant(&mut tx, auth.id(), package, Source::Mock, Some(auth.id()), Some("mock payment")).await?;
|
|
tx.commit().await?;
|
|
tracing::info!(user = %auth.id(), package = package.id, "mock payment");
|
|
Ok(Json(holdings(&state, &auth).await?))
|
|
}
|