Adding entries
In this section, let us focus on adding a Person
or a Company
contact to AddressBook
. We will start with the business logic and then we will link the business logic to the CLI part of our application.
The business logic
We will first write all the code related to the addition of contact. We will have two functions: add_person
and add_company
. Both functions are similar, however, they both receive different information as parameters. Let us first talk about the similarities between these two functions.
The first similarity is that both functions take db
as a parameter. So, we have the following:
def add_person(db: IO[bytes], ...): #... def add_company(db: IO[bytes], ...): #...
Next, both functions will use read_from_db
to get the potentially already existing serialized data, and then write_to_db
to save the newly updated data. Both functions will contain the following beginning and ending:
book = read_from_db(db) if book.contacts...