Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
a5daa45c
Commit
a5daa45c
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
create /api/ec-projects endpoint
parent
62547b73
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
merge feature/COMP-152-EC-PROJECTS-TABLE into develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/routes/api.py
+2
-0
2 additions, 0 deletions
compendium_v2/routes/api.py
compendium_v2/routes/ec_projects.py
+67
-0
67 additions, 0 deletions
compendium_v2/routes/ec_projects.py
with
69 additions
and
0 deletions
compendium_v2/routes/api.py
+
2
−
0
View file @
a5daa45c
...
@@ -20,6 +20,7 @@ from compendium_v2.routes.funding import routes as funding_routes
...
@@ -20,6 +20,7 @@ from compendium_v2.routes.funding import routes as funding_routes
from
compendium_v2.routes.charging
import
routes
as
charging_routes
from
compendium_v2.routes.charging
import
routes
as
charging_routes
from
compendium_v2.routes.staff
import
routes
as
staff_routes
from
compendium_v2.routes.staff
import
routes
as
staff_routes
from
compendium_v2.routes.organization
import
routes
as
org_routes
from
compendium_v2.routes.organization
import
routes
as
org_routes
from
compendium_v2.routes.ec_projects
import
routes
as
ec_routes
routes
=
Blueprint
(
'
compendium-v2-api
'
,
__name__
)
routes
=
Blueprint
(
'
compendium-v2-api
'
,
__name__
)
routes
.
register_blueprint
(
budget_routes
,
url_prefix
=
'
/budget
'
)
routes
.
register_blueprint
(
budget_routes
,
url_prefix
=
'
/budget
'
)
...
@@ -27,6 +28,7 @@ routes.register_blueprint(funding_routes, url_prefix='/funding')
...
@@ -27,6 +28,7 @@ routes.register_blueprint(funding_routes, url_prefix='/funding')
routes
.
register_blueprint
(
charging_routes
,
url_prefix
=
'
/charging
'
)
routes
.
register_blueprint
(
charging_routes
,
url_prefix
=
'
/charging
'
)
routes
.
register_blueprint
(
staff_routes
,
url_prefix
=
'
/staff
'
)
routes
.
register_blueprint
(
staff_routes
,
url_prefix
=
'
/staff
'
)
routes
.
register_blueprint
(
org_routes
,
url_prefix
=
'
/organization
'
)
routes
.
register_blueprint
(
org_routes
,
url_prefix
=
'
/organization
'
)
routes
.
register_blueprint
(
ec_routes
,
url_prefix
=
'
/ec-project
'
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/routes/ec_projects.py
0 → 100644
+
67
−
0
View file @
a5daa45c
import
logging
from
flask
import
Blueprint
,
jsonify
,
current_app
from
compendium_v2
import
db
from
compendium_v2.routes
import
common
from
compendium_v2.db
import
model
from
typing
import
Any
routes
=
Blueprint
(
'
ec-projects
'
,
__name__
)
@routes.before_request
def
before_request
():
config
=
current_app
.
config
[
'
CONFIG_PARAMS
'
]
dsn_prn
=
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
db
.
init_db_model
(
dsn_prn
)
logger
=
logging
.
getLogger
(
__name__
)
EC_PROJECTS_RESPONSE_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
definitions
'
:
{
'
ec_project
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
nren
'
:
{
'
type
'
:
'
string
'
},
'
year
'
:
{
'
type
'
:
'
integer
'
},
'
project
'
:
{
'
type
'
:
'
string
'
}
},
'
required
'
:
[
'
nren
'
,
'
year
'
,
'
project
'
],
'
additionalProperties
'
:
False
}
},
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/ec_project
'
}
}
@routes.route
(
'
/
'
,
methods
=
[
'
GET
'
])
@common.require_accepts_json
def
ec_projects_view
()
->
Any
:
"""
handler for /api/ec-projects requests
returns EC projects for each NREN/year combination
response will be formatted as:
.. asjson::
compendium_v2.routes.ec_projects.EC_PROJECTS_RESPONSE_SCHEMA
:return:
"""
def
_extract_project
(
entry
:
model
.
ECProject
):
return
{
'
nren
'
:
entry
.
nren
.
name
,
'
year
'
:
entry
.
year
,
'
project
'
:
entry
.
project
}
with
db
.
session_scope
()
as
session
:
result
=
[
_extract_project
(
project
)
for
project
in
session
.
query
(
model
.
ECProject
)]
return
jsonify
(
result
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment