From 074dd4041ff45f54e77a638a76c656ed2dce68eb Mon Sep 17 00:00:00 2001 From: gahusb Date: Tue, 7 Apr 2026 23:51:06 +0900 Subject: [PATCH] =?UTF-8?q?feat(realestate-lab):=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=EC=97=90=20=EB=A7=A4=EC=B9=AD=20=EC=A0=90?= =?UTF-8?q?=EC=88=98=20=ED=8F=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _enrich_items()로 통합: 가격 범위 + match_score/reasons/eligible_types - 프로필 기반 매칭 점수가 공고 카드에 바로 표시됨 Co-Authored-By: Claude Opus 4.6 --- realestate-lab/app/db.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/realestate-lab/app/db.py b/realestate-lab/app/db.py index 6b96377..d22aed4 100644 --- a/realestate-lab/app/db.py +++ b/realestate-lab/app/db.py @@ -235,11 +235,13 @@ def upsert_announcement(data: Dict[str, Any]) -> tuple: return _ann_row_to_dict(row), is_new -def _enrich_with_price(conn, items: List[Dict[str, Any]]) -> List[Dict[str, Any]]: - """공고 목록에 모델 기반 가격 범위를 추가한다.""" +def _enrich_items(conn, items: List[Dict[str, Any]]) -> List[Dict[str, Any]]: + """공고 목록에 모델 기반 가격 범위 + 매칭 점수를 추가한다.""" for item in items: + ann_id = item.get("id") hmno = item.get("house_manage_no") pno = item.get("pblanc_no") + # 가격 정보 if hmno and pno: price_row = conn.execute( "SELECT MIN(top_amount) as min_price, MAX(top_amount) as max_price " @@ -249,6 +251,16 @@ def _enrich_with_price(conn, items: List[Dict[str, Any]]) -> List[Dict[str, Any] if price_row and price_row["min_price"] is not None: item["min_price"] = price_row["min_price"] item["max_price_display"] = price_row["max_price"] + # 매칭 점수 + if ann_id: + match_row = conn.execute( + "SELECT match_score, match_reasons, eligible_types FROM match_results WHERE announcement_id = ?", + (ann_id,), + ).fetchone() + if match_row: + item["match_score"] = match_row["match_score"] + item["match_reasons"] = json.loads(match_row["match_reasons"]) if match_row["match_reasons"] else [] + item["eligible_types"] = json.loads(match_row["eligible_types"]) if match_row["eligible_types"] else [] return items @@ -296,7 +308,7 @@ def get_announcements( params + [size, offset], ).fetchall() items = [_ann_row_to_dict(r) for r in rows] - items = _enrich_with_price(conn, items) + items = _enrich_items(conn, items) return { "items": items, "total": total, @@ -617,7 +629,7 @@ def get_dashboard() -> Dict[str, Any]: ORDER BY receipt_start ASC """).fetchall() bookmarked_items = [_ann_row_to_dict(r) for r in bookmarked_rows] - bookmarked_items = _enrich_with_price(conn, bookmarked_items) + bookmarked_items = _enrich_items(conn, bookmarked_items) return { "active_count": active,