- Added subscription_service.py for managing subscriptions with functions to create, read, update, and delete subscriptions. - Added tenant_service.py for managing tenants with functions to create, read, update, delete tenants, and assign users to tenants. - Added user_service.py for managing users with functions to create, read, update, and delete users. - Created tests for business types, plans, subscriptions, tenants, and users, ensuring proper functionality and error handling. - Implemented pagination in user listing and included user profiles in responses. - Established fixtures for database setup and teardown in tests.
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from fastapi import APIRouter, Depends, Request, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.database import get_db
|
|
from app.responses import created_response
|
|
from app.schemas.subscription import (
|
|
SubscriptionCreate,
|
|
SubscriptionResponse,
|
|
SubscriptionUpdate,
|
|
)
|
|
from app.services.subscription_service import (
|
|
create_subscription,
|
|
delete_subscription,
|
|
get_subscription_by_id,
|
|
get_subscription_list,
|
|
update_subscription,
|
|
)
|
|
|
|
router = APIRouter(prefix="/subscriptions", tags=["subscriptions"])
|
|
|
|
|
|
@router.get("/", response_model=list[SubscriptionResponse])
|
|
def list_subscriptions(db: Session = Depends(get_db)):
|
|
return get_subscription_list(db)
|
|
|
|
|
|
@router.get("/{id}", response_model=SubscriptionResponse)
|
|
def get_subscription(id: str, db: Session = Depends(get_db)):
|
|
return get_subscription_by_id(db, id)
|
|
|
|
|
|
@router.post("/", status_code=status.HTTP_201_CREATED)
|
|
def create_subscription_route(
|
|
request: Request, data: SubscriptionCreate, db: Session = Depends(get_db)
|
|
):
|
|
sub = create_subscription(db, data)
|
|
location = f"{request.url.path}{sub.id}"
|
|
return created_response(location)
|
|
|
|
|
|
@router.put("/{id}", response_model=SubscriptionResponse)
|
|
def update_subscription_route(
|
|
id: str, data: SubscriptionUpdate, db: Session = Depends(get_db)
|
|
):
|
|
return update_subscription(db, id, data)
|
|
|
|
|
|
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
def delete_subscription_route(id: str, db: Session = Depends(get_db)):
|
|
delete_subscription(db, id)
|