Commit 3bf63beb authored by ras19's avatar ras19
Browse files

Filter relevant project-user assignments in the python backend and assigned...

Filter relevant project-user assignments in the python backend and assigned users now are shown in the project landing page
parent ab31fbf5
Pipeline #202764 passed with stage
in 56 seconds
......@@ -3,6 +3,7 @@ from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.project_model import Project
from backend.models.task_model import Task
from backend.models.user_model import User_project
project = Blueprint('project', __name__)
......@@ -63,6 +64,9 @@ def delete_project(project_id):
tasks = Task.query.filter_by(project_id=project_id)
for task in tasks:
DB.delete(task)
assignments = User_project.query.filter_by(project_id=project_id)
for assignment in assignments:
DB.delete(assignment)
entry = Project.query.get(project_id)
DB.delete(entry)
return ''
......@@ -7,22 +7,21 @@ user_project = Blueprint('user_project', __name__)
@user_project.route('/user_project', methods=['GET'])
def get_all_assignments():
project_query = User_project.query.all()
assignments = User_project.query.all()
projects_list = [{"username" : x.username,
assignments_list = [{"username" : x.username,
"project_id" : x.project_id,
"id" : x.id} for x in project_query]
return jsonify(projects_list)
"id" : x.id} for x in assignments]
return jsonify(assignments_list)
@user_project.route('/user_project/<assignment_id>', methods=['GET'])
def get_single_assignment(assignment_id):
entry = User_project.query.get(assignment_id)
return jsonify(
username=entry.username,
project_id=entry.project_id,
id=entry.id
)
@user_project.route('/user_project/<project_id>', methods=['GET'])
def get_relevant_assignment(project_id):
entries = User_project.query.filter_by(project_id=project_id)
assignments_list = [{"username" : x.username,
"project_id" : x.project_id,
"id" : x.id} for x in entries]
return jsonify(assignments_list)
@user_project.route('/user_project', methods=['POST'])
def assign_project_to_user():
......
......@@ -6,6 +6,7 @@ from backend.blueprints.project import project
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
ENV = os.environ.get("ENV")
......@@ -15,6 +16,7 @@ app.register_blueprint(project)
app.register_blueprint(user)
app.register_blueprint(todo)
app.register_blueprint(task)
app.register_blueprint(user_project)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
......
......@@ -28,7 +28,6 @@ const CreateProject = () => {
});
const responseJSON = await response.json();
console.log(responseJSON.id);
const project_id = responseJSON.id;
......
......@@ -7,9 +7,9 @@ const ProjectDetails = () => {
const history = useHistory();
const { data: project, error, isPending } = useFetch("/projects/" + id)
const { data: user_project_assignments, errorAssignment, isPendingAssignment } = useFetch("/user_project")
const { data: assignments, errorAssignment, isPendingAssignment } = useFetch("/user_project/" + id)
const users = user_project_assignments.filter(user_project => (user_project.id === id))
// const relevantAssignments = user_project_assignments.filter(assignment => assignment.project_id === { id })
const handleRemove = e => {
e.preventDefault()
......@@ -46,14 +46,15 @@ const ProjectDetails = () => {
<h3>Volunteers working on this project</h3>
<div>
{users.map((assignment) => (
<div>
<div>
<h4>{assignment.username}</h4>
</div>
{assignments.map(a => {
<div className="preview" key={a.id}>
<Link to={`/users/${a.username}`}>
<h2>{a.username}</h2>
</Link>
</div>
))}
}
)
}
</div>
<div className="project-tasks">
......
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