(
session: SessionDep,
current_user: CurrentUser,
collection_id: uuid.UUID,
card_in: CardCreate,
provider: GeminiProviderDep,
)
| 138 | |
| 139 | @router.post("/collections/{collection_id}/cards/", response_model=Card) |
| 140 | async def create_card( |
| 141 | session: SessionDep, |
| 142 | current_user: CurrentUser, |
| 143 | collection_id: uuid.UUID, |
| 144 | card_in: CardCreate, |
| 145 | provider: GeminiProviderDep, |
| 146 | ) -> Any: |
| 147 | access_checked = await asyncio.to_thread( |
| 148 | lambda: services.check_collection_access( |
| 149 | session, collection_id, current_user.id |
| 150 | ) |
| 151 | ) |
| 152 | if not access_checked: |
| 153 | raise HTTPException(status_code=404, detail="Collection not found") |
| 154 | if card_in.prompt: |
| 155 | if not await asyncio.to_thread( |
| 156 | lambda: check_and_increment_ai_usage_quota(session, current_user) |
| 157 | ): |
| 158 | raise HTTPException( |
| 159 | status_code=429, detail="Quota for AI usage is reached." |
| 160 | ) |
| 161 | card_base = await services.generate_ai_flashcard(card_in.prompt, provider) |
| 162 | card_in.front = card_base.front |
| 163 | card_in.back = card_base.back |
| 164 | return await asyncio.to_thread( |
| 165 | lambda: services.create_card( |
| 166 | session=session, collection_id=collection_id, card_in=card_in |
| 167 | ) |
| 168 | ) |
| 169 | |
| 170 | |
| 171 | @router.get("/collections/{collection_id}/cards/{card_id}", response_model=Card) |
nothing calls this directly
no test coverage detected