async def delete(book_id: int, db: DatabaseSession = Depends(get_db)): model = db.query(Book).filter(Book.id == book_id).first() db.delete(model) db.commit() return { 'id': model.id, }
async def update(book_id: int, db: DatabaseSession = Depends(get_db)): model = db.query(Book).filter(Book.id == book_id).first() model.read = True db.add(model) db.commit() return { 'id': model.id, }
async def create(book: BookModel, db: DatabaseSession = Depends(get_db)): now = datetime.now() model = Book(title=book.title, created_at=now, read=False) db.add(model) db.commit() return { 'id': model.id, 'title': model.title, 'created_at': model.created_at.isoformat() }