Tarot readings have a topic: general, relationship, work, self-knowledge
The new reading form starts with the topic; it steers how the model reads the cards (with the topic's own limits, e.g. no break-up predictions for relationships) and shows on the reading and in the list. Readings from before count as general. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -69,6 +69,8 @@ impl ReadingRow {
|
||||
"status": self.status,
|
||||
"spread": self.tarot["spread"],
|
||||
"spread_name": spread.map(|s| s.name),
|
||||
"topic": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.id),
|
||||
"topic_name": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.name),
|
||||
"question": self.tarot["question"],
|
||||
"cards": cards,
|
||||
"content": self.content,
|
||||
@@ -147,6 +149,8 @@ pub async fn get_one(State(state): St, auth: AuthUser, WithRejection(Path(id), _
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NewReading {
|
||||
spread: String,
|
||||
/// `general` (the default), `love`, `work` or `self`.
|
||||
topic: Option<String>,
|
||||
question: Option<String>,
|
||||
}
|
||||
|
||||
@@ -157,6 +161,7 @@ pub async fn create(
|
||||
WithRejection(Json(req), _): Body<NewReading>,
|
||||
) -> ApiResult<(StatusCode, Json<Value>)> {
|
||||
let spread = tarot::spread(&req.spread).ok_or_else(|| ApiError::BadRequest("unknown spread".into()))?;
|
||||
let topic = tarot::topic(req.topic.as_deref()).ok_or_else(|| ApiError::BadRequest("unknown topic".into()))?;
|
||||
let question = req.question.map(|q| q.trim().replace("\r\n", "\n")).filter(|q| !q.is_empty());
|
||||
if question.as_ref().is_some_and(|q| q.chars().count() > TAROT_QUESTION_MAX_CHARS) {
|
||||
return Err(ApiError::BadRequest(format!(
|
||||
@@ -179,6 +184,7 @@ pub async fn create(
|
||||
let (sun, moon, ascendant) = big_three(&state, auth.id()).await?;
|
||||
let reading = json!({
|
||||
"spread": spread.id,
|
||||
"topic": topic.id,
|
||||
"question": question,
|
||||
"cards": draw(spread),
|
||||
"sun": sun,
|
||||
|
||||
@@ -2593,7 +2593,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
app.chart(&anna, "Saját", true, "1990-07-01").await;
|
||||
let body = json!({"spread": "trinity", "question": "Merre induljak tovább?"});
|
||||
let body = json!({"spread": "trinity", "topic": "love", "question": "Merre induljak tovább?"});
|
||||
// No units: a package or the addon is needed.
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), body.clone()).await;
|
||||
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED, "{}", r.body);
|
||||
@@ -2610,6 +2610,8 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "nincs"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "topic": "pénz"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let long = "x".repeat(analysis_prompt::TAROT_QUESTION_MAX_CHARS + 1);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "question": long})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
@@ -2618,6 +2620,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
assert_eq!(r.status, StatusCode::ACCEPTED, "{}", r.body);
|
||||
assert_eq!(r.body["status"], "pending");
|
||||
assert_eq!(r.body["spread_name"], "Sorsfonalak hármas");
|
||||
assert_eq!((&r.body["topic"], &r.body["topic_name"]), (&json!("love"), &json!("Párkapcsolat")));
|
||||
assert_eq!(r.body["question"], "Merre induljak tovább?");
|
||||
let cards = r.body["cards"].as_array().unwrap();
|
||||
assert_eq!(cards.len(), 3);
|
||||
|
||||
Reference in New Issue
Block a user