feature/balance #13
|
@ -99,6 +99,32 @@ def set_limit(userid, current_session: Session):
|
||||||
return HTTP.no_content()
|
return HTTP.no_content()
|
||||||
|
|
||||||
|
|
||||||
|
@BalancePlugin.blueprint.route("/users/balance/limit", methods=["GET", "PUT"])
|
||||||
|
|||||||
|
@login_required(permission=permissions.SET_LIMIT)
|
||||||
|
def limits(current_session: Session):
|
||||||
|
"""Get, Modify limit of all users
|
||||||
|
|
||||||
|
Args:
|
||||||
|
current_ession: Session sent with Authorization Header
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
JSON encoded array of userid with limit or HTTP-error
|
||||||
|
"""
|
||||||
|
|
||||||
|
users = userController.get_users()
|
||||||
|
if request.method == "GET":
|
||||||
|
return jsonify([{"userid": user.userid, "limit": user.get_attribute("balance_limit")} for user in users])
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
try:
|
||||||
|
limit = data["limit"]
|
||||||
|
except (TypeError, KeyError):
|
||||||
|
raise BadRequest
|
||||||
|
for user in users:
|
||||||
|
balance_controller.set_limit(user, limit)
|
||||||
|
return HTTP.no_content()
|
||||||
|
|
||||||
|
|
||||||
@BalancePlugin.blueprint.route("/users/<userid>/balance", methods=["GET"])
|
@BalancePlugin.blueprint.route("/users/<userid>/balance", methods=["GET"])
|
||||||
@login_required(permission=permissions.SHOW)
|
@login_required(permission=permissions.SHOW)
|
||||||
def get_balance(userid, current_session: Session):
|
def get_balance(userid, current_session: Session):
|
||||||
|
|
Loading…
Reference in New Issue
Not sure how I think about that API.
Not a friend of multiple API endpoints for quite the same task (changing the limit of an user).
But on the other hand the current enpoint requires you to send N requests (for N users)...