Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kacprzak, Izabella
DRP-InAGlobe-Platform
Commits
f8c1b6e9
Commit
f8c1b6e9
authored
Jun 15, 2021
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/blueprints/project_to_user.py
View file @
f8c1b6e9
...
...
@@ -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_assignmen
t
(
project_id
):
@
user_project
.
route
(
'/user_project/
project/
<project_id>'
,
methods
=
[
'GET'
])
def
get_
users_for_projec
t
(
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'
])
...
...
frontend/src/Home.js
View file @
f8c1b6e9
...
...
@@ -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>
}
...
...
frontend/src/ProjectDetails.js
View file @
f8c1b6e9
...
...
@@ -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
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment