Skip to content

Solution#640

Open
Rostyslavv11 wants to merge 3 commits into
mate-academy:mainfrom
Rostyslavv11:develop
Open

Solution#640
Rostyslavv11 wants to merge 3 commits into
mate-academy:mainfrom
Rostyslavv11:develop

Conversation

@Rostyslavv11
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Your implementation has two critical missing requirements that must be addressed: First, the task explicitly requires 'Filter books by author ID' as an API endpoint functionality - the GET /books endpoint only accepts skip/limit parameters but does not support filtering by author_id. You need to add an optional author_id query parameter to the endpoint and update the corresponding CRUD function to filter books by author. Second, the task explicitly requires 'Create the database tables using the SQLAlchemy models' at application startup, but the Base.metadata.create_all(bind=engine) call is missing from main.py (and related files). This initialization step is required and should be added before the FastAPI app definition. Both of these are explicit checklist items that must be implemented for task completion.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread crud.py
Comment on lines +42 to +46

def get_books_by_skip_limit(db: Session, skip: int, limit: int):
db_books = db.scalars(select(Book)).all()
return db_books[skip:skip + limit]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requirements explicitly state 'Filter books by author ID' as an API endpoint requirement, but this functionality is not implemented. There's no query parameter on GET /books to filter by author_id, nor a dedicated endpoint like GET /books?author_id=X.

Comment on lines +42 to +46
op.create_index(op.f('ix_books_id'), 'books', ['id'], unique=False)
op.create_index(op.f('ix_books_title'), 'books', ['title'], unique=False)
# ### end Alembic commands ###


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requirement states: 'Filter books by author ID'. This endpoint accepts skip/limit parameters but does not support filtering by author_id. Consider adding an optional author_id query parameter to filter books by a specific author.

Comment thread alembic/env.py Outdated
Comment on lines +46 to +47
target_metadata=target_metadata,
literal_binds=True,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requirements specify that the API must support filtering books by author ID, but this endpoint only accepts skip and limit query parameters without author_id filtering support.

Comment thread alembic/env.py Outdated
Comment on lines +12 to +23
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = [Base.metadata]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task explicitly requires creating database tables using the SQLAlchemy models at application startup. The Base.metadata.create_all(bind=engine) call is missing.

Comment thread db/models.py
from db.database import Base


class Author(Base):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task explicitly requires creating database tables using SQLAlchemy models at startup. Missing Base.metadata.create_all(bind=engine) call.

Comment thread main.py Outdated
Comment on lines +47 to +50

@app.get("/books", response_model=schemas.Book)
def get_books(skip: int = 0, limit: int = 0, db: Session = Depends(get_db)):
return get_books_by_skip_limit(db, skip, limit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task explicitly requires 'Filter books by author ID' as an API endpoint functionality, but the GET /books endpoint only accepts skip/limit parameters. No author_id filtering is implemented.

Comment thread main.py
Comment on lines +12 to +23


def get_db() -> Generator[Any, Any, None]:
db = SessionLocal()

try:
yield db
finally:
db.close()


@app.get("/")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires 'Create the database tables using the SQLAlchemy models' at application startup. This initialization step is missing - there's no call to Base.metadata.create_all(bind=engine) or similar.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

The GET /books endpoint has a critical bug that breaks optional filtering. On line 64 of main.py, the author_id parameter defaults to 0 instead of None, which means when the parameter is omitted, books are filtered by author_id=0 (returning an empty list) rather than returning all books. The crud.py function already correctly handles None with if author_id is not None, so the fix is straightforward: change author_id: int = 0 to author_id: int | None = None. This is a functional blocker since it breaks the expected behavior of the endpoint's optional filtering feature.

To fix: Update line 64 in main.py from author_id: int = 0 to author_id: int | None = None. This single change will make the optional filtering work as intended.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread main.py
Comment on lines +52 to +53

@app.get("/books", response_model=list[schemas.Book])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change author_id: int = 0 to author_id: int | None = None. With the current default of 0, when the query parameter is omitted, the endpoint will filter by author_id=0 (which doesn't exist) instead of returning all books. The crud function's if author_id is not None check treats 0 as a valid filter value, breaking the optional filtering behavior.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Your Library Management API implementation is approved. All requirements are met: FastAPI with SQLite and SQLAlchemy ORM is properly configured, all five required files are present with correct structure, Author and Book models include all specified fields with relationships, Pydantic schemas provide validation, CRUD functions handle database operations, and all API endpoints work as expected with pagination and optional author filtering. Great job fixing the optional filtering parameter - using author_id: int | None = None correctly allows returning all books when no author_id is provided. Your implementation demonstrates solid understanding of the FastAPI framework and database integration. Keep up the excellent work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants