Add recommended vehicle check to car view access
Cars that were recommended to the user (via vehicle request with 1CC payment) should be accessible without additional CC payment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import stripe
|
||||
import logging
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import User, Car, CarView, PerformanceCheckView, ChargeHistory, CarPerformanceCheck, CCPackage, DEFAULT_CC_PACKAGES
|
||||
from ..models import User, Car, CarView, PerformanceCheckView, ChargeHistory, CarPerformanceCheck, CCPackage, DEFAULT_CC_PACKAGES, VehicleRequest, RequestVehicle
|
||||
from ..models.settings import SystemSettings
|
||||
from ..models.user import PaymentSettings
|
||||
from ..schemas import UserResponse, CarViewResponse, PurchaseViewRequest
|
||||
@@ -135,13 +135,27 @@ def check_car_view(
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""Check if user has purchased view access for a specific car"""
|
||||
# Check if user purchased view access
|
||||
existing_view = db.query(CarView).filter(
|
||||
CarView.user_id == current_user.id,
|
||||
CarView.car_id == car_id
|
||||
).first()
|
||||
|
||||
if existing_view:
|
||||
return {
|
||||
"has_access": True,
|
||||
"cc_balance": current_user.cc_balance or 0
|
||||
}
|
||||
|
||||
# Check if this car was recommended to the user (paid 1 CC for recommendation)
|
||||
recommended_vehicle = db.query(RequestVehicle).join(VehicleRequest).filter(
|
||||
VehicleRequest.user_id == current_user.id,
|
||||
RequestVehicle.car_id == car_id,
|
||||
RequestVehicle.is_approved == True
|
||||
).first()
|
||||
|
||||
return {
|
||||
"has_access": existing_view is not None,
|
||||
"has_access": recommended_vehicle is not None,
|
||||
"cc_balance": current_user.cc_balance or 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user