Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group 2 - refactoring library class #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Optional
from library.model.book import Book
from library.model.genre import Genre


class Library():

# Prints crime audio books
def print_longest_crime_audio_book(self) -> str:
crime_audio_books: list[Book] = []
max: Optional[Book] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

The max variable does not really tell us what this variable should be holding. Renaming it to longest_book would make it clearer

Suggested change
max: Optional[Book] = None
longest_book: Optional[Book] = None


# print banner
print("*********************************************")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will printed even if no book was found. Should maybe be inside the a condition.

print("********* Longest Crime Audio Book **********")
print("*********************************************")

for b in self.get_books():
if Genre.CRIME in b.genres:
if b._book_type == "Audio":
if max is not None and max.duration < b.duration:
max = b
# end if
# end if
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The else branch is not needed, because it does not perform any special functionality.

pass
# end else
# end for

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no check that a book was found! If no book was found, accessing the book member variables would throw an error.

Suggested change
if longest_book is not None:
print(f"Title: {max.title}")
print(f"Author: {max.authors}")
print(f"Duration: {max.duration}")
print(f"______________________________")

print(f"Title: {max.title}")
print(f"Author: {max.authors}")
print(f"Duration: {max.duration}")
print(f"______________________________")
return str(max)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The method should either return the book, or it should print the book to the console but not both.


# Constructor
def __init__(self, books: list[Book]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Constructor and member variables should be at the top of the class and commented

self._books = books

_books: list[Book] = []

def get_books(self) -> list[Book]:
return self._books