예제 #1
0
 def add(self, rental):
     if self.available_book(rental) is False:
         raise ServiceError('SERVICE ERROR: Not available book!')
     if self.available_client(rental) is False:
         raise ServiceError('SERVICE ERROR: Not available client')
     self._list_rentals.add(rental)
     undo = FunctionCall(self.delete, rental)
     redo = FunctionCall(self.add, rental)
     op = Operation(undo, redo)
     self._undo_controller.recordOperation(op)
예제 #2
0
 def add(self, book):
     if Validate.check_book(None, book) is False:
         raise ServiceError('Invalid input!')
     self._list_books.add(book)
     undo = FunctionCall(self._list_books.delete, book)
     redo = FunctionCall(self._list_books.add, book)
     op = Operation(undo, redo)
     self._undo_controller.recordOperation(op)
예제 #3
0
 def delete(self, client, var=True):
     if Validate.check_client(self, client) is False:
         raise ServiceError('Invalid input!')
     self._list_clients.delete(client)
     if var == True:
         undo = FunctionCall(self._list_clients.add, client)
         redo = FunctionCall(self._list_clients.delete, client)
         op = Operation(undo, redo)
         return op
예제 #4
0
 def add(self, client):
     # this function will get a client and add it to the list of clients
     if Validate.check_client(self, client) is False:
         raise ServiceError('Invalid input!')
     self._list_clients.add(client)
     undo = FunctionCall(self._list_clients.delete, client)
     redo = FunctionCall(self._list_clients.add, client)
     op = Operation(undo, redo)
     self._undo_controller.recordOperation(op)
예제 #5
0
 def delete(self, book, variable=True):
     # this function deletes an object from the list
     if Validate.check_book(None, book) is False:
         raise ServiceError('Invalid input!')
     if variable == True:
         self._list_books.delete(book)
         undo = FunctionCall(self.add, book)
         redo = FunctionCall(self.delete, book)
         operation = Operation(undo, redo)
         return operation
예제 #6
0
 def update(self, client, new_name):
     if Validate.check_client(self, client) is False:
         raise ServiceError('Invalid input!')
     client = self.find_client_by_id(client.id)
     old_name = client.name
     client.set_name(new_name)
     self._list_clients.update(client)
     undo = FunctionCall(self.update, client, old_name)
     redo = FunctionCall(self.update, client, new_name)
     op = Operation(undo, redo)
     self._undo_controller.recordOperation(op)
예제 #7
0
 def find_client_by_id(self, client_id):
     list = self.get_all()
     for element in list:
         if element.id == client_id:
             return element
     raise ServiceError('No element found!')
예제 #8
0
 def search(self, client):
     if Validate.check_client(self, client) is False:
         raise ServiceError('Invalid input!')
     return self._list_clients.search(client)
예제 #9
0
 def find_rental_by_id(self, rental_id):
     list = self.get_rentals()
     for element in list:
         if element.rental_id == rental_id:
             return element
     raise ServiceError('No elements found!')
예제 #10
0
 def find_book_by_id(self, book_id):
     list = self._list_books.get_all()
     for element in list:
         if str(element.id) == str(book_id):
             return element
     raise ServiceError('No element found!')
예제 #11
0
 def search(self, book):
     # this function returns the object if it is in the list
     if Validate.check_book(None, book) is False:
         raise ServiceError('Invalid input!')
     return self._list_books.search(book)