Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
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
Service Desk
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
Réouven ASSOULY
zesje
Commits
7727d983
Commit
7727d983
authored
7 years ago
by
Joseph Weston
Browse files
Options
Downloads
Patches
Plain Diff
add grader API
closes #104.
parent
bdf41b3a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zesje/api.py
+29
-6
29 additions, 6 deletions
zesje/api.py
with
29 additions
and
6 deletions
zesje/api.py
+
29
−
6
View file @
7727d983
from
flask
import
Blueprint
,
jsonify
,
request
,
redirect
import
json
from
flask
import
Blueprint
,
Response
,
jsonify
,
request
,
abort
from
.
import
db
app
=
Blueprint
(
__name__
,
__name__
)
@app.route
(
'
/students
'
,
methods
=
[
'
GET
'
])
# TODO: when making new database structure, have only a single
# 'name' field: it is just an identifier
@app.route
(
'
/graders
'
,
methods
=
[
'
GET
'
])
@db.session
def
get_students
():
def
get_graders
():
return
jsonify
([
dict
(
id
=
s
.
id
,
first_name
=
s
.
first_name
,
last_name
=
s
.
last_name
,
email
=
s
.
email
)
for
s
in
db
.
Student
.
select
()
dict
(
id
=
g
.
id
,
first_name
=
g
.
first_name
,
last_name
=
g
.
last_name
)
for
g
in
db
.
Grader
.
select
()
])
@app.route
(
'
/graders
'
,
methods
=
[
'
POST
'
])
@db.session
def
post_graders
():
grader_spec
=
request
.
get_json
(
silent
=
False
,
force
=
True
)
try
:
new_grader
=
db
.
Grader
(
first_name
=
grader_spec
[
'
first_name
'
],
last_name
=
grader_spec
[
'
last_name
'
])
db
.
orm
.
commit
()
except
KeyError
:
abort
(
400
)
return
jsonify
({
'
id
'
:
new_grader
.
id
,
'
first_name
'
:
grader_spec
[
'
first_name
'
],
'
last_name
'
:
grader_spec
[
'
last_name
'
],
})
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