sync
This commit is contained in:
@@ -15,16 +15,18 @@ key_bp = Blueprint("key_bp", __name__)
|
||||
def past_key(usecase: FromDishka[PostKey]):
|
||||
json_data = request.get_json()
|
||||
|
||||
if not json_data.get("key"):
|
||||
abort(400, "'key' required")
|
||||
elif not json_data.get("val"):
|
||||
abort(400, "'val' required")
|
||||
|
||||
if json_data:
|
||||
result = usecase(
|
||||
request=KeyDTO(key=json_data.get("key"), val=json_data.get("val"))
|
||||
)
|
||||
return (
|
||||
jsonify({"message": "Ok", "data": result}),
|
||||
201,
|
||||
)
|
||||
result = usecase(request=KeyDTO(key=json_data.get("key"), val=json_data.get("val")))
|
||||
if result is None:
|
||||
abort(400, "Key alredy exist")
|
||||
return jsonify({"message": "Ok", "data": result}), 201
|
||||
else:
|
||||
return jsonify({"message": "No JSON data received"}), 400
|
||||
abort(400, "Invalid json data")
|
||||
|
||||
|
||||
@key_bp.route("/", methods=["GET"])
|
||||
@@ -50,16 +52,21 @@ def get_key(usecase: FromDishka[GetKey]):
|
||||
def put_key(usecase: FromDishka[PutKey]):
|
||||
json_data = request.get_json()
|
||||
|
||||
if not json_data.get("key"):
|
||||
abort(400, "'key' required")
|
||||
elif not json_data.get("val"):
|
||||
abort(400, "'val' required")
|
||||
|
||||
if json_data:
|
||||
result = usecase(
|
||||
request=KeyDTO(key=json_data.get("key"), val=json_data.get("val"))
|
||||
)
|
||||
result = usecase(request=KeyDTO(key=json_data.get("key"), val=json_data.get("val")))
|
||||
if result is None:
|
||||
abort(400, "No item for update")
|
||||
return (
|
||||
jsonify({"message": "Updated", "data": result}),
|
||||
200,
|
||||
)
|
||||
else:
|
||||
return jsonify({"message": "No JSON data received"}), 400
|
||||
abort(400, "Inalid JSON data")
|
||||
|
||||
|
||||
@key_bp.route("/", methods=["DELETE"])
|
||||
@@ -74,4 +81,4 @@ def delete_key(usecase: FromDishka[DelKey]):
|
||||
200,
|
||||
)
|
||||
else:
|
||||
return jsonify({"message": "No JSON data received"}), 400
|
||||
abort(400, "Inalid JSON data")
|
||||
|
Reference in New Issue
Block a user