Skip to content

Commit

Permalink
Extract analyses endpoints (#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard authored Aug 19, 2024
1 parent 891a291 commit 367ef1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
17 changes: 1 addition & 16 deletions cg/server/api.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import logging
from http import HTTPStatus
from flask import Blueprint, abort, g, jsonify, request
from flask import Blueprint, abort, g, jsonify

from cg.server.ext import db
from cg.server.endpoints.utils import before_request
from cg.store.models import Analysis

LOG = logging.getLogger(__name__)
BLUEPRINT = Blueprint("api", __name__, url_prefix="/api/v1")
BLUEPRINT.before_request(before_request)


@BLUEPRINT.route("/analyses")
def get_analyses():
"""Return analyses."""
if request.args.get("status") == "delivery":
analyses: list[Analysis] = db.get_analyses_to_deliver_for_pipeline()
elif request.args.get("status") == "upload":
analyses: list[Analysis] = db.get_analyses_to_upload()
else:
analyses: list[Analysis] = db.get_analyses()
parsed_analysis: list[dict] = [analysis_obj.to_dict() for analysis_obj in analyses[:30]]
return jsonify(analyses=parsed_analysis, total=len(analyses))


@BLUEPRINT.route("/me")
def get_user_information():
"""Return information about current user."""
Expand Down
4 changes: 4 additions & 0 deletions cg/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from cg.server import admin, api, ext, invoices
from cg.server.app_config import app_config
from cg.server.endpoints.analyses import ANALYSES_BLUEPRINT
from cg.server.endpoints.flow_cells import FLOW_CELLS_BLUEPRINT
from cg.server.endpoints.orders import ORDERS_BLUEPRINT
from cg.server.endpoints.applications import APPLICATIONS_BLUEPRINT
Expand Down Expand Up @@ -98,6 +99,8 @@ def logged_in(blueprint, token):
app.register_blueprint(SAMPLES_BLUEPRINT)
app.register_blueprint(POOLS_BLUEPRINT)
app.register_blueprint(FLOW_CELLS_BLUEPRINT)
app.register_blueprint(ANALYSES_BLUEPRINT)

_register_admin_views()

ext.csrf.exempt(api.BLUEPRINT)
Expand All @@ -107,6 +110,7 @@ def logged_in(blueprint, token):
ext.csrf.exempt(ORDERS_BLUEPRINT)
ext.csrf.exempt(POOLS_BLUEPRINT)
ext.csrf.exempt(FLOW_CELLS_BLUEPRINT)
ext.csrf.exempt(ANALYSES_BLUEPRINT)

@app.route("/")
def index():
Expand Down
21 changes: 21 additions & 0 deletions cg/server/endpoints/analyses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask import Blueprint, jsonify, request

from cg.server.ext import db
from cg.server.endpoints.utils import before_request
from cg.store.models import Analysis

ANALYSES_BLUEPRINT = Blueprint("analyses", __name__, url_prefix="/api/v1")
ANALYSES_BLUEPRINT.before_request(before_request)


@ANALYSES_BLUEPRINT.route("/analyses")
def get_analyses():
"""Return analyses."""
if request.args.get("status") == "delivery":
analyses: list[Analysis] = db.get_analyses_to_deliver_for_pipeline()
elif request.args.get("status") == "upload":
analyses: list[Analysis] = db.get_analyses_to_upload()
else:
analyses: list[Analysis] = db.get_analyses()
parsed_analysis: list[dict] = [analysis_obj.to_dict() for analysis_obj in analyses[:30]]
return jsonify(analyses=parsed_analysis, total=len(analyses))

0 comments on commit 367ef1c

Please sign in to comment.