예제 #1
0
def get_task_by_id():

	"""
	Fetch a task by id.

	Arguments:
		task_id (string): UUID4 of task to fetch.

	Returns: Success boolean and API formatted task object.
	"""

	task_uuid4 = request.args.get('task_id')
	if task_uuid4 is None:
		res = {
			'success': 0,
			'error': '"task_id" param required'
		}
		return make_response(
			jsonify(res),
			400
		)
	task = TaskService.load_task_by_uuid4(task_uuid4)
	if task is not None:
		task = TaskService.get_task_api_formatted_data(task)
	res = {
		'success': 1 if task is not None else 0,
		'task': task
	}
	return jsonify(res)	
예제 #2
0
def create_task(params):

	"""
	Create a task.

	Arguments:
		task_title (string): Title of task.

	Side-effects: Emits 'task_created' event with task object payload.
	"""

	if 'task_title' not in params:
		return None
	task_title = params['task_title']
	task = TaskService.create_task(task_title)
	if task is not None:
		task = TaskService.get_task_api_formatted_data(task)
		emit('task_created', task, broadcast=True)
예제 #3
0
def get_all_tasks():

	"""
	Fetch all tasks.

	Returns: Success boolean and array of API formatted task objects.
	"""

	tasks = TaskService.load_all_tasks()
	if tasks is not None:
		tasks = [
			TaskService.get_task_api_formatted_data(task)
			for task in tasks
		]
	res = {
		'success': 1 if tasks is not None else 0,
		'tasks': tasks
	}
	return jsonify(res)