def handle_borrow_book_screen(self): book_id = book_to_borrow() if book_id is not None: for book in self.books: if book['id'] == book_id: book['loan'] = True serialize_book_to_json(self.books) self.state = 'logged_client'
def handle_adding_book_screen(self): book_input = user_input_book_properties() if book_input is not None: book = self.create_book(book_input) self.books.append(book) serialize_book_to_json(self.books) print("Pomyślnie dodano") self.state = 'logged_employee'
def handle_removing_book_screen(self): guid = user_input_book_guid() for book in self.books: if book['id'] == guid: self.books.remove(book) serialize_book_to_json(self.books) print("Pomyślnie usunięto") break serialize_book_to_json(self.books) self.state = 'logged_employee'
def handle_returning_book_screen(self): guid = user_input_book_guid() for d in self.books: if d['id'] == guid: if d['loan']: d['loan'] = False serialize_book_to_json(self.books) print("Zmieniono status") break else: print("Książka jest niewypożyczona") break self.state = 'logged_employee'
def run(self): while self.state != 'exit': if self.state == 'hello_screen': self.handle_welcome_screen() elif self.state == 'login': self.handle_login_screen() elif self.state == 'logged_employee': self.handle_logged_employee_screen() elif self.state == 'adding_book': self.handle_adding_book_screen() elif self.state == 'removing_book': self.handle_removing_book_screen() elif self.state == 'returning_book': self.handle_returning_book_screen() elif self.state == 'adding_user': self.handle_adding_user_screen() elif self.state == 'logged_client': self.handle_welcome_screen() elif self.state == 'search_book_set': self.handle_search_book_set_screen() elif self.state == 'borrow_book': self.handle_borrow_book_screen() elif self.state == 'add_employee_user': self.handle_add_user_screen(True) elif self.state == 'add_regular_user': self.handle_add_user_screen(False) else: self.state = 'hello_screen' serialize_user_to_json(self.users) serialize_book_to_json(self.books)