fix: correct imports in admin subscriptions module
- Use get_current_admin_api instead of non-existent get_current_admin - Use get_db from app.core.database - Replace generic NotFoundException with specific exceptions: - TierNotFoundException for tier lookup failures - ConflictException for duplicate tier codes - BusinessLogicException for tier deletion with active subscriptions - ResourceNotFoundException for subscription lookup failures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,8 @@ import logging
|
|||||||
from fastapi import APIRouter, Depends, Path, Query
|
from fastapi import APIRouter, Depends, Path, Query
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.api.deps import get_current_admin, get_db
|
from app.api.deps import get_current_admin_api
|
||||||
|
from app.core.database import get_db
|
||||||
from app.services.admin_subscription_service import admin_subscription_service
|
from app.services.admin_subscription_service import admin_subscription_service
|
||||||
from models.database.user import User
|
from models.database.user import User
|
||||||
from models.schema.billing import (
|
from models.schema.billing import (
|
||||||
@@ -43,7 +44,7 @@ logger = logging.getLogger(__name__)
|
|||||||
@router.get("/tiers", response_model=SubscriptionTierListResponse)
|
@router.get("/tiers", response_model=SubscriptionTierListResponse)
|
||||||
def list_subscription_tiers(
|
def list_subscription_tiers(
|
||||||
include_inactive: bool = Query(False, description="Include inactive tiers"),
|
include_inactive: bool = Query(False, description="Include inactive tiers"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -62,7 +63,7 @@ def list_subscription_tiers(
|
|||||||
@router.get("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
@router.get("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
||||||
def get_subscription_tier(
|
def get_subscription_tier(
|
||||||
tier_code: str = Path(..., description="Tier code"),
|
tier_code: str = Path(..., description="Tier code"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Get a specific subscription tier by code."""
|
"""Get a specific subscription tier by code."""
|
||||||
@@ -73,7 +74,7 @@ def get_subscription_tier(
|
|||||||
@router.post("/tiers", response_model=SubscriptionTierResponse, status_code=201)
|
@router.post("/tiers", response_model=SubscriptionTierResponse, status_code=201)
|
||||||
def create_subscription_tier(
|
def create_subscription_tier(
|
||||||
tier_data: SubscriptionTierCreate,
|
tier_data: SubscriptionTierCreate,
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Create a new subscription tier."""
|
"""Create a new subscription tier."""
|
||||||
@@ -87,7 +88,7 @@ def create_subscription_tier(
|
|||||||
def update_subscription_tier(
|
def update_subscription_tier(
|
||||||
tier_data: SubscriptionTierUpdate,
|
tier_data: SubscriptionTierUpdate,
|
||||||
tier_code: str = Path(..., description="Tier code"),
|
tier_code: str = Path(..., description="Tier code"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Update a subscription tier."""
|
"""Update a subscription tier."""
|
||||||
@@ -101,7 +102,7 @@ def update_subscription_tier(
|
|||||||
@router.delete("/tiers/{tier_code}", status_code=204)
|
@router.delete("/tiers/{tier_code}", status_code=204)
|
||||||
def delete_subscription_tier(
|
def delete_subscription_tier(
|
||||||
tier_code: str = Path(..., description="Tier code"),
|
tier_code: str = Path(..., description="Tier code"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -125,7 +126,7 @@ def list_vendor_subscriptions(
|
|||||||
status: str | None = Query(None, description="Filter by status"),
|
status: str | None = Query(None, description="Filter by status"),
|
||||||
tier: str | None = Query(None, description="Filter by tier"),
|
tier: str | None = Query(None, description="Filter by tier"),
|
||||||
search: str | None = Query(None, description="Search vendor name"),
|
search: str | None = Query(None, description="Search vendor name"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -161,7 +162,7 @@ def list_vendor_subscriptions(
|
|||||||
@router.get("/{vendor_id}", response_model=VendorSubscriptionWithVendor)
|
@router.get("/{vendor_id}", response_model=VendorSubscriptionWithVendor)
|
||||||
def get_vendor_subscription(
|
def get_vendor_subscription(
|
||||||
vendor_id: int = Path(..., description="Vendor ID"),
|
vendor_id: int = Path(..., description="Vendor ID"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Get subscription details for a specific vendor."""
|
"""Get subscription details for a specific vendor."""
|
||||||
@@ -181,7 +182,7 @@ def get_vendor_subscription(
|
|||||||
def update_vendor_subscription(
|
def update_vendor_subscription(
|
||||||
update_data: VendorSubscriptionUpdate,
|
update_data: VendorSubscriptionUpdate,
|
||||||
vendor_id: int = Path(..., description="Vendor ID"),
|
vendor_id: int = Path(..., description="Vendor ID"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -219,7 +220,7 @@ def list_billing_history(
|
|||||||
per_page: int = Query(20, ge=1, le=100),
|
per_page: int = Query(20, ge=1, le=100),
|
||||||
vendor_id: int | None = Query(None, description="Filter by vendor"),
|
vendor_id: int | None = Query(None, description="Filter by vendor"),
|
||||||
status: str | None = Query(None, description="Filter by status"),
|
status: str | None = Query(None, description="Filter by status"),
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""List billing history (invoices) across all vendors."""
|
"""List billing history (invoices) across all vendors."""
|
||||||
@@ -267,7 +268,7 @@ def list_billing_history(
|
|||||||
|
|
||||||
@router.get("/stats", response_model=SubscriptionStatsResponse)
|
@router.get("/stats", response_model=SubscriptionStatsResponse)
|
||||||
def get_subscription_stats(
|
def get_subscription_stats(
|
||||||
current_user: User = Depends(get_current_admin),
|
current_user: User = Depends(get_current_admin_api),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Get subscription statistics for admin dashboard."""
|
"""Get subscription statistics for admin dashboard."""
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ from math import ceil
|
|||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.exceptions import NotFoundException
|
from app.exceptions import (
|
||||||
|
BusinessLogicException,
|
||||||
|
ConflictException,
|
||||||
|
ResourceNotFoundException,
|
||||||
|
TierNotFoundException,
|
||||||
|
)
|
||||||
from models.database.subscription import (
|
from models.database.subscription import (
|
||||||
BillingHistory,
|
BillingHistory,
|
||||||
SubscriptionStatus,
|
SubscriptionStatus,
|
||||||
@@ -54,7 +59,7 @@ class AdminSubscriptionService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not tier:
|
if not tier:
|
||||||
raise NotFoundException(f"Tier '{tier_code}' not found")
|
raise TierNotFoundException(tier_code)
|
||||||
|
|
||||||
return tier
|
return tier
|
||||||
|
|
||||||
@@ -67,7 +72,7 @@ class AdminSubscriptionService:
|
|||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if existing:
|
if existing:
|
||||||
raise NotFoundException(
|
raise ConflictException(
|
||||||
f"Tier with code '{tier_data['code']}' already exists"
|
f"Tier with code '{tier_data['code']}' already exists"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -107,7 +112,7 @@ class AdminSubscriptionService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if active_subs > 0:
|
if active_subs > 0:
|
||||||
raise NotFoundException(
|
raise BusinessLogicException(
|
||||||
f"Cannot delete tier: {active_subs} active subscriptions are using it"
|
f"Cannot delete tier: {active_subs} active subscriptions are using it"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -172,7 +177,7 @@ class AdminSubscriptionService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
raise NotFoundException(f"Subscription for vendor {vendor_id} not found")
|
raise ResourceNotFoundException(f"Subscription for vendor {vendor_id} not found")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user