Fix updating the uses (#6)
* update the usescsv db row when uses change * add a created column for visual aid of the created links * allow decrease uses
This commit is contained in:
parent
13ca6ed5c4
commit
d8b6ac40bc
2 changed files with 27 additions and 1 deletions
|
|
@ -43,6 +43,12 @@ new Vue({
|
||||||
label: 'Wait',
|
label: 'Wait',
|
||||||
field: 'wait_time'
|
field: 'wait_time'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'uses',
|
||||||
|
align: 'right',
|
||||||
|
label: 'Created',
|
||||||
|
field: 'uses'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'uses_left',
|
name: 'uses_left',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
|
|
||||||
22
views_api.py
22
views_api.py
|
|
@ -113,7 +113,27 @@ async def api_link_create_or_update(
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
detail="Not your withdraw link.", status_code=HTTPStatus.FORBIDDEN
|
detail="Not your withdraw link.", status_code=HTTPStatus.FORBIDDEN
|
||||||
)
|
)
|
||||||
link = await update_withdraw_link(link_id, **data.dict())
|
|
||||||
|
data_dict = data.dict()
|
||||||
|
if link.uses > data.uses:
|
||||||
|
if data.uses - link.used <= 0:
|
||||||
|
raise HTTPException(
|
||||||
|
detail="Cannot reduce uses below current used.", status_code=HTTPStatus.BAD_REQUEST
|
||||||
|
)
|
||||||
|
numbers = link.usescsv.split(",")
|
||||||
|
usescsv = ",".join(numbers[:data.uses - link.used])
|
||||||
|
data_dict["usescsv"] = usescsv
|
||||||
|
|
||||||
|
if link.uses < data.uses:
|
||||||
|
numbers = link.usescsv.split(",")
|
||||||
|
current_number = int(numbers[-1])
|
||||||
|
while len(numbers) < (data.uses - link.used):
|
||||||
|
current_number += 1
|
||||||
|
numbers.append(str(current_number))
|
||||||
|
usescsv = ",".join(numbers)
|
||||||
|
data_dict["usescsv"] = usescsv
|
||||||
|
|
||||||
|
link = await update_withdraw_link(link_id, **data_dict)
|
||||||
else:
|
else:
|
||||||
link = await create_withdraw_link(wallet_id=wallet.wallet.id, data=data)
|
link = await create_withdraw_link(wallet_id=wallet.wallet.id, data=data)
|
||||||
assert link
|
assert link
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue