feat: Add promo preference survey on main page
- Add promo preference fields to User model (promo_preferred_maker, promo_preferred_model, promo_email_enabled) - Create API endpoints for getting/updating promo preferences - Create PromoPreference component with maker/model selection - Show login prompt for non-logged-in users when interacting - Add promo notification service to send emails when matching vehicles are added to promotion - Add multi-language translations (en, mn, ru, ko) 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, UploadFile, File, Query, Body
|
||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Query, Body, BackgroundTasks
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
import os
|
||||
@@ -17,6 +17,7 @@ from ..schemas.hero_banner import (
|
||||
from .auth import get_current_user
|
||||
from ..models import User
|
||||
from ..config import get_settings
|
||||
from ..services.promo_notification_service import notify_users_for_promo_vehicle
|
||||
|
||||
router = APIRouter(prefix="/hero-banners", tags=["hero-banners"])
|
||||
|
||||
@@ -309,15 +310,16 @@ async def upload_banner_image(
|
||||
# ==================== Banner Toggle & Ordering ====================
|
||||
|
||||
@router.post("/admin/toggle/{car_id}")
|
||||
def toggle_banner(
|
||||
async def toggle_banner(
|
||||
car_id: int,
|
||||
background_tasks: BackgroundTasks,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_admin_user)
|
||||
):
|
||||
"""차량의 배너 상태 토글 (Admin)
|
||||
|
||||
- HeroBanner 존재 → 삭제
|
||||
- HeroBanner 없음 → 생성
|
||||
- HeroBanner 없음 → 생성 (+ 프로모션 알림 이메일 전송)
|
||||
"""
|
||||
car = db.query(Car).filter(Car.id == car_id).first()
|
||||
if not car:
|
||||
@@ -360,4 +362,8 @@ def toggle_banner(
|
||||
car.is_banner = True
|
||||
db.commit()
|
||||
db.refresh(banner)
|
||||
|
||||
# Send promo notification emails in background
|
||||
background_tasks.add_task(notify_users_for_promo_vehicle, db, car)
|
||||
|
||||
return {"car_id": car_id, "is_banner": True, "banner_id": banner.id, "message": "Added to banner"}
|
||||
|
||||
Reference in New Issue
Block a user