diff --git a/app.py b/app.py index a5b4243..22aeedd 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index bd54171..ae9bb5f 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -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 diff --git a/models/Habit.py b/models/Habit.py index 044b83b..812330f 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -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)