Updated get_next_Slot method

This commit is contained in:
Verox001 2024-01-26 08:30:06 +01:00
parent 9e41461359
commit 03eec7bd4a
3 changed files with 9 additions and 3 deletions

2
app.py
View File

@ -219,12 +219,14 @@ def habit_create():
errors=errors,
)"""
@app.route('/check', methods=['POST'])
@login_required
def check_habit():
habit = request.get_json()["habitId"]
return {}
# Run the application
if __name__ == '__main__':
app.run(port=5000, debug=True)

View File

@ -75,13 +75,17 @@ def create_habit(user_id: int, name: str, times: int, unit: int, slot: int, note
return cursor.lastrowid
def get_next_slot():
query = f"SELECT slot FROM habits ORDER BY slot DESC LIMIT 1;"
def get_next_slot(user_id: int):
query = f"SELECT slot FROM habits WHERE user_id = {user_id} ORDER BY slot DESC LIMIT 1;"
conn = con3()
cursor = conn.cursor()
cursor.execute(query)
slot = cursor.fetchone()
conn.close()
if not slot:
return 0
return slot[0] + 1 if slot else 0

View File

@ -20,7 +20,7 @@ class Habit:
@staticmethod
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
slot = get_next_slot()
slot = get_next_slot(user_id)
id = create_habit(user_id, name, times, unit, slot, note)
return Habit(id, user_id, name, note, times, unit, slot)