Skip to content

Commit

Permalink
Added count (get/post) and /list (post) for validations
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Feb 16, 2024
1 parent 565af41 commit ddc5d0b
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion fedn/fedn/network/api/v1/validation_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from fedn.network.storage.statestore.repositories.validation_repository import \
ValidationRepository

from .shared import api_version, get_typed_list_headers, get_use_typing, mdb
from .shared import (api_version, get_post_data_to_kwargs,
get_typed_list_headers, get_use_typing, mdb)

bp = Blueprint("validation", __name__, url_prefix=f"/api/{api_version}/validations")

Expand All @@ -31,6 +32,37 @@ def get_validations():
return jsonify({"error": str(e)}), 500


@bp.route("/list", methods=["POST"])
def list_validations():
try:
limit, skip, sort_key, sort_order, use_typing = get_typed_list_headers(request.headers)
kwargs = get_post_data_to_kwargs(request)

validations = validation_repository.list(limit, skip, sort_key, sort_order, use_typing=use_typing, **kwargs)

result = [validation.__dict__ for validation in validations["result"]] if use_typing else validations["result"]

response = {
"count": validations["count"],
"result": result
}

return jsonify(response), 200
except Exception as e:
return jsonify({"error": str(e)}), 500


@bp.route("/count", methods=["GET", "POST"])
def validations_count():
try:
kwargs = request.args.to_dict() if request.method == "GET" else get_post_data_to_kwargs(request)
count = validation_repository.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"error": str(e)}), 404


@bp.route("/<string:id>", methods=["GET"])
def get_validation(id: str):
try:
Expand Down

0 comments on commit ddc5d0b

Please sign in to comment.