api/app/routers/plans.py
Yoga Pangestu 7bbe4e7295 Implement subscription, tenant, and user services with CRUD operations and associated tests
- 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.
2026-07-17 23:36:31 +07:00

43 lines
1.2 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.plan import PlanCreate, PlanResponse, PlanUpdate
from app.services.plan_service import (
create_plan,
delete_plan,
get_plan_by_id,
get_plan_list,
update_plan,
)
router = APIRouter(prefix="/plans", tags=["plans"])
@router.get("/", response_model=list[PlanResponse])
def list_plans(db: Session = Depends(get_db)):
return get_plan_list(db)
@router.get("/{id}", response_model=PlanResponse)
def get_plan(id: str, db: Session = Depends(get_db)):
return get_plan_by_id(db, id)
@router.post("/", status_code=status.HTTP_201_CREATED)
def create_plan_route(request: Request, data: PlanCreate, db: Session = Depends(get_db)):
plan = create_plan(db, data)
location = f"{request.url.path}{plan.id}"
return created_response(location)
@router.put("/{id}", response_model=PlanResponse)
def update_plan_route(id: str, data: PlanUpdate, db: Session = Depends(get_db)):
return update_plan(db, id, data)
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_plan_route(id: str, db: Session = Depends(get_db)):
delete_plan(db, id)