def get_swim_lane(self, board_id, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): swim_lane_obj = SwimLane() swim_lane_obj.boardId = board_id # Fetching the swimlane collection swim_lanes_collection = self.__get_swim_lane_collection() cursor = swim_lanes_collection\ .find({"boardId" : swim_lane_obj.boardId}).sort("position") swim_lanes = [] for swim_lane in cursor: swim_lane_obj = SwimLane() swim_lane_obj.boardId = str(swim_lane['boardId']) swim_lane_obj.laneId = str(swim_lane['_id']) swim_lane_obj.title = swim_lane['title'] swim_lane_obj.position = swim_lane['position'] task_service = TaskService() swim_lane_obj.cards = task_service.get_tasks( str(swim_lane['_id']), headers) swim_lanes.append(swim_lane_obj) # Closing the DB connection self.mongo_db.disconnect() # Returning list of swimlanes return swim_lanes else: return "Invalid Authorization" except Exception as exception: raise exception
def create_task(self, task, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a task object task_obj = Task() task_obj.title = task['title'] task_obj.laneId = task['laneId'] task_obj.description = task['description'] task_obj.userId = payload['sub'] task_obj.position = task['position'] task_obj.notificationTimeMinutes = task[ 'notificationTimeMinutes'] # Storing the task in tasks collection task_collection = self.__get_task_collection() saved_task = task_collection.insert_one(task_obj.__dict__) # Storing the task_id in the object and returning task_obj.id = str(saved_task.inserted_id) # Closing the DB connection self.mongo_db.disconnect() return task_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def edit_swim_lane(self, swimlane, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a swim_lane object swim_lane_obj = SwimLane() swim_lane_obj.title = swimlane['title'] swim_lane_obj.boardId = swimlane['boardId'] swim_lane_obj.position = swimlane['position'] swim_lane_obj.id = swimlane['id'] # Updating the swim_lane in swimlanes collection swim_lanes_collection = self.__get_swim_lane_collection() query = {'_id': ObjectId(swim_lane_obj.id)} updated_values = {"$set": swim_lane_obj.__dict__} swim_lanes_collection.update_one(query, updated_values) # Closing the DB connection self.mongo_db.disconnect() return swim_lane_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def create_swim_lane(self, swimlane, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a swim_lane object swim_lane_obj = SwimLane() swim_lane_obj.title = swimlane['title'] swim_lane_obj.boardId = swimlane['boardId'] swim_lane_obj.position = swimlane['position'] # Storing the swim_lane in swimlanes collection swim_lanes_collection = self.__get_swim_lane_collection() saved_swim_lane = swim_lanes_collection.insert_one( swim_lane_obj.__dict__) # Storing the swimlane_id in the object and returning swim_lane_obj.id = str(saved_swim_lane.inserted_id) # Closing the DB connection self.mongo_db.disconnect() return swim_lane_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def get_boards(self, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): board_obj = Board() board_obj.user_id = payload['sub'] # Fetching thee board collection boards_collection = self.__get_board_collection() cursor = boards_collection.find({"user_id": board_obj.user_id}) # Creating a list named boards boards = [] for board in cursor: board_obj = Board() board_obj.board_id = str(board['_id']) board_obj.user_id = board['user_id'] board_obj.description = board['description'] board_obj.color = board['color'] board_obj.name = board['name'] board_obj.image = board['image'] boards.append(board_obj) # Returning list return boards else: return "Invalid Authorization" except Exception as exception: raise exception
def edit_board(self, board, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a board object board_obj = Board() board_obj.user_id = payload['sub'] board_obj.name = board['name'] board_obj.board_id = board['board_id'] board_obj.description = board['description'] board_obj.color = board['color'] board_obj.image = board['image'] # Checking if the image is being passed or not if (board['image'] and len(board['image']) > 0): # Storing the image in Amazon S3 bucket amazon_s3_handler = AmazonS3Handler() board_obj.image = amazon_s3_handler.store_in_S3( board['image'], board['board_id']) # Updating the board boards_collection = self.__get_board_collection() query = {'_id': ObjectId(board_obj.board_id)} updated_values = {"$set": board_obj.__dict__} boards_collection.update_one(query, updated_values) # Closing the DB connection self.mongo_db.disconnect() return board_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def create_board(self, board, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a board object board_obj = Board() board_obj.user_id = payload['sub'] board_obj.name = board['name'] board_obj.color = board['color'] # Storing the board in boards collection boards_collection = self.__get_board_collection() saved_board = boards_collection.insert_one(board_obj.__dict__) # Stroing the board_id in the object and returning board_obj.board_id = str(saved_board.inserted_id) # Closing the DB connection self.mongo_db.disconnect() return board_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def edit_user_details(self, user, headers): # logic to update user data try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a user object user_obj = User() user_obj.user_id = payload['sub'] user_obj.name = user['name'] user_obj.email = user['email'] user_obj.image = user['image'] user_obj.emailNotification = user['emailNotification'] user_obj.pushNotification = user['pushNotification'] # Checking if the image is being passed or not if (user['image']): # Storing the image in Amazon S3 bucket amazon_s3_handler = AmazonS3Handler() user_obj.image = amazon_s3_handler.store_in_S3( user['image'], user_obj.user_id) users_collection = self.__get_user_collection() if ("password" in user.keys() and user['password'] != "" and user['password'] == user['confirmPassword']): user_obj.password = self.crypto_handler.encrypt_the_string( user['password']) else: try: if (users_collection and users_collection.find( {'_id': ObjectId(user_obj.user_id)})): cursor = users_collection.find( {'_id': ObjectId(user_obj.user_id)}) user_obj.password = cursor[0]['password'] except Exception as exception: raise exception # Updating the user collecion query = {'_id': ObjectId(user_obj.user_id)} updated_values = {"$set": user_obj.__dict__} users_collection.update_one(query, updated_values) # Closing the DB connection self.mongo_db.disconnect() user_obj.password = None return user_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def get_calendar(self, client_type, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if(payload): # Fetching thee tasks collection tasks_collection = self.__get_tasks_collection() cursor = tasks_collection.find({"userId" : payload['sub']}) # Formatting the data as per the client type if(client_type == "android"): return self.get_calendar_data_for_android(cursor) if(client_type == "web"): return self.get_calendar_data_for_web(cursor) else: return "Invalid Authorization" except Exception as exception: raise exception
def edit_task(self, task, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): # Creating a task object task_obj = Task() task_obj.title = task['title'] task_obj.laneId = task['laneId'] task_obj.id = task['id'] task_obj.dueDateTime = task['dueDateTime'] task_obj.notificationTimeMinutes = task[ 'notificationTimeMinutes'] if (task_obj.dueDateTime and task['notificationTimeMinutes'] != -1): datetime_object = datetime.strptime( task_obj.dueDateTime, '%m/%d/%Y %H:%M:%S') task_obj.notificationDateTime = datetime_object - timedelta( minutes=int(task['notificationTimeMinutes'])) task_obj.description = task['description'] task_obj.userId = payload['sub'] task_obj.position = task['position'] # Updating the task in tasks collection task_collection = self.__get_task_collection() query = {'_id': ObjectId(task_obj.id)} updated_values = {"$set": task_obj.__dict__} task_collection.update_one(query, updated_values) # Closing the DB connection self.mongo_db.disconnect() return task_obj else: return "Invalid Authorization" except Exception as exception: raise exception
def get_tasks(self, swim_lane_id, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if (payload): task_obj = Task() task_obj.laneId = swim_lane_id # Fetching the tasks collection task_collection = self.__get_task_collection() cursor = task_collection\ .find({"laneId" : task_obj.laneId }).sort("position") tasks = [] for task in cursor: task_obj = Task() task_obj.laneId = task['laneId'] task_obj.id = str(task['_id']) task_obj.title = task['title'] task_obj.dueDateTime = task['dueDateTime'] task_obj.notificationDateTime = task[ 'notificationDateTime'] task_obj.notificationTimeMinutes = task[ 'notificationTimeMinutes'] task_obj.description = task['description'] task_obj.position = task['position'] tasks.append(task_obj) # Closing the DB connection self.mongo_db.disconnect() # Returning list of tasks return tasks else: return "Invalid Authorization" except Exception as exception: raise exception
def get_events_by(self, date, headers): try: # Checking if the token is valid or not payload = JwtHandler.decode_auth_token(headers['Authorization']) if(payload): # Fetching the tasks collection tasks_collection = self.__get_tasks_collection() date = str(int(date[0:2])) + "/" + str(int(date[2:4])) + "/" + str(int(date[4:8])) query = {"$and": [{"userId" : payload['sub']}, {"dueDateTime": {"$regex": date} }]} # Fetching the task based on user and date cursor = tasks_collection.find(query) # preparing events list events = [] for task in cursor: event = Task() event.title = task["title"] event.description = task["description"] event.dueDateTime = task["dueDateTime"] events.append(event) return events else: return "Invalid Authorization" except Exception as exception: raise exception