
This commit adds new functionality for tracking user activities within the application, including: - Implementation of a new activity service to fetch and manage group activities. - Creation of a dedicated activity store to handle state management for activities. - Introduction of new API endpoints for retrieving paginated activity data. - Enhancements to the UI with new components for displaying activity feeds and items. - Refactoring of existing components to utilize the new activity features, improving user engagement and interaction. These changes aim to enhance the application's activity tracking capabilities and provide users with a comprehensive view of their interactions.
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database import get_session
|
|
from app.crud import activity as crud_activity
|
|
from app.schemas.activity import PaginatedActivityResponse
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get(
|
|
"/groups/{group_id}/activity",
|
|
response_model=PaginatedActivityResponse,
|
|
summary="Get group activity feed",
|
|
tags=["Activity"],
|
|
)
|
|
async def get_group_activity(
|
|
group_id: int,
|
|
limit: int = Query(20, ge=1, le=100),
|
|
cursor: Optional[int] = Query(None, description="Unix timestamp for pagination"),
|
|
db: AsyncSession = Depends(get_session),
|
|
):
|
|
"""
|
|
Retrieves a paginated feed of recent activities within a group.
|
|
"""
|
|
activities = await crud_activity.get_group_activity(db, group_id=group_id, limit=limit, cursor=cursor)
|
|
|
|
next_cursor = None
|
|
if activities and len(activities) == limit:
|
|
next_cursor = int(activities[-1].timestamp.timestamp())
|
|
|
|
return PaginatedActivityResponse(items=activities, cursor=next_cursor) |