Add horoscope-api, synastry, and backend services
- horoscope-api: Swiss Ephemeris natal charts, timezone/place resolution, POST /v1/natal and POST /v1/synastry - backend: users with roles, email/password and Google login, saved charts, synastries and invites, analyses with credit ledger, public shares, admin - shared crates: astro-engine, db (migrations), horoscope-client, service-kit - docker-compose with postgres, legacy Java project for reference Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
//! `POST /v1/synastry`: two sets of birth data -> two natal charts ->
|
||||
//! inter-chart aspects, house overlays and the composite chart.
|
||||
|
||||
use astro_engine::{ChartOptions, Synastry, calculate_synastry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::AppState;
|
||||
use crate::error::ApiError;
|
||||
use crate::natal::{self, Meta, NatalRequest, NatalResult};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SynastryRequest {
|
||||
pub person1: NatalRequest,
|
||||
pub person2: NatalRequest,
|
||||
/// Calculation options for both charts (per-person `options` are not allowed).
|
||||
#[serde(default)]
|
||||
pub options: ChartOptions,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SynastryResponse {
|
||||
pub person1: NatalResult,
|
||||
pub person2: NatalResult,
|
||||
#[serde(flatten)]
|
||||
pub synastry: Synastry,
|
||||
pub meta: Meta,
|
||||
}
|
||||
|
||||
fn person_chart(
|
||||
state: &AppState,
|
||||
label: &'static str,
|
||||
mut req: NatalRequest,
|
||||
options: ChartOptions,
|
||||
) -> Result<NatalResult, ApiError> {
|
||||
if req.options != ChartOptions::default() {
|
||||
return Err(
|
||||
ApiError::BadRequest("options must be given at the top level, not per person".into()).for_person(label)
|
||||
);
|
||||
}
|
||||
req.options = options;
|
||||
natal::calculate(state, req).map_err(|e| e.for_person(label))
|
||||
}
|
||||
|
||||
pub fn calculate(state: &AppState, req: SynastryRequest) -> Result<SynastryResponse, ApiError> {
|
||||
let person1 = person_chart(state, "person1", req.person1, req.options)?;
|
||||
let person2 = person_chart(state, "person2", req.person2, req.options)?;
|
||||
let mut synastry = calculate_synastry(&person1.chart, &person2.chart, &req.options);
|
||||
for (label, p) in [("person1", &person1), ("person2", &person2)] {
|
||||
if !p.time.time_known {
|
||||
synastry.warnings.push(format!(
|
||||
"Birth time of {label} is unknown: its angles are left out of the inter-chart aspects, there are no \
|
||||
house overlays into its chart, and the composite has no angles or houses."
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(SynastryResponse { person1, person2, synastry, meta: natal::meta(state) })
|
||||
}
|
||||
Reference in New Issue
Block a user