Feature: Add list unread books command#64
Closed
ishizuka-nkc wants to merge 1 commit intogithub:mainfrom
Closed
Conversation
- Add BookCollection.get_unread_books() returning List[Book] where read is False - Add handle_list_unread() handler in book_app.py - Register 'unread' command in COMMANDS dict - Update show_help() to document the new command - Add TestGetUnreadBooks with 19 comprehensive tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds CLI support to filter and display unread books in the sample book app, along with supporting collection APIs and expanded test coverage.
Changes:
- Added
BookCollection.get_unread_books()and wired a newunreadCLI command to display only unread books. - Added
search_books()support +searchCLI command, and introduced publication year range validation (1–2100). - Significantly expanded the test suite for
BookCollectionbehaviors and added tests forutils.get_book_details().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| samples/book-app-project/books.py | Adds year validation, search_books(), and get_unread_books() APIs on BookCollection. |
| samples/book-app-project/book_app.py | Adds unread + search CLI commands, refactors command dispatch via COMMANDS, and updates help output. |
| samples/book-app-project/tests/test_books.py | Reworks/expands collection tests, including persistence, search, and unread behavior. |
| samples/book-app-project/tests/test_utils.py | Adds unit tests for utils.get_book_details() input parsing/normalization behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+36
to
45
| if not year_str: | ||
| print("\nError: Year cannot be empty.\n") | ||
| return | ||
|
|
||
| try: | ||
| year = int(year_str) if year_str else 0 | ||
| year = int(year_str) | ||
| if year < 1 or year > 2100: | ||
| print("\nError: Year must be between 1 and 2100.\n") | ||
| return | ||
| collection.add_book(title, author, year) |
Comment on lines
+101
to
+109
| COMMANDS = { | ||
| "list": handle_list, | ||
| "unread": handle_list_unread, | ||
| "add": handle_add, | ||
| "remove": handle_remove, | ||
| "find": handle_find, | ||
| "search": handle_search, | ||
| "help": show_help, | ||
| } |
Collaborator
|
Appreciate the PR @ishizuka-nkc. Since changes to the code impact the output generated throughout the course chapters, we're going to leave it "as is" for now (changes to Python would have to be updated across the other languages as well). If we decide to make changes we'll refer back to this though in the future. Thanks again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
unreadcommand to the book app CLI that displays only books wherereadisFalse.Changes
books.pyBookCollection.get_unread_books() -> List[Book]method that returns all unread books using a list comprehensionbook_app.pyhandle_list_unread()handler function"unread"command in theCOMMANDSdictshow_help()to document the new commandtests/test_books.pyTestGetUnreadBooksclass with 19 comprehensive tests covering:add_book,mark_as_read, and persistenceUsage
Test Results