def get(self): data = Task.parser.parse_args() print(data) task = TaskModel.find_by_id(data["task_id"]) if task: return task.json() return {"message": "Task not found"}, 404
def put(self, task_id): """update fields: -is_done -assignee_id --- currently logged in user""" data = Task.updating_parser.parse_args() task = TaskModel.find_by_id(task_id) if task is None: return {'message': "Task with id {} doesn't exist".format(task_id)} elif task.assignee_id is None: user = UserModel.find_by_id(current_identity.id) # assigning currently logged user to task task.assignee_id = user.id task.assignee_name = user.username elif data['is_done'] is not None: user = UserModel.find_by_id(current_identity.id) if task.assignee_id == user.id: # updating is_done field task.is_done = data['is_done'] else: return {'message': 'You are not assigned to this task'}, 400 else: return {'message': 'You are not assigned to this task'}, 400 try: task.save_to_db() except: return {'message': "An error occurred inserting the task."}, 500 return task.json(), 201
def delete(self, id): task = TaskModel.find_by_id(id) if task: task.delete_from_db() return {'message': 'Task deleted'}
def get(self, _id, owner): task = TaskModel.find_by_id(_id, owner) if task: return task.json() else: return {'message': f'Task {_id} not found - owner : {owner}'}, 404
def get(cls, task_id: int): task = TaskModel.find_by_id(task_id) if task: return task_schema.dump(task), HttpStatusCode.OK.value return generate_message_json(HttpStatusCode.NOT_FOUND.value, TASK_NOT_FOUND)
def put(self, _id, owner): parser = reqparse.RequestParser() parser.add_argument('description', type=str, required=False) parser.add_argument( 'start_date', type=lambda x: dt.datetime.strptime(x, "%Y-%m-%d %H:%M:%S"), required=False) parser.add_argument( 'end_date', type=lambda x: dt.datetime.strptime(x, "%Y-%m-%d %H:%M:%S"), required=False) parser.add_argument('completed', type=bool, required=False) task = TaskModel.find_by_id(_id, owner) if task: payload = parser.parse_args() if payload['description']: task.description = payload['description'] if payload['start_date']: task.start_date = payload['start_date'] if payload['end_date']: task.end_date = payload['end_date'] if payload['completed'] is not None: task.completed = payload['completed'] task.save() return { 'message': f'Task {_id} changed.', 'record': task.json() }, 201 else: return {'message': f'Task {_id} not found - owner : {owner}'}, 404
def get(cls, task_id:int): task = TaskModel.find_by_id(task_id) if not task: return {"message": f"Task with taskID {task_id} is not found"}, 404 return task_schema.dump(task), 200
def patch(cls, task_id: int): json = request.get_json() # Check if the task exists task = TaskModel.find_by_id(task_id) if not task: return generate_message_json(HttpStatusCode.NOT_FOUND.value, TASK_NOT_FOUND) # Check if client is trying to edit readonly fields readonly = {"id", "category_id"} keys = json.keys() forbidden = readonly & keys if forbidden: return generate_message_json( HttpStatusCode.BAD_REQUEST.value, FIELD_CANNOT_BE_EDITED.format(str(forbidden)[1:-1]), ) # Check if the client specified non existing attrs try: check_attr(json.keys(), task) for key, value in json.items(): setattr(task, key, value) task.save_to_db() # Persist chages to db return task_schema.dump(task), HttpStatusCode.OK.value except AttributeError as ae: return generate_message_json(HttpStatusCode.BAD_REQUEST.value, str(ae)) except SQLAlchemyError as se: return generate_message_json(HttpStatusCode.BAD_REQUEST.value, str(se))
def put(self, _id, owner): parser = reqparse.RequestParser() parser.add_argument('description', type=str, required=False, help="Field description cannot be empty") parser.add_argument( 'due_date', type=lambda x: dt.datetime.strptime(x, "%Y-%m-%d").date(), required=False, help="Field due_date cannot be empty") parser.add_argument('complete', type=bool, required=False, help="Field complete cannot be empty") task = TaskModel.find_by_id(_id, owner) if task: payload = parser.parse_args() if payload['description']: task.description = payload['description'] if payload['due_date']: task.due_date = payload['due_date'] if payload['complete']: task.complete = payload['complete'] task.save() return {'message': f'Task {_id} changed.'}, 201 else: return {'message': f'Task {_id} not found - owner : {owner}'}, 404
def get(self, _id): task = TaskModel.find_by_id(_id, current_identity.id) if task and current_identity.id != task.user_id: return {"message": "Not authorized to view this content"}, 401 if task: return task.json() return {"message": "Task not found."}, 404
def delete(self, _id): task = TaskModel.find_by_id(_id) if task: task.delete_from_db() return {'message': 'Task deleted'} return {'message': "There is no task with id '{}'".format(_id)}, 400
def delete(self, _id): task = TaskModel.find_by_id(_id, current_identity.id) if task and current_identity.id != task.user_id: return {"message": "Not authorized to delete this content"}, 401 if task: task.delete_from_db() return {"message": "Task deleted."} return {"message": "Task with id {}, was not found".format(_id)}, 404
def delete(cls, task_id:int): task = TaskModel.find_by_id(task_id) if not task: return {"message": f"Task with taskID {task_id} is not found"}, 404 task.delete_from_db() return {"message": "Task deleted successfully"}, 200
def delete(cls, task_id: int): task = TaskModel.find_by_id(task_id) if task: task.delete_from_db() return "", HttpStatusCode.NO_CONTENT.value return generate_message_json(HttpStatusCode.NOT_FOUND.value, TASK_NOT_FOUND)
def put(self, task_id): task = TaskModel.find_by_id(task_id) data = Task.parser.parse_args() if task: task.is_finished = data['is_finished'] else: task = TaskModel(data['body'], data['list_id']) task.save_to_db() return task.json()
def delete(self, _id, owner): task = TaskModel.find_by_id(_id, owner) if task: task.delete() return {'message': f'Task {_id} deleted - owner : {owner}'} else: return {'message': f'Task {_id} not found - owner : {owner}'}, 404
def get(self, task_id): # Validate task_id task = TaskModel.find_by_id(task_id) # Get task details from task_id # Return task details or error if task: return task.json() return {'message': 'Task not found'}, 404
def get(cls, task_id: str = None): if task_id: task = TaskModel.find_by_id(task_id) if not task: return {"message": "Task not found"}, 404 return task_schema.dump(task), 200 tasks = TaskModel.fetch_all() return task_list_schema.dump(tasks), 200
def get(self, task_id): """returns task with given id""" try: task = TaskModel.find_by_id(task_id) except: return {"message": "An error occurred finding the task."}, 500 if task: return task.json() return {'message': 'Task not found'}, 404
def get(self, id): task = TaskModel.find_by_id(id) if task: # since the task variable is a TaskModel object instance # we must first convert it to a json object before returning # it to the client return task.json() else: return {'message': 'Task not found'}, 404
def delete(self, task_id): """deletes task with provided id, if it's assigned to current user""" task = TaskModel.find_by_id(task_id) current_user = UserModel.find_by_id(current_identity.id) if (task is not None) and (task.assignee_id == current_user.id): task.delete_from_db() return {'message': 'Task deleted'} return { 'message': "You are not assigned to this task, or it doesnt't exist" }, 400
def put(self, _id): data = self.parser.parse_args() task = TaskModel.find_by_id(_id) if task: task.title = data['title'] task.description = data['description'] task.done = data['done'] else: task = TaskModel(**data) task.save_to_db() return task.json()
def put(self, id): current_user_id = get_jwt_identity() task = TaskModel.find_by_id(id) if not task: return {"message": "task not found"}, 404 if current_user_id != task.user_id: return {"message": "Unauthorized"}, 401 data = Task.parser.parse_args() task_name = data['task_name'] if not task_name: task_name = task.task_name project_id = task.project_id project = ProjectModel.find_by_id(project_id) if not project: return {"message": "project not found"}, 404 if project.is_archived: return {"message": "Close Unauthorized"}, 401 is_open = data['is_open'] print(is_open) if is_open: task.is_open = is_open # is_open = task.is_open try: task.task_name = task_name task.is_open = is_open task.save_to_db() except: return {"message": "An error occured creating the Project"}, 500 project_id = task.project_id is_open = task.is_open task_name = task.task_name return { "project_id": project_id, "task_name": task_name, "is_open": is_open }, 201
def get(self, id): current_user_id = get_jwt_identity() task = TaskModel.find_by_id(id) if not task: return {"message": "task not found"}, 404 if current_user_id == task.user_id: task_id = task.id task_name = task.task_name return {"task_id": task_id, "task_name": task_name}, 200 return {"message": "Unauthorized"}, 401
def delete(self, id): current_user_id = get_jwt_identity() task = TaskModel.find_by_id(id) if not task: return {"message": "task not found"}, 404 if task.user_id != current_user_id: return {"message": "Unauthorized"}, 401 task.delete_from_db() return {"message": "Task deleted"}
def put(self): data = Task.parser.parse_args() task = TaskModel.find_by_id(data["task_id"]) # If task exists, edit if task: task.task_name = data["task_name"] task.task_description = data["task_description"] task.instructor_id = data["instructor_id"] task.task_notes = data["task_notes"] task.save_to_db() return {"_task": task.json()}, 201 # If task doesn't exist, error out else: return {"message": "Task does not exist"}, 404
def put(cls, task_id: int): task = TaskModel.find_by_id(task_id) if not task: return {"message": f"Task with taskID {task_id} is not found"}, 404 task_json = request.get_json() task.title = task_json["title"] task.description = task_json["description"] try: task.save_to_db() except: return {"message": "Unable to update the task"}, 500 return task_schema.dump(task), 200
def put(self, id): data = Task.parser.parse_args() task = TaskModel.find_by_id(id) if task is None: task = TaskModel(**data) else: task.name = data['name'] task.description = data['description'] task.duedate = data['duedate'] task.completed = data['completed'] task.save_to_db() return task.json()
def get(self, id): current_user_id = get_jwt_identity() task = TaskModel.find_by_id(id) if not task: return {"message": "task not found"}, 404 if task.is_open == False: return {"message": "Task aleready completed"} if task.user_id != current_user_id: return {"message": "Unauthorized"}, 401 task.is_open = False task.termined_at = datetime.datetime.now() task.save_to_db() return {"message": "Task completed"}
def put(self, _id): data = Task.parser.parse_args() complete = data['complete'] task = TaskModel.find_by_id(_id, current_identity.id) if task is None: return { "message": "Task with id '{}', does not exist.".format(title) }, 400 task.complete = complete try: task.save_to_db() except: return { "message": "An error occurred while storing the task." }, 500 return task.json()