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 updateAClient(commandInPieces):
    # updates a client that is already in the repository
    # input - details about the client to be updated (id) and the values that must be edited
    repoCaller = Repo()
    listOfClients = repoCaller.getListOfClients()
    idToUpdate = commandInPieces[1]
    newId = commandInPieces[2]
    newName = commandInPieces[3]
    updatedClient = Client(newId, newName)
    position = 0
    try:
        validateAClient(updatedClient)
        for iterator in listOfClients:
            if Client.getClientId(iterator) == idToUpdate:
                if commandInPieces[0] != "undo":
                    undoFunction = Undo("updateC", [
                        "undo", newId,
                        Client.getClientId(iterator),
                        Client.getClientName(iterator), "undo",
                        Client.getClientId(iterator), newId, newName
                    ])
                    repoCaller.addToListOfOperations(undoFunction)
                    repoCaller.setRedoFalse()
                repoCaller.removeClientFromPosition(position)
                repoCaller.insertClientIntoPosition(position, updatedClient)
                repoCaller.loadIntoFiles()
                repoCaller.loadIntoPickle()

                break
            position += 1
    except ClientAlreadyExistsError:
        print(ClientAlreadyExistsError())
    return False
Esempio n. 3
0
def removeAClient(commandInPieces):
    # removes a client from the repository
    # input - details about the client (id)
    repoCaller = Repo()
    idToRemove = commandInPieces[1]
    position = 0
    removed = False

    for iterator in Repo.listOfClients:
        if Client.getClientId(iterator) == idToRemove:
            if commandInPieces[0] != "undo":
                undoFunction = Undo("addC", [
                    "undo",
                    Client.getClientId(iterator),
                    Client.getClientName(iterator)
                ])
                repoCaller.addToListOfOperations(undoFunction)
                repoCaller.setRedoFalse()
            repoCaller.removeClientFromPosition(position)
            repoCaller.loadIntoFiles()
            repoCaller.loadIntoPickle()
            removed = True
        position += 1
    if removed == False:
        print(IdOfClientDoesntExist())
    return False
Esempio n. 4
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
Esempio n. 5
0
def addAClient(commandInPieces):
    # adds a client to the repository
    # input - details about the client as a list
    repoCaller = Repo()
    clientId = commandInPieces[1]
    clientName = commandInPieces[2]
    undoFunction = Undo("removeC", ["undo", clientId, clientName])
    if commandInPieces[0] != "undo":
        repoCaller.addToListOfOperations(undoFunction)
        repoCaller.setRedoFalse()
    newClient = Client(clientId, clientName)
    try:
        validateAClient(newClient)
        repoCaller.addTheClientToTheRepo(newClient)
        repoCaller.loadIntoFiles()
        repoCaller.loadIntoPickle()
    except ClientAlreadyExistsError:
        print(str(ClientAlreadyExistsError()))
    return False
Esempio n. 6
0
def addABook(commandInPieces):
    # adds a book to the repository
    # input - details about the book as a list
    bookId = commandInPieces[1]
    repoCaller = Repo()
    bookTitle = commandInPieces[2]

    bookAuthor = commandInPieces[3]
    newBook = Book(bookId, bookTitle, bookAuthor)
    undoFunction = Undo("removeB", ["undo", bookId, bookTitle, bookAuthor])
    if commandInPieces[0] != "undo":
        repoCaller.addToListOfOperations(undoFunction)
        repoCaller.setRedoFalse()
    try:
        validateABook(newBook)
        repoCaller.addTheBookToTheRepo(newBook)
        repoCaller.loadIntoFiles()
        repoCaller.loadIntoPickle()
    except BookAlreadyExistsError:
        print(str(BookAlreadyExistsError()))
    return False