init
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
from dishka.integrations.flask import FromDishka, inject
|
||||
from flask import Blueprint, jsonify, request
|
||||
from protocols.models import KeyDTO
|
||||
from usecase.add import PostKey
|
||||
from usecase.get import GetKey
|
||||
from usecase.put import PutKey
|
||||
|
||||
key_bp = Blueprint("key_bp", __name__)
|
||||
|
||||
|
||||
@key_bp.route("/", methods=["POST"])
|
||||
def past_key():
|
||||
def past_key(usecase: FromDishka[PostKey]):
|
||||
json_data = request.get_json()
|
||||
|
||||
if json_data:
|
||||
result = usecase(request=KeyDTO(key=json_data))
|
||||
return (
|
||||
jsonify({"message": "Received JSON data successfully", "data": json_data}),
|
||||
jsonify({"message": "Received JSON data successfully", "data": result}),
|
||||
200,
|
||||
)
|
||||
else:
|
||||
@@ -17,25 +23,29 @@ def past_key():
|
||||
|
||||
|
||||
@key_bp.route("/", methods=["GET"])
|
||||
def get_key():
|
||||
json_data = request.args.get("key")
|
||||
@inject
|
||||
def get_key(usecase: FromDishka[GetKey]):
|
||||
request_data = request.args.get("key")
|
||||
|
||||
if json_data:
|
||||
if request_data:
|
||||
result = usecase(request=KeyDTO(key=request_data))
|
||||
return (
|
||||
jsonify({"message": "Received JSON data successfully", "data": json_data}),
|
||||
jsonify({"message": "Received JSON data successfully", "data": result}),
|
||||
200,
|
||||
)
|
||||
|
||||
else:
|
||||
return jsonify({"message": "No JSON data received"}), 400
|
||||
return jsonify({"message": "No GET parameters received"}), 400
|
||||
|
||||
|
||||
@key_bp.route("/", methods=["PUT"])
|
||||
def put_key():
|
||||
def put_key(usecase: FromDishka[PutKey]):
|
||||
json_data = request.get_json()
|
||||
|
||||
if json_data:
|
||||
result = usecase(request=KeyDTO(key=json_data))
|
||||
return (
|
||||
jsonify({"message": "Received JSON data successfully", "data": json_data}),
|
||||
jsonify({"message": "Received JSON data successfully", "data": result}),
|
||||
200,
|
||||
)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user