Weekly horoscope: its own page, a Monday e-mail, and one page for every e-mail setting
CI / test (push) Successful in 3m17s
CI / build (push) Skipped
CI / deploy (push) Skipped

- The week's sky on the member's own chart (horoscope-api POST /v1/week,
  astro_engine::week): the planets' aspects to the natal points with the day
  each is exact, positions, the Moon's signs, lunar phases, stations and sign
  changes; stored once per chart and week (weekly_skies, migration 0047).
- Its text is a 'weekly' analysis written by the summary's (cheap) model when
  the member opens /heti-horoszkop: one month per page, the newest week
  first, the waiting animation while it is written. In the menu, and linked
  from the chart page.
- Monday 7:00 e-mail (worker task 'weekly'): only that it is there; on by
  default for everyone with a chart, members of today too. Its footer opens
  /ertesitesek?token=…, where the weekly e-mail and every forum e-mail can
  be set without logging in; the mail client's one-click unsubscribe turns
  off the weekly one. Also a switch on the page and on the Profile page.
- Privacy notice (HU/EN) describes it; ratings, admin labels and the model
  page know the new kind.

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-27 09:40:09 +00:00
co-authored by Claude Opus 5.5
parent 50c29e4595
commit 0358e137f1
46 changed files with 2368 additions and 70 deletions
+1
View File
@@ -16,6 +16,7 @@ mod sky;
mod synastry;
#[cfg(test)]
mod tests;
mod week;
use std::path::PathBuf;
use std::sync::Arc;
+13
View File
@@ -17,6 +17,7 @@ use crate::forecast::{self, ForecastRequest, ForecastResponse};
use crate::natal::{self, NatalRequest, NatalResponse};
use crate::sky::{self, EventsQuery, EventsResponse, SkyQuery, SkyResponse};
use crate::synastry::{self, SynastryRequest, SynastryResponse};
use crate::week::{self, WeekRequest, WeekResponse};
type AppResult<T> = Result<Json<T>, ApiError>;
@@ -30,6 +31,7 @@ pub fn router(state: Arc<AppState>) -> Router {
.route("/v1/natal", post(natal_chart))
.route("/v1/synastry", post(synastry_chart))
.route("/v1/forecast", post(forecast_year))
.route("/v1/week", post(week_of_chart))
.route("/v1/sky", get(sky_now))
.route("/v1/sky/events", get(sky_events))
.layer(cors())
@@ -167,6 +169,17 @@ async fn forecast_year(
Ok(Json(response))
}
async fn week_of_chart(
State(state): State<Arc<AppState>>,
body: Result<Json<WeekRequest>, JsonRejection>,
) -> AppResult<WeekResponse> {
let Json(request) = body?;
let response = tokio::task::spawn_blocking(move || week::calculate(&state, request))
.await
.map_err(|e| ApiError::Internal(e.to_string()))??;
Ok(Json(response))
}
async fn sky_now(
State(state): State<Arc<AppState>>,
query: Result<Query<SkyQuery>, QueryRejection>,
+27
View File
@@ -319,6 +319,33 @@ async fn forecast_year_with_solar_return() {
assert_eq!(status, StatusCode::BAD_REQUEST);
}
#[tokio::test]
async fn one_week_of_a_chart() {
let birth = json!({"date": "1985-07-14", "time": "14:30", "country": "HU", "place": "Budapest"});
let (status, d) = call("POST", "/v1/week", Some(json!({"birth": birth, "start": "2026-11-30"}))).await;
assert_eq!(status, StatusCode::OK, "{d}");
assert_eq!(d["timezone"], "Europe/Budapest");
let w = &d["week"];
assert_eq!((w["start"].as_str(), w["end"].as_str()), (Some("2026-11-30"), Some("2026-12-06")));
assert_eq!(w["positions"].as_array().unwrap().len(), 9);
assert!(w["positions"][0]["house"].as_u64().is_some());
assert!(!w["moon_ingresses"].as_array().unwrap().is_empty());
// Unknown birth time: no houses.
let (status, u) = call(
"POST",
"/v1/week",
Some(json!({"birth": {"date": "1985-07-14", "country": "HU", "place": "Budapest"}, "start": "2026-11-30"})),
)
.await;
assert_eq!(status, StatusCode::OK, "{u}");
assert!(u["week"]["positions"][0]["house"].is_null());
// Not a Monday.
let (status, _) = call("POST", "/v1/week", Some(json!({"birth": birth, "start": "2026-12-01"}))).await;
assert_eq!(status, StatusCode::BAD_REQUEST);
}
#[tokio::test]
async fn sky_at_a_moment() {
// 2026-03-10 12:00 UTC: Mercury retrograde (26 Feb – 20 Mar), waning Moon.
+63
View File
@@ -0,0 +1,63 @@
//! `POST /v1/week`: one week of a natal chart, for the weekly horoscope: the
//! planets' aspects to the natal points (with the day each is exact), where
//! the planets stand, the Moon's sign changes, the lunar phases, and the
//! planets' stations and sign changes. The week runs from Monday 0:00 to the
//! next Monday on the clock of `tz` (default Europe/Budapest); the dates are
//! local days there.
use astro_engine::{Week, calculate_week};
use jiff::civil::Date;
use serde::{Deserialize, Serialize};
use crate::AppState;
use crate::error::ApiError;
use crate::natal::{self, NatalRequest};
use crate::sky::DEFAULT_TZ;
const UNIX_EPOCH_JD: f64 = 2_440_587.5;
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct WeekRequest {
/// Birth data as for `POST /v1/natal`.
pub birth: NatalRequest,
/// The Monday the week starts on, `YYYY-MM-DD`.
pub start: String,
#[serde(default)]
pub tz: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct WeekResponse {
pub timezone: String,
pub week: Week,
}
fn bad(msg: impl Into<String>) -> ApiError {
ApiError::BadRequest(msg.into())
}
pub fn calculate(state: &AppState, req: WeekRequest) -> Result<WeekResponse, ApiError> {
let start: Date = req.start.parse().map_err(|_| bad("start must be a date (YYYY-MM-DD)"))?;
if start.weekday() != jiff::civil::Weekday::Monday {
return Err(bad("start must be a Monday"));
}
if !(1900..=2100).contains(&start.year()) {
return Err(bad("start must be between 1900 and 2100"));
}
let zone_name = req.tz.unwrap_or_else(|| DEFAULT_TZ.to_string());
let tz = state.atlas.zones.get(&zone_name)?;
let natal = natal::calculate(state, req.birth).map_err(|e| e.for_person("birth"))?;
let jd_at = |date: Date| -> Result<(f64, f64), ApiError> {
let zoned = date.to_zoned(tz.clone()).map_err(|e| ApiError::Internal(e.to_string()))?;
let jd = zoned.timestamp().as_second() as f64 / 86_400.0 + UNIX_EPOCH_JD;
Ok((jd, f64::from(zoned.offset().seconds()) / 3600.0))
};
let (start_jd, offset) = jd_at(start)?;
let next = start.checked_add(jiff::Span::new().days(7)).map_err(|e| ApiError::Internal(e.to_string()))?;
let (end_jd, _) = jd_at(next)?;
let week = calculate_week(state.engine.as_ref(), &natal.chart, start_jd, end_jd, offset)
.map_err(|e| ApiError::Calculation(e.to_string()))?;
Ok(WeekResponse { timezone: zone_name, week })
}