feat: Add car availability check feature
- Add daily scheduled check for Carmodoo car availability - Add manual trigger button in admin settings - Mark sold cars as soldout=True automatically - Add settings for check time and enable/disable toggle - Display check status and statistics in admin UI 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..database import get_db
|
||||
@@ -6,6 +6,7 @@ from ..models.settings import SystemSettings
|
||||
from ..schemas.settings import SystemSettingsUpdate, SystemSettingsResponse
|
||||
from .auth import get_current_user
|
||||
from ..models import User
|
||||
from ..services.car_availability_service import run_car_availability_check
|
||||
|
||||
router = APIRouter(prefix="/settings", tags=["settings"])
|
||||
|
||||
@@ -71,3 +72,57 @@ def update_system_settings(
|
||||
db.commit()
|
||||
db.refresh(settings)
|
||||
return settings
|
||||
|
||||
|
||||
# ==================== Car Availability Check Endpoints ====================
|
||||
|
||||
@router.post("/car-availability-check")
|
||||
async def trigger_car_availability_check(
|
||||
background_tasks: BackgroundTasks,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_admin_user)
|
||||
):
|
||||
"""차량 판매상태 검증 즉시 실행 (Admin)"""
|
||||
# 백그라운드에서 실행
|
||||
async def run_check():
|
||||
from ..database import SessionLocal
|
||||
check_db = SessionLocal()
|
||||
try:
|
||||
await run_car_availability_check(check_db)
|
||||
finally:
|
||||
check_db.close()
|
||||
|
||||
import asyncio
|
||||
asyncio.create_task(run_check())
|
||||
|
||||
return {
|
||||
"message": "Car availability check started in background",
|
||||
"status": "running"
|
||||
}
|
||||
|
||||
|
||||
@router.get("/car-availability-status")
|
||||
def get_car_availability_status(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_admin_user)
|
||||
):
|
||||
"""차량 판매상태 검증 상태 조회 (Admin)"""
|
||||
settings = get_or_create_settings(db)
|
||||
|
||||
# soldout 통계
|
||||
from ..models.car import Car
|
||||
total_cars = db.query(Car).filter(Car.source == 'carmodoo').count()
|
||||
available_cars = db.query(Car).filter(Car.source == 'carmodoo', Car.soldout == False).count()
|
||||
sold_cars = db.query(Car).filter(Car.source == 'carmodoo', Car.soldout == True).count()
|
||||
|
||||
return {
|
||||
"check_enabled": settings.car_availability_check_enabled,
|
||||
"check_hour": settings.car_availability_check_hour,
|
||||
"last_check": settings.car_availability_last_check,
|
||||
"last_result": settings.car_availability_last_result,
|
||||
"stats": {
|
||||
"total_cars": total_cars,
|
||||
"available": available_cars,
|
||||
"sold": sold_cars
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user