Skip to content

Commit

Permalink
Recurring Orders & scheduler (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3nd0x authored Jun 20, 2024
2 parents a0bc813 + 19953bc commit ff389e9
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 136 deletions.
29 changes: 16 additions & 13 deletions webapp/api/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,23 @@ async def startup_event():
continue

#### migrate pig_bidmapping to pig_userbudgets
user_data = mysql.get('''select * from registered_user''')
bidmapping_data = mysql.get('''select * from pig_bidmapping''')
try:
user_data = mysql.get('''select * from registered_user''')
bidmapping_data = mysql.get('''select * from pig_bidmapping''')

insert_query = "INSERT INTO pig_userbudgets (user_id, budget_id, joined) VALUES (%s, %s, %s)"
insert_query = "INSERT INTO pig_userbudgets (user_id, budget_id, joined) VALUES (%s, %s, %s)"

for user in user_data:
for bidmapping in bidmapping_data:
if bidmapping["id"] == user["bid_mapping"]:
for i in "b0", "b1", "b2", "b3":
if bidmapping[i]:
mysql.post(f'''insert into pig_userbudgets values ({user["id"]},{bidmapping[i]},1)''')

noti_queries = "INSERT IGNORE INTO pig_notisettings VALUES ({user_id},1,1,1,1),({user_id},1,2,1,1),({user_id},2,1,1,1),({user_id},2,2,1,1),({user_id},3,3,1,1),({user_id},1,3,1,1),({user_id},2,3,1,1),({user_id},4,3,1,1)".format(user_id=user["id"])
mysql.post(noti_queries)
for user in user_data:
for bidmapping in bidmapping_data:
if bidmapping["id"] == user["bid_mapping"]:
for i in "b0", "b1", "b2", "b3":
if bidmapping[i]:
mysql.post(f'''insert into pig_userbudgets values ({user["id"]},{bidmapping[i]},1)''')

noti_queries = "INSERT IGNORE INTO pig_notisettings VALUES ({user_id},1,1,1,1),({user_id},1,2,1,1),({user_id},2,1,1,1),({user_id},2,2,1,1),({user_id},3,3,1,1),({user_id},1,3,1,1),({user_id},2,3,1,1),({user_id},4,3,1,1)".format(user_id=user["id"])
mysql.post(noti_queries)
except:
print("Skipping bid_mapping migration")

mysql.close()

Expand Down Expand Up @@ -200,7 +203,7 @@ async def get_current_user(token: str = Depends(oauth2_scheme)):
except JWTError:
mysql.close()
raise credentials_exception
user = mysql.get('''select id,email,name,bid_mapping from registered_user where email="{}"'''.format(username))
user = mysql.get('''select id,email,name from registered_user where email="{}"'''.format(username))
mysql.close()
if user is None:
raise credentials_exception
Expand Down
16 changes: 13 additions & 3 deletions webapp/api/routes/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class newOrder(BaseModel):
day: Optional[str] = None
date: Optional[str] = None
currency: Optional[str] = None
recurring: Optional[str] = None
budget_id: str
class Config:
schema_extra = {
Expand All @@ -70,8 +71,9 @@ class Config:
"day": "01 (optional)",
"date": "2024-01-01 (optional)",
"budget_id": "151",
"description": "Einkaufen Kupsch (optional)",
"currency": "EUR (optional)"
"description": "Groceries (optional)",
"currency": "EUR (optional)",
"recurring": "choose between daily weekly monthly quarterly halfyearly yearly"
}
}

Expand Down Expand Up @@ -121,14 +123,22 @@ async def orders(newOrder: newOrder,current_user = Depends(get_current_user)):


insert = mysql.post(query)
if newOrder.recurring:
schedule = newOrder.recurring
order_id = mysql.lastrowid()

query = f'''INSERT into pig_schedules(schedule,o_id) VALUES("{schedule}",{order_id})'''

insert = mysql.post(query)

if insert == True:
output = "Order added".format(userid,value, curr, category,description)

uid_list = _get_uids(mysql,budget_id)
print(uid_list,flush=True)

for dstuid in uid_list:
dstuid = dstuid["id"]
dstuid = dstuid["user_id"]

if dstuid != userid:

Expand Down
3 changes: 1 addition & 2 deletions webapp/api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ async def delete_account(userid: str,budget_id: str, force: bool=False, dict = D
if mysql.get('''select mode from pig_budgets where id={}'''.format(budget_id))[0]["mode"] == 0:
query = '''delete from pig_budgets where id={} and mode=0'''.format(budget_id)
query1 = '''delete from pig_category where budget_id={}'''.format(budget_id)
query2 = '''delete from pig_bidmapping where b0={}'''.format(budget_id)
for i in query,query1,query2:
for i in query,query1:
response.append(mysql.delete(i))
query = '''delete from pig_orders where user_id={}'''.format(userid)
query1 = '''delete from registered_user where id={}'''.format(userid)
Expand Down
9 changes: 7 additions & 2 deletions webapp/app/views/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ def get_data():
else:
flash_message = {response: "success"}
elif data["ordertype"] == "recurring":
print("skip")
flash_message = {False: "danger"}
data.pop("ordertype")

s, response = pigapi.post(url="order/new", data=data)
if response == "Order added!":
flash_message = {response: "danger"}
else:
flash_message = {response: "success"}

flash(flash_message)
pigapi.close()
Expand Down
Loading

0 comments on commit ff389e9

Please sign in to comment.