부동산 청약 단지 관리 API 추가
- realestate_complexes 테이블 추가 (lotto.db) - CRUD 엔드포인트 4개: GET/POST /api/realestate/complexes, PUT/DELETE /api/realestate/complexes/:id - status: 청약예정|청약중|결과발표|완료, priority: high|normal|low 검증 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ from .db import (
|
||||
get_all_todos, create_todo, update_todo, delete_todo, delete_done_todos,
|
||||
# blog
|
||||
get_all_posts, create_post, update_post, delete_post,
|
||||
# realestate
|
||||
get_all_complexes, get_complex, create_complex, update_complex, delete_complex,
|
||||
)
|
||||
from .recommender import recommend_numbers, recommend_with_heatmap
|
||||
from .collector import sync_latest, sync_ensure_all
|
||||
@@ -670,3 +672,82 @@ def api_blog_delete(post_id: int):
|
||||
if not ok:
|
||||
raise HTTPException(status_code=404, detail="Post not found")
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
# ── RealEstate API ─────────────────────────────────────────────────────────────
|
||||
|
||||
VALID_STATUSES = {"청약예정", "청약중", "결과발표", "완료"}
|
||||
VALID_PRIORITIES = {"high", "normal", "low"}
|
||||
|
||||
|
||||
class ComplexCreate(BaseModel):
|
||||
name: str
|
||||
address: str = ""
|
||||
lat: Optional[float] = None
|
||||
lng: Optional[float] = None
|
||||
units: Optional[int] = None
|
||||
types: List[str] = []
|
||||
avgPricePerPyeong: Optional[int] = None
|
||||
subscriptionStart: Optional[str] = None
|
||||
subscriptionEnd: Optional[str] = None
|
||||
resultDate: Optional[str] = None
|
||||
status: str = "청약예정"
|
||||
priority: str = "normal"
|
||||
tags: List[str] = []
|
||||
naverUrl: str = ""
|
||||
floorPlanUrl: str = ""
|
||||
memo: str = ""
|
||||
|
||||
|
||||
class ComplexUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
address: Optional[str] = None
|
||||
lat: Optional[float] = None
|
||||
lng: Optional[float] = None
|
||||
units: Optional[int] = None
|
||||
types: Optional[List[str]] = None
|
||||
avgPricePerPyeong: Optional[int] = None
|
||||
subscriptionStart: Optional[str] = None
|
||||
subscriptionEnd: Optional[str] = None
|
||||
resultDate: Optional[str] = None
|
||||
status: Optional[str] = None
|
||||
priority: Optional[str] = None
|
||||
tags: Optional[List[str]] = None
|
||||
naverUrl: Optional[str] = None
|
||||
floorPlanUrl: Optional[str] = None
|
||||
memo: Optional[str] = None
|
||||
|
||||
|
||||
@app.get("/api/realestate/complexes")
|
||||
def api_realestate_list():
|
||||
return get_all_complexes()
|
||||
|
||||
|
||||
@app.post("/api/realestate/complexes", status_code=201)
|
||||
def api_realestate_create(body: ComplexCreate):
|
||||
if body.status not in VALID_STATUSES:
|
||||
raise HTTPException(status_code=400, detail=f"status must be one of {VALID_STATUSES}")
|
||||
if body.priority not in VALID_PRIORITIES:
|
||||
raise HTTPException(status_code=400, detail=f"priority must be one of {VALID_PRIORITIES}")
|
||||
return create_complex(body.model_dump())
|
||||
|
||||
|
||||
@app.put("/api/realestate/complexes/{complex_id}")
|
||||
def api_realestate_update(complex_id: int, body: ComplexUpdate):
|
||||
data = body.model_dump(exclude_none=True)
|
||||
if "status" in data and data["status"] not in VALID_STATUSES:
|
||||
raise HTTPException(status_code=400, detail=f"status must be one of {VALID_STATUSES}")
|
||||
if "priority" in data and data["priority"] not in VALID_PRIORITIES:
|
||||
raise HTTPException(status_code=400, detail=f"priority must be one of {VALID_PRIORITIES}")
|
||||
updated = update_complex(complex_id, data)
|
||||
if updated is None:
|
||||
raise HTTPException(status_code=404, detail="Complex not found")
|
||||
return updated
|
||||
|
||||
|
||||
@app.delete("/api/realestate/complexes/{complex_id}")
|
||||
def api_realestate_delete(complex_id: int):
|
||||
ok = delete_complex(complex_id)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=404, detail="Complex not found")
|
||||
return {"ok": True}
|
||||
|
||||
Reference in New Issue
Block a user