This commit is contained in:
xds
2026-02-24 12:11:19 +03:00
parent f07105b0e5
commit bc9230a49b
8 changed files with 147 additions and 22 deletions

View File

@@ -66,6 +66,7 @@ async def get_generations(
character_id: Optional[str] = None,
limit: int = 10,
offset: int = 0,
only_liked: bool = False,
generation_service: GenerationService = Depends(get_generation_service),
current_user: dict = Depends(get_current_user),
project_id: Optional[str] = Depends(get_project_id),
@@ -75,13 +76,16 @@ async def get_generations(
# If project_id is set, we don't filter by user to show all project-wide generations
created_by_filter = None if project_id else str(current_user["_id"])
only_liked_by = str(current_user["_id"]) if only_liked else None
return await generation_service.get_generations(
character_id=character_id,
limit=limit,
offset=offset,
created_by=created_by_filter,
project_id=project_id
project_id=project_id,
only_liked_by=only_liked_by,
current_user_id=str(current_user["_id"])
)
@@ -150,7 +154,7 @@ async def get_generation_group(
generation_service: GenerationService = Depends(get_generation_service),
current_user: dict = Depends(get_current_user)
):
return await generation_service.get_generations_by_group(group_id)
return await generation_service.get_generations_by_group(group_id, current_user_id=str(current_user["_id"]))
@router.get("/{generation_id}", response_model=GenerationResponse)
@@ -159,7 +163,7 @@ async def get_generation(
generation_service: GenerationService = Depends(get_generation_service),
current_user: dict = Depends(get_current_user)
) -> GenerationResponse:
gen = await generation_service.get_generation(generation_id)
gen = await generation_service.get_generation(generation_id, current_user_id=str(current_user["_id"]))
if not gen:
raise HTTPException(status_code=404, detail="Generation not found")
@@ -176,6 +180,18 @@ async def get_generation(
return gen
@router.post("/{generation_id}/like", response_model=dict)
async def toggle_like(
generation_id: str,
generation_service: GenerationService = Depends(get_generation_service),
current_user: dict = Depends(get_current_user)
):
is_liked = await generation_service.toggle_like(generation_id, str(current_user["_id"]))
if is_liked is None:
raise HTTPException(status_code=404, detail="Generation not found")
return {"is_liked": is_liked}
@router.post("/import", response_model=GenerationResponse)
async def import_external_generation(
request: Request,