mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Add more examples
This commit is contained in:
parent
523faaea05
commit
8a69d6364a
@ -1,5 +1,6 @@
|
||||
from flask_restx import Namespace, Resource
|
||||
from .auth import token_auth
|
||||
from ..jobs import tasks
|
||||
from ..models import Job
|
||||
|
||||
|
||||
@ -7,12 +8,41 @@ ns = Namespace('jobs', description='Job operations')
|
||||
|
||||
|
||||
@ns.route('/')
|
||||
class JobList(Resource):
|
||||
'''Shows a list of all jobs, and lets you POST to add new job'''
|
||||
class API_Jobs(Resource):
|
||||
'''Shows a list of all jobs and lets you POST to add new job'''
|
||||
|
||||
@ns.doc(security='apiKey')
|
||||
@token_auth.login_required
|
||||
def get(self):
|
||||
'''List all jobs'''
|
||||
# TODO: Implement the correct get_jobs functionality
|
||||
jobs = Job.query.all()
|
||||
return [job.to_dict(include_relationships=False) for job in jobs]
|
||||
|
||||
@ns.doc(security='apiKey')
|
||||
@token_auth.login_required
|
||||
def post(self):
|
||||
'''Create a new job'''
|
||||
# TODO: Implement this
|
||||
pass
|
||||
|
||||
|
||||
@ns.route('/<int:id>')
|
||||
class API_Job(Resource):
|
||||
'''Show a single job and lets you delete it'''
|
||||
|
||||
@ns.doc(security='apiKey')
|
||||
@token_auth.login_required
|
||||
def get(self, id):
|
||||
'''Get a job by id'''
|
||||
job = Job.query.get_or_404(id)
|
||||
return job.to_dict(include_relationships=False)
|
||||
|
||||
@ns.doc(security='apiKey')
|
||||
@token_auth.login_required
|
||||
def delete(self, id):
|
||||
'''Delete a job by id'''
|
||||
job = Job.query.get_or_404(id)
|
||||
# We use this imported task because it will run in the background
|
||||
tasks.delete_job(job.id)
|
||||
return '', 204
|
||||
|
@ -7,13 +7,13 @@ ns = Namespace('tokens', description='Token operations')
|
||||
|
||||
|
||||
@ns.route('/')
|
||||
class Token(Resource):
|
||||
class API_Tokens(Resource):
|
||||
'''Get or revoke a user authentication token'''
|
||||
|
||||
@ns.doc(security='basicAuth')
|
||||
@basic_auth.login_required
|
||||
def post(self):
|
||||
'''Get user token'''
|
||||
'''Get a user token'''
|
||||
token = basic_auth.current_user().get_token()
|
||||
db.session.commit()
|
||||
return {'token': 'Bearer ' + token}
|
||||
@ -21,7 +21,7 @@ class Token(Resource):
|
||||
@ns.doc(security='apiKey')
|
||||
@token_auth.login_required
|
||||
def delete(self):
|
||||
'''Revoke user token'''
|
||||
'''Revoke a user token'''
|
||||
token_auth.current_user().revoke_token()
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
Loading…
Reference in New Issue
Block a user