feat: enhance activity and task APIs with improved payload handling and response models
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
"""Activity timeline API stubs."""
|
||||
"""Activity timeline endpoints backed by ActivityService."""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
|
||||
from app.api.deps import get_organization_context
|
||||
from app.api.deps import get_activity_service, get_organization_context
|
||||
from app.models.activity import ActivityRead
|
||||
from app.services.activity_service import (
|
||||
ActivityForbiddenError,
|
||||
ActivityListFilters,
|
||||
ActivityService,
|
||||
ActivityValidationError,
|
||||
)
|
||||
from app.services.organization_service import OrganizationContext
|
||||
|
||||
from .models import ActivityCommentPayload
|
||||
@@ -11,26 +18,44 @@ from .models import ActivityCommentPayload
|
||||
router = APIRouter(prefix="/deals/{deal_id}/activities", tags=["activities"])
|
||||
|
||||
|
||||
def _stub(endpoint: str) -> dict[str, str]:
|
||||
return {"detail": f"{endpoint} is not implemented yet"}
|
||||
|
||||
|
||||
@router.get("/", status_code=status.HTTP_501_NOT_IMPLEMENTED)
|
||||
@router.get("/", response_model=list[ActivityRead])
|
||||
async def list_activities(
|
||||
deal_id: int,
|
||||
limit: int = Query(50, ge=1, le=200),
|
||||
offset: int = Query(0, ge=0),
|
||||
context: OrganizationContext = Depends(get_organization_context),
|
||||
) -> dict[str, str]:
|
||||
"""Placeholder for listing deal activities."""
|
||||
_ = (deal_id, context)
|
||||
return _stub("GET /deals/{deal_id}/activities")
|
||||
service: ActivityService = Depends(get_activity_service),
|
||||
) -> list[ActivityRead]:
|
||||
"""Fetch paginated activities for the deal within the current organization."""
|
||||
|
||||
filters = ActivityListFilters(deal_id=deal_id, limit=limit, offset=offset)
|
||||
try:
|
||||
activities = await service.list_activities(filters=filters, context=context)
|
||||
except ActivityForbiddenError as exc:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
||||
|
||||
return [ActivityRead.model_validate(activity) for activity in activities]
|
||||
|
||||
|
||||
@router.post("/", status_code=status.HTTP_501_NOT_IMPLEMENTED)
|
||||
@router.post("/", response_model=ActivityRead, status_code=status.HTTP_201_CREATED)
|
||||
async def create_activity_comment(
|
||||
deal_id: int,
|
||||
payload: ActivityCommentPayload,
|
||||
context: OrganizationContext = Depends(get_organization_context),
|
||||
) -> dict[str, str]:
|
||||
"""Placeholder for adding a comment activity to a deal."""
|
||||
_ = (deal_id, payload, context)
|
||||
return _stub("POST /deals/{deal_id}/activities")
|
||||
service: ActivityService = Depends(get_activity_service),
|
||||
) -> ActivityRead:
|
||||
"""Add a comment to the deal timeline."""
|
||||
|
||||
try:
|
||||
activity = await service.add_comment(
|
||||
deal_id=deal_id,
|
||||
author_id=context.user_id,
|
||||
text=payload.extract_text(),
|
||||
context=context,
|
||||
)
|
||||
except ActivityValidationError as exc:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
|
||||
except ActivityForbiddenError as exc:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
||||
|
||||
return ActivityRead.model_validate(activity)
|
||||
|
||||
Reference in New Issue
Block a user