diff --git a/app/api/jobs.py b/app/api/jobs.py index 5ade2fe4..0a42f9c3 100644 --- a/app/api/jobs.py +++ b/app/api/jobs.py @@ -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('/') +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 diff --git a/app/api/tokens.py b/app/api/tokens.py index 6d23b744..48ab1422 100644 --- a/app/api/tokens.py +++ b/app/api/tokens.py @@ -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