Commit f8c1b6e9 authored by ras19's avatar ras19
Browse files

Created function which returns projects that are relevant to a user in the backend [RS, EW]

parent 9535382c
Pipeline #202924 passed with stage
in 57 seconds
......@@ -2,6 +2,7 @@ from re import T
from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.user_model import User_project
from backend.models.project_model import Project
user_project = Blueprint('user_project', __name__)
......@@ -15,14 +16,26 @@ def get_all_assignments():
return jsonify(assignments_list)
@user_project.route('/user_project/<project_id>', methods=['GET'])
def get_relevant_assignment(project_id):
@user_project.route('/user_project/project/<project_id>', methods=['GET'])
def get_users_for_project(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/username/<username>', methods=['GET'])
def get_projects_for_user(username):
entries = User_project.query.filter_by(username=username)
project_list = [{"id" : Project.query.get(x.project_id).id,
"name" : Project.query.get(x.project_id).name,
"status" : Project.query.get(x.project_id).status,
"description" : Project.query.get(x.project_id).description,
"tag" : Project.query.get(x.project_id).tag,
"location" : Project.query.get(x.project_id).location,
"files" : Project.query.get(x.project_id).files} for x in entries]
return jsonify(project_list)
@user_project.route('/user_project', methods=['POST'])
def assign_project_to_user():
username, project_id = (request.json['username'], request.json['project_id'])
......
......@@ -2,20 +2,22 @@ import ProjectList from './ProjectList'
import PersonalToDo from './PersonalToDo'
import useFetch from './useFetch'
import useToken from './useToken';
import { useState } from "react";
const Home = () => {
const {data: projects, errorProjects, isPendingProjects} = useFetch("/projects")
const {data: todos, errorTodos, isPendingTodos} = useFetch("/todos")
const {data: projects, errorProjects, isPendingProjects} = useFetch("/projects");
const {data: todos, errorTodos, isPendingTodos} = useFetch("/todos");
const {setToken, token} = useToken();
const {data: relevantProjects, errorRProjects, isPendingRProjects} = useFetch("/user_project/username/" + token);
return (
<div className="home">
<h1>Dashboard</h1>
<div className="home-projects" style={{float: "left", width: "600px"}}>
{ isPendingProjects && <h2>Loading...</h2> }
{ projects && <ProjectList projects={projects} title="All Projects"/> }
{ projects && <ProjectList projects={projects.filter(project => project.status === "Completed")} title="Completed Projects"/> }
{ projects && <ProjectList projects={relevantProjects} title="My Projects"/> }
</div>
<div className="homeTodos">
{ isPendingTodos && <h2>Loading...</h2> }
......
......@@ -7,7 +7,7 @@ const ProjectDetails = () => {
const history = useHistory();
const { data: project, error, isPending } = useFetch("/projects/" + id)
const { data: assignments, errorAssignment, isPendingAssignment } = useFetch("/user_project/" + id)
const { data: assignments, errorAssignment, isPendingAssignment } = useFetch("/user_project/project/" + id)
const handleRemove = e => {
e.preventDefault()
......
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