Detailed analysis button, loading wheel, birth data change limits
CI / test (push) Successful in 41s
CI / build (push) Successful in 4m11s
CI / deploy (push) Skipped

Backend:
- own birth data: three corrections within an hour of the first save,
  then one change per 24 hours (birth_data_changes); 429
  birth_data_change_limit with the user-facing message; /v1/me
  birth_change shows the notice; admins are not limited
- admins get detailed analyses free (no unit spent)
- POST /v1/payments/mock (MOCK_PAYMENTS): stand-in payment that adds a
  unit, until Stripe is connected; on in the compose files for now

Frontend:
- detailed analysis offer: admin starts it free, users with units
  confirm, others go through the (stand-in) payment step
- turning wheel with elapsed time while the summary or the analysis is
  being written
- no "adatok javítása" on the chart page (only in the profile), limit
  notice there; wheel hover highlighting removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 06:45:33 +00:00
co-authored by Claude Opus 5.5
parent 85337f2c79
commit e5cfbd6cdd
23 changed files with 544 additions and 110 deletions
+4 -1
View File
@@ -28,12 +28,15 @@ pub async fn me(State(state): St, auth: AuthUser) -> ApiResult<Json<Value>> {
.bind(auth.id())
.fetch_optional(&state.db)
.await?;
let balance = credits::balance(&mut *state.db.acquire().await?, auth.id()).await?;
let mut conn = state.db.acquire().await?;
let balance = credits::balance(&mut conn, auth.id()).await?;
let birth_change = crate::birth_changes::view(&mut conn, &auth).await?;
Ok(Json(json!({
"user": UserView::from(&auth.user),
"providers": providers.into_iter().map(|(p,)| p).collect::<Vec<_>>(),
"primary_chart_id": primary.map(|(id,)| id),
"analyses_left": balance.view(),
"birth_change": birth_change,
})))
}
+7 -4
View File
@@ -1,7 +1,7 @@
//! Text analyses (LLM) of charts and synastries.
//!
//! A request creates a `pending` analysis and spends one unit of its kind
//! (`natal` or `synastry`, see [`credits`]); the worker
//! (`natal` or `synastry`, see [`credits`]; admins pay nothing); the worker
//! writes the text later. A finished analysis with the same cache key (same
//! chart or synastry hash, prompt version, model and language) is copied
//! instead, free of charge, so the same chart is never paid for twice.
@@ -29,6 +29,7 @@ use crate::auth::AuthUser;
use crate::credits::{self, Unit};
use crate::error::{ApiError, ApiResult};
use crate::views::{rfc3339, rfc3339_opt, sha256_hex};
use db::Role;
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct AnalysisRow {
@@ -117,12 +118,14 @@ async fn request(
req: AnalysisRequest,
) -> ApiResult<(StatusCode, Json<Value>)> {
let language = validate_locale(state, Some(req.language.as_deref().unwrap_or(&auth.user.locale)))?;
// Admins get detailed analyses free of charge.
let unit = match target {
Target::Synastry { .. } => Unit::Synastry,
_ => Unit::Natal,
_ if auth.user.has_role(Role::Admin) => None,
Target::Synastry { .. } => Some(Unit::Synastry),
_ => Some(Unit::Natal),
};
let model = state.config.analysis_model.clone();
let (status, row) = queue(state, auth.id(), &target, &language, &model, Some(unit)).await?;
let (status, row) = queue(state, auth.id(), &target, &language, &model, unit).await?;
Ok((status, Json(row.view())))
}
+10 -1
View File
@@ -14,6 +14,7 @@ use uuid::Uuid;
use super::{Body, IdPath, St};
use crate::AppState;
use crate::auth::AuthUser;
use crate::birth_changes;
use crate::error::{ApiError, ApiResult};
use crate::views::{chart_hash, chart_highlights, rfc3339};
@@ -130,7 +131,8 @@ fn clean_birth(birth: Value) -> Result<Value, ApiError> {
/// Saves a new chart. If the user already has a chart with exactly the same
/// birth data, that one is returned (and made primary if asked) instead of
/// calculating it again.
/// calculating it again. Replacing the user's own chart counts against the
/// birth data change limit ([`birth_changes`]).
pub async fn create(
State(state): St,
auth: AuthUser,
@@ -157,6 +159,7 @@ pub async fn create(
.bind(chart.id)
.fetch_one(&mut *tx)
.await?;
birth_changes::record(&mut tx, &auth, row.id).await?;
tx.commit().await?;
queue_summary(&state, &auth, &row).await;
return Ok((StatusCode::OK, Json(row.owner_view())));
@@ -194,6 +197,9 @@ pub async fn create(
.bind(hash)
.fetch_one(&mut *tx)
.await?;
if req.is_primary {
birth_changes::record(&mut tx, &auth, row.id).await?;
}
tx.commit().await?;
queue_summary(&state, &auth, &row).await;
Ok((StatusCode::CREATED, Json(row.owner_view())))
@@ -243,6 +249,9 @@ pub async fn update(
.bind(id)
.fetch_one(&mut *tx)
.await?;
if is_primary && !chart.is_primary {
birth_changes::record(&mut tx, &auth, id).await?;
}
tx.commit().await?;
Ok(Json(row.owner_view()))
}
+3
View File
@@ -10,6 +10,7 @@ mod admin;
mod analyses;
mod auth;
mod charts;
mod payments;
mod shares;
mod synastries;
@@ -63,6 +64,7 @@ pub fn router(state: Arc<AppState>) -> Router {
.route("/v1/me/password", post(account::change_password))
.route("/v1/me/export", get(account::export))
.route("/v1/credits", get(account::credits))
.route("/v1/payments/mock", post(payments::mock))
// charts
.route("/v1/charts", get(charts::list).post(charts::create))
.route("/v1/charts/{id}", get(charts::get_one).patch(charts::update).delete(charts::remove))
@@ -119,6 +121,7 @@ async fn public_config(State(state): St) -> Json<Value> {
"analysis_model": c.analysis_model,
"summary_model": c.summary_model,
"password_login": c.password_login,
"mock_payments": c.mock_payments,
"password_min_length": crate::auth::MIN_PASSWORD_LEN,
}))
}
+44
View File
@@ -0,0 +1,44 @@
//! Payments. Until Stripe is connected, `MOCK_PAYMENTS=true` turns on a
//! stand-in: "paying" adds one analysis unit 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 uuid::Uuid;
use super::{Body, St};
use crate::auth::AuthUser;
use crate::credits::{self, Unit};
use crate::error::{ApiError, ApiResult};
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MockPayment {
unit: Unit,
}
/// Adds one unit of the given kind 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 mut tx = state.db.begin().await?;
sqlx::query(
"INSERT INTO credit_ledger (id, user_id, unit, delta, reason, note) VALUES ($1, $2, $3, 1, 'purchase', 'mock payment')",
)
.bind(Uuid::now_v7())
.bind(auth.id())
.bind(req.unit.as_str())
.execute(&mut *tx)
.await?;
let balance = credits::balance(&mut tx, auth.id()).await?;
tx.commit().await?;
Ok(Json(json!({ "analyses_left": balance.view() })))
}