| 14 | |
| 15 | |
| 16 | def _get_collection_basic_info( |
| 17 | session: Session, collection_id: uuid.UUID |
| 18 | ) -> CollectionBasicInfo: |
| 19 | collection = session.get(Collection, collection_id) |
| 20 | if not collection: |
| 21 | raise ValueError( |
| 22 | f"Collection with id {collection_id} not found in _get_collection_basic_info" |
| 23 | ) |
| 24 | collection_name = collection.name |
| 25 | total_cards_stmt = select(func.count(Card.id)).where( |
| 26 | Card.collection_id == collection_id |
| 27 | ) |
| 28 | total_cards = session.exec(total_cards_stmt).one() |
| 29 | total_sessions_stmt = select(func.count(PracticeSession.id)).where( |
| 30 | PracticeSession.collection_id == collection_id, |
| 31 | PracticeSession.is_completed, |
| 32 | ) |
| 33 | total_sessions = session.exec(total_sessions_stmt).one() |
| 34 | |
| 35 | return CollectionBasicInfo( |
| 36 | name=collection_name, |
| 37 | total_cards=total_cards, |
| 38 | total_practice_sessions=total_sessions, |
| 39 | ) |
| 40 | |
| 41 | |
| 42 | def _get_recent_sessions( |