Big update, corpus analysis reworked, versioned services, preliminary work for contributions

This commit is contained in:
Patrick Jentsch
2022-02-03 12:39:16 +01:00
parent 0647537192
commit fe938c0ca2
36 changed files with 1552 additions and 431 deletions

View File

@ -1,7 +1,6 @@
from flask import Blueprint
from flask_restx import Api
from .jobs import ns as jobs_ns
from .tokens import ns as tokens_ns
bp = Blueprint('api', __name__)
@ -23,5 +22,4 @@ api = Api(
version='1.0'
)
api.add_namespace(jobs_ns)
api.add_namespace(tokens_ns)

View File

@ -9,8 +9,12 @@ token_auth = HTTPTokenAuth()
@basic_auth.verify_password
def verify_password(email_or_username, password):
user = User.query.filter(or_(User.username == email_or_username,
User.email == email_or_username.lower())).first()
user = User.query.filter(
or_(
User.username == email_or_username,
User.email == email_or_username.lower()
)
).first()
if user and user.verify_password(password):
return user

View File

@ -1,48 +0,0 @@
from flask_restx import Namespace, Resource
from .auth import token_auth
from ..jobs import tasks
from ..models import Job
ns = Namespace('jobs', description='Job operations')
@ns.route('')
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('/<hashid: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