Include Loyalty/Communication/Sports Center backends and registry updates alongside production nginx and compose wiring. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
"""Campaign APIs — Phase 7.0 shell."""
|
|
from __future__ import annotations
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.api.deps import get_db, get_pagination, require_tenant
|
|
from app.api.permissions import require_permissions
|
|
from app.permissions.definitions import (
|
|
LOYALTY_CAMPAIGNS_CREATE,
|
|
LOYALTY_CAMPAIGNS_DELETE,
|
|
LOYALTY_CAMPAIGNS_UPDATE,
|
|
LOYALTY_CAMPAIGNS_VIEW,
|
|
)
|
|
from app.schemas.foundation import CampaignCreate, CampaignRead, CampaignUpdate
|
|
from app.services.foundation import CampaignService
|
|
from shared.pagination import PaginationParams
|
|
from shared.security import CurrentUser
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("", response_model=CampaignRead, status_code=status.HTTP_201_CREATED)
|
|
async def create_campaign(
|
|
body: CampaignCreate,
|
|
tenant_id: UUID = Depends(require_tenant),
|
|
db: AsyncSession = Depends(get_db),
|
|
user: CurrentUser = Depends(require_permissions(LOYALTY_CAMPAIGNS_CREATE)),
|
|
):
|
|
return await CampaignService(db).create(tenant_id, body, actor=user)
|
|
|
|
|
|
@router.get("", response_model=list[CampaignRead])
|
|
async def list_campaigns(
|
|
tenant_id: UUID = Depends(require_tenant),
|
|
pagination: PaginationParams = Depends(get_pagination),
|
|
db: AsyncSession = Depends(get_db),
|
|
_user: CurrentUser = Depends(require_permissions(LOYALTY_CAMPAIGNS_VIEW)),
|
|
):
|
|
return await CampaignService(db).list(
|
|
tenant_id, offset=pagination.offset, limit=pagination.page_size
|
|
)
|
|
|
|
|
|
@router.get("/{campaign_id}", response_model=CampaignRead)
|
|
async def get_campaign(
|
|
campaign_id: UUID,
|
|
tenant_id: UUID = Depends(require_tenant),
|
|
db: AsyncSession = Depends(get_db),
|
|
_user: CurrentUser = Depends(require_permissions(LOYALTY_CAMPAIGNS_VIEW)),
|
|
):
|
|
return await CampaignService(db).get(tenant_id, campaign_id)
|
|
|
|
|
|
@router.patch("/{campaign_id}", response_model=CampaignRead)
|
|
async def update_campaign(
|
|
campaign_id: UUID,
|
|
body: CampaignUpdate,
|
|
tenant_id: UUID = Depends(require_tenant),
|
|
db: AsyncSession = Depends(get_db),
|
|
user: CurrentUser = Depends(require_permissions(LOYALTY_CAMPAIGNS_UPDATE)),
|
|
):
|
|
return await CampaignService(db).update(
|
|
tenant_id, campaign_id, body, actor=user
|
|
)
|
|
|
|
|
|
@router.post("/{campaign_id}/delete", response_model=CampaignRead)
|
|
async def soft_delete_campaign(
|
|
campaign_id: UUID,
|
|
tenant_id: UUID = Depends(require_tenant),
|
|
db: AsyncSession = Depends(get_db),
|
|
user: CurrentUser = Depends(require_permissions(LOYALTY_CAMPAIGNS_DELETE)),
|
|
):
|
|
return await CampaignService(db).soft_delete(
|
|
tenant_id, campaign_id, actor=user
|
|
)
|