From f3eb0c94352b80242bf534c073082681e6fcca75 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 8 Nov 2024 19:37:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D1=80=D0=B8=D1=86=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B9=20coins=5Fadd,=20coins=5Fdel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api.py b/api.py index ae6bd4e..f7e7c66 100644 --- a/api.py +++ b/api.py @@ -134,7 +134,7 @@ class Coins_add(BaseModel): amount: str @app.post('/api/coins_add/') def coins_add(it: Coins_add): - token, id, amount = it.token, it.id, float(it.amount) + token, id, amount = it.token, it.id, abs(float(it.amount)) if token_check(token): db = read() db['id'][id]['bal'] = fix_add(db['id'][id]['bal'], amount) @@ -150,13 +150,16 @@ class Coins_del(BaseModel): amount: str @app.post('/api/coins_del/') def coins_del(it: Coins_del): - token, id, amount = it.token, it.id, float(it.amount) + token, id, amount = it.token, it.id, abs(float(it.amount)) if token_check(token): db = read() - db['id'][id]['bal'] = fix_sub(db['id'][id]['bal'], amount) - write(db) - stat_run(amount*-1) - return 'OK' + if db['id'][id]['bal'] >= amount: + db['id'][id]['bal'] = fix_sub(db['id'][id]['bal'], amount) + write(db) + stat_run(amount*-1) + return 'OK' + else: + return 'Error' else: return 'Error'