Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter, Depends, HTTPException | |
| from sqlalchemy.orm import Session | |
| from typing import List | |
| from app.db.session import SessionLocal | |
| from app.schemas.dictionary_entry import DictionaryEntry, DictionaryEntryCreate | |
| from app.services.dictionary_service import search_entries, get_entry, create_entry | |
| router = APIRouter() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def search(query: str = "", db: Session = Depends(get_db)): | |
| return search_entries(db, query) | |
| def read_entry(entry_id: int, db: Session = Depends(get_db)): | |
| entry = get_entry(db, entry_id) | |
| if not entry: | |
| raise HTTPException(status_code=404, detail="Entry not found") | |
| return entry | |
| def create(data: DictionaryEntryCreate, db: Session = Depends(get_db)): | |
| return create_entry(db, data) | |