feat(trade-in): TI-1 mock /trade-in/estimate endpoint + Pydantic + SQL migration #316
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#316
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/ti-1-mock-estimate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Wave A для issue #314 TradeIn MVP. Mock backend, чтобы frontend (Wave B TI-3) мог стартовать integration пока objective_lots data не готов (issue #307 OBJ-1/2 ещё в работе).
POST /api/v1/trade-in/estimate— realistic ЕКБ mock prices by rooms/floor/repairGET /api/v1/trade-in/estimate/{estimate_id}— fetch saved estimate by UUID (для future PDF endpoint TI-2)trade_in_estimatesс full input snapshot + output JSON, TTL 24hbackend/app/schemas/trade_in.py:TradeInEstimateInput,AnalogLot,AggregatedEstimatedata/sql/115_trade_in_estimates.sql: table + 2 indexes + CHECK constraint on confidenceMock price bands (ЕКБ 2026)
Adjustments: ±5% floor (1st/top floor discount), ±10% repair_state. Генерит 7–10 analog listings + 3–5 actual_deals с реальными ЕКБ адресами (Малышева/Куйбышева/Восточная).
TI-1b (next PR — after OBJ-1/2 merge)
_mock_estimate()будет заменена на real SQL aggregation изobjective_lots+rosreestr_deals. GET endpoint и DB table уже production-ready.psycopg v3 compliance
Все SQL используют
CAST(:x AS uuid)/CAST(:x AS jsonb)— никаких:x::typeпосле bind params.Test plan
POST /api/v1/trade-in/estimate{"address":"ул. Малышева 10","area_m2":42,"rooms":1,"floor":5,"total_floors":17}→ 200 + AggregatedEstimate JSONdata/sql/115_trade_in_estimates.sql→ verify table + indexestrade_in_estimatesпосле POSTGET /api/v1/trade-in/estimate/{id}returns same shape with 200Part of issue #314 (Wave A — TI-1 mock).
Merged via deep-code-reviewer — verdict APPROVE.
Что проверено:
CAST(:id AS uuid)иCAST(:analogs AS jsonb)/CAST(:actual_deals AS jsonb)— корректно во всех queries, нет::typeпосле bind paramsjson.dumps(..., ensure_ascii=False)для jsonb binds — правильно115_идёт после114_— sequential ✅, BEGIN/COMMIT +IF NOT EXISTS— idempotentconfidence IN ('low','medium','high')матчит Pydantic Literalcreated_at DESC+expires_at— полезно для TTL queries/api/v1/trade-inвmain.pyMinor flags для TI-1b (не блокирующее):
expires_at > NOW()(app-side), но row не удаляется из таблицы — нуженpg_cronjobDELETE FROM trade_in_estimates WHERE expires_at < NOW() - interval '7 days'или подобное, иначе таблица растёт неограниченноTradeInEstimateInputпринимаетfloor=50, total_floors=5без ошибки — добавитьmodel_validatorнаfloor <= total_floors_gen_analogs()детерминирован (seed=42+rooms+n), ноn_analogs = random.randint(7, 10)использует globalrandomбез seed → разные размеры списков для same input. Если нужна полная детерминированность POST same input → same response — seed'и тоже_confidence(): всегда возвращаетhigh/medium, никогдаlow(хотя Literal допускает) — можно опустить доlowдля exotic rooms/arealat,lonв таблице, но не в Pydantic schema — будут всегда NULL до TI-1bWave B (TI-3 frontend integration) разблокирован.
Test plan для post-deploy verify:
data/sql/115_trade_in_estimates.sqlчерез deploy.yml auto-applycurl -X POST /api/v1/trade-in/estimate -d '{"address":"ул. Малышева 10","area_m2":42,"rooms":1,"floor":5,"total_floors":17}'→ 200 + AggregatedEstimateGET /api/v1/trade-in/estimate/{id}с returned UUID → same shapetrade_in_estimatesчерез SQL