diff --git a/README.md b/README.md index f9aa26d..b910446 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,18 @@ -# mock-machine-coding-3 -Welcome to the 3rd Mock Machine Coding Round by [workat.tech](http://workat.tech). +# mock-machine-coding-3 : Trello -Please visit [this link](https://workattech.github.io/mock-machine-coding-3/) to participate. +Whats working : +- SHOW +- BOARD CREATE +- BOARD `id` name `name` +- BOARD `id` privacy `privacy` + +How to run + +``` +git clone https://github.com/raunaqness/mock-machine-coding-3/tree/trello-python +cd mock-machine-coding-3/src +python trello.py +``` + +Original Problem statement: [https://workattech.github.io/mock-machine-coding-3/](https://workattech.github.io/mock-machine-coding-3/). diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..b910446 --- /dev/null +++ b/src/README.md @@ -0,0 +1,18 @@ +# mock-machine-coding-3 : Trello + +Whats working : + +- SHOW +- BOARD CREATE +- BOARD `id` name `name` +- BOARD `id` privacy `privacy` + +How to run + +``` +git clone https://github.com/raunaqness/mock-machine-coding-3/tree/trello-python +cd mock-machine-coding-3/src +python trello.py +``` + +Original Problem statement: [https://workattech.github.io/mock-machine-coding-3/](https://workattech.github.io/mock-machine-coding-3/). diff --git a/src/entities/__pycache__/board.cpython-37.pyc b/src/entities/__pycache__/board.cpython-37.pyc new file mode 100644 index 0000000..f18de43 Binary files /dev/null and b/src/entities/__pycache__/board.cpython-37.pyc differ diff --git a/src/entities/__pycache__/card.cpython-37.pyc b/src/entities/__pycache__/card.cpython-37.pyc new file mode 100644 index 0000000..04ed08b Binary files /dev/null and b/src/entities/__pycache__/card.cpython-37.pyc differ diff --git a/src/entities/__pycache__/list.cpython-37.pyc b/src/entities/__pycache__/list.cpython-37.pyc new file mode 100644 index 0000000..ffbdc36 Binary files /dev/null and b/src/entities/__pycache__/list.cpython-37.pyc differ diff --git a/src/entities/__pycache__/user.cpython-37.pyc b/src/entities/__pycache__/user.cpython-37.pyc new file mode 100644 index 0000000..66e3263 Binary files /dev/null and b/src/entities/__pycache__/user.cpython-37.pyc differ diff --git a/src/entities/board.py b/src/entities/board.py new file mode 100644 index 0000000..7e072ca --- /dev/null +++ b/src/entities/board.py @@ -0,0 +1,16 @@ +from utils.uid import get_unique_id + +class Board(object): + + def __init__(self, name): + + self.id = get_unique_id() + self.name = name + self.privacy = "PUBLIC" + self.url = "https://trello.com/" + self.id + self.members = [] + self.lists = [] + + def json(self): + return self.__dict__ + diff --git a/src/entities/card.py b/src/entities/card.py new file mode 100644 index 0000000..7519a2c --- /dev/null +++ b/src/entities/card.py @@ -0,0 +1,12 @@ +from utils.uid import get_unique_id + +class Card(object): + + def __init__(self, name, description, assigned_user): + + self.id = get_unique_id + self.name = name + self.description = description + self.assigned_user = assigned_user + + diff --git a/src/entities/list.py b/src/entities/list.py new file mode 100644 index 0000000..85cb51e --- /dev/null +++ b/src/entities/list.py @@ -0,0 +1,9 @@ +from utils.uid import get_unique_id + +class List(object): + + def __init__(self, name): + + self.id = get_unique_id + self.name = name + self.cards = [] diff --git a/src/entities/user.py b/src/entities/user.py new file mode 100644 index 0000000..a190279 --- /dev/null +++ b/src/entities/user.py @@ -0,0 +1,14 @@ +from utils.uid import get_unique_id + +class User(object): + + def __init__(self, name, email): + + # Initialize the User + self.id = get_unique_id + self.name = name + self.email = email + + + + diff --git a/src/trello.py b/src/trello.py new file mode 100644 index 0000000..d4cfcc6 --- /dev/null +++ b/src/trello.py @@ -0,0 +1,168 @@ +from entities import user, board, list, card +import pdb + +class Manager(object): + def __init__(self): + + # initialize stuff here + self.boards = [] + self.users = [] + self.lists = [] + self.cards = [] + + def process_main_input(self, main_input): + + tokens = main_input.split(" ") + + if tokens[0] == "SHOW": + self.show(tokens[1:]) + + if tokens[0] == "BOARD": + self.process_board_input(tokens[1:]) + + if tokens[0] == "LIST": + self.process_list_input(tokens[1:]) + + if tokens[0] == "CARD": + self.process_card_input(tokens[1:]) + + def show(self, input_data): + + if len(input_data) == 0: + res = [] + for board in self.boards: + res.append(board.json()) + + print(res) + + else: + input_type_to_show = input_data[0] + input_type_id = input_data[1] + + if input_type_to_show == "BOARD": + self.show_board(input_type_id) + + if input_type_to_show == "CARD": + self.show_card(input_type_id) + + if input_type_to_show == "LIST": + self.show_list(input_type_id) + + def show_board(self, id): + # TODO + pass + + def show_card(self, id): + # TODO + pass + + def show_list(self, id): + # TODO + pass + + def process_board_input(self, input_data): + id_or_command = input_data[0] + + if id_or_command == "CREATE": + self.create_board(input_data[1:]) + else: + self.modify_board(input_data) + + def create_board(self, properties): + board_name = properties[0] + new_board = board.Board(board_name) + self.boards.append(new_board) + print("Created Board : " + new_board.id) + + + def modify_board(self, properties): + + if len(properties) < 3: + print("Incorrect params for Board.") + return + + id, key, val = properties + + board = self.get_board_by_id(id) + + if board is None: + print("Board with id : " + id + " does not exist.") + return + + if key.upper() == "NAME": + new_name = val + board.name = new_name + print("Name updated") + + elif key.upper() == "PRIVACY": + new_privacy = val + board.privacy = new_privacy + print("Privacy updated") + + else: + print("Incorrect param") + return + + print(board.json()) + return + + def get_board_by_id(self, id): + for board in self.boards: + if board.id == id: + return board + return None + + def process_list_input(self, input_data): + id_or_command = input_data[0] + + if id_or_command == "CREATE": + self.create_list(input_data[1:]) + else: + self.modify_list(input_data[1:]) + + def create_list(self, properties): + # TODO + pass + + def modify_list(self, properties): + # TODO + pass + + def process_card_input(self, input_data): + id_or_command = input_data[0] + + if id_or_command == "CREATE": + self.create_card(input_data[1:]) + else: + self.modify_card(input_data[1:]) + + def create_card(self, properties): + # TODO + pass + + def modify_card(self, properties): + # TODO + pass + + +if __name__ == "__main__": + m = Manager() + main_input = None + + # Initialize with some Data + m.process_main_input("SHOW") + m.process_main_input("BOARD CREATE board1") + + while True: + + main_input = str(input("Enter Input : ")) + if main_input == "QUIT": + break + + m.process_main_input(main_input) + + print("Exiting.") + + + + diff --git a/src/utils/__pycache__/uid.cpython-37.pyc b/src/utils/__pycache__/uid.cpython-37.pyc new file mode 100644 index 0000000..327adf9 Binary files /dev/null and b/src/utils/__pycache__/uid.cpython-37.pyc differ diff --git a/src/utils/uid.py b/src/utils/uid.py new file mode 100644 index 0000000..2dd4c7f --- /dev/null +++ b/src/utils/uid.py @@ -0,0 +1,5 @@ +import uuid + + +def get_unique_id(): + return (uuid.uuid1().hex)