Esempio n. 1
0
def updateABook(commandInPieces):
    # updates a book from the repository
    # input - details about the book that must be updated(id) and the values that must be edited
    repoCaller = Repo()
    listOfBooks = repoCaller.getListOfBooks()
    idToUpdate = commandInPieces[1]
    newBookId = commandInPieces[2]
    newTitle = commandInPieces[3]
    newAuthor = commandInPieces[4]
    updatedBook = Book(newBookId, newTitle, newAuthor)
    position = 0
    try:
        validateABook(updatedBook)
        for iterator in listOfBooks:
            if Book.getBookId(iterator) == idToUpdate:
                if commandInPieces[0] != "undo":
                    undoFunction = Undo("updateB", [
                        "undo", newBookId,
                        Book.getBookId(iterator),
                        Book.getBookName(iterator),
                        Book.getBookAuthor(iterator), "undo", idToUpdate,
                        newBookId, newTitle, newAuthor
                    ])
                    repoCaller.addToListOfOperations(undoFunction)
                    repoCaller.setRedoFalse()
                repoCaller.removeBookFromPosition(position)
                repoCaller.insertBookIntoPosition(position, updatedBook)
                repoCaller.loadIntoFiles()
                repoCaller.loadIntoPickle()
                break
            position += 1
    except BookAlreadyExistsError:
        print(BookAlreadyExistsError())
    return False
Esempio n. 2
0
def removeABook(commandInPieces):
    # removes a book from the repository
    # input - details about the book to be removed (id)
    repoCaller = Repo()
    listOfBooks = repoCaller.getListOfBooks()
    idToRemove = commandInPieces[1]
    position = 0
    removed = False
    for iterator in listOfBooks:

        if Book.getBookId(iterator) == idToRemove:
            if commandInPieces[0] != "undo":
                undoFunction = Undo("addB", [
                    "undo",
                    Book.getBookId(iterator),
                    Book.getBookName(iterator),
                    Book.getBookAuthor(iterator)
                ])
                repoCaller.addToListOfOperations(undoFunction)
                repoCaller.setRedoFalse()
            repoCaller.removeBookFromPosition(position)
            repoCaller.loadIntoFiles()
            repoCaller.loadIntoPickle()
            removed = True
        position += 1
    if removed == False:
        print(IdOfBookDoesntExist())
    return False