Skip to content

Commit

Permalink
Fix updating the uses (#6)
Browse files Browse the repository at this point in the history
* update the usescsv db row when uses change
* add a created column for visual aid of the created links
* allow decrease uses
  • Loading branch information
talvasconcelos authored Sep 24, 2023
1 parent 13ca6ed commit d8b6ac4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ new Vue({
label: 'Wait',
field: 'wait_time'
},
{
name: 'uses',
align: 'right',
label: 'Created',
field: 'uses'
},
{
name: 'uses_left',
align: 'right',
Expand Down
22 changes: 21 additions & 1 deletion views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,27 @@ async def api_link_create_or_update(
raise HTTPException(
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:
link = await create_withdraw_link(wallet_id=wallet.wallet.id, data=data)
assert link
Expand Down

0 comments on commit d8b6ac4

Please sign in to comment.