Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/).
18 changes: 18 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -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/).
Binary file added src/entities/__pycache__/board.cpython-37.pyc
Binary file not shown.
Binary file added src/entities/__pycache__/card.cpython-37.pyc
Binary file not shown.
Binary file added src/entities/__pycache__/list.cpython-37.pyc
Binary file not shown.
Binary file added src/entities/__pycache__/user.cpython-37.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions src/entities/board.py
Original file line number Diff line number Diff line change
@@ -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__

12 changes: 12 additions & 0 deletions src/entities/card.py
Original file line number Diff line number Diff line change
@@ -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


9 changes: 9 additions & 0 deletions src/entities/list.py
Original file line number Diff line number Diff line change
@@ -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 = []
14 changes: 14 additions & 0 deletions src/entities/user.py
Original file line number Diff line number Diff line change
@@ -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




168 changes: 168 additions & 0 deletions src/trello.py
Original file line number Diff line number Diff line change
@@ -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.")




Binary file added src/utils/__pycache__/uid.cpython-37.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions src/utils/uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import uuid


def get_unique_id():
return (uuid.uuid1().hex)