Commit 573dc4b0 authored by ras19's avatar ras19
Browse files

Created blueprint to assigning tasks to users, registered this in main app and...

Created blueprint to assigning tasks to users, registered this in main app and developed AddProjectTask.js to push entry to AssignedTasks table as well [RS]
parent b81a17ee
Pipeline #203246 passed with stage
in 1 minute and 10 seconds
from operator import truediv
from re import T
from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.task_model import AssignedTasks
assigned_task = Blueprint('assigned_task', __name__)
@assigned_task.route('/assigned_task', methods=['GET'])
def get_all_assignments():
assignments = AssignedTasks.query.all()
assignments_list = [{"username" : x.username,
"task_id" : x.task_id,
"id" : x.id} for x in assignments]
return jsonify(assignments_list)
@assigned_task.route('/assigned_task', methods=['POST'])
def assign_task_to_user():
username, task_id = (request.json['username'], request.json['task_id'])
entry = AssignedTasks(username=username, task_id=task_id)
DB.add(entry)
return ''
\ No newline at end of file
......@@ -31,7 +31,7 @@ def add_project_task(project_id):
is_completed = False
entry = Task(due_date=due_date, priority=priority, description=description, completed=is_completed, project_id=project_id)
DB.add(entry)
return ''
return jsonify(id=entry.id)
@task.route('/projects/<project_id>/tasks/<task_id>', methods=['POST'])
......
......@@ -7,6 +7,7 @@ from backend.blueprints.user import user
from backend.blueprints.todo import todo
from backend.blueprints.task import task
from backend.blueprints.project_to_user import user_project
from backend.blueprints.assigned_task import assigned_task
ENV = os.environ.get("ENV")
......@@ -17,6 +18,7 @@ app.register_blueprint(user)
app.register_blueprint(todo)
app.register_blueprint(task)
app.register_blueprint(user_project)
app.register_blueprint(assigned_task)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
......
......@@ -22,23 +22,31 @@ const AddProjectTask = () => {
setAssignedUsers(Array.isArray(e) ? e.map(x => x.value) : []);
}
const handleSubmit = e => {
const handleSubmit = async e => {
e.preventDefault()
const newProjectTask = {
description,
due_date,
priority,
completed
}
const newProjectTask = { description, due_date, priority, completed };
fetch("/projects/" + project.id + "/tasks", {
const response = await fetch("/projects/" + project.id + "/tasks", {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newProjectTask)
}).then(() => {
history.push('/projects/' + id + '/tasks');
})
});
const responseJSON = await response.json();
const task_id = responseJSON.id;
assignedUsers.map(username => {
const assigned_task = { username, task_id };
fetch("/assigned_task", {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(assigned_task)
});
});
history.push("/");
}
return (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment