Updated get_next_Slot method
This commit is contained in:
parent
9e41461359
commit
03eec7bd4a
2
app.py
2
app.py
@ -219,12 +219,14 @@ def habit_create():
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
|
|
||||||
@app.route('/check', methods=['POST'])
|
@app.route('/check', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def check_habit():
|
def check_habit():
|
||||||
habit = request.get_json()["habitId"]
|
habit = request.get_json()["habitId"]
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(port=5000, debug=True)
|
app.run(port=5000, debug=True)
|
||||||
|
|||||||
@ -75,13 +75,17 @@ def create_habit(user_id: int, name: str, times: int, unit: int, slot: int, note
|
|||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
|
||||||
def get_next_slot():
|
def get_next_slot(user_id: int):
|
||||||
query = f"SELECT slot FROM habits ORDER BY slot DESC LIMIT 1;"
|
query = f"SELECT slot FROM habits WHERE user_id = {user_id} ORDER BY slot DESC LIMIT 1;"
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
slot = cursor.fetchone()
|
slot = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
if not slot:
|
||||||
|
return 0
|
||||||
|
|
||||||
return slot[0] + 1 if slot else 0
|
return slot[0] + 1 if slot else 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class Habit:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
|
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)
|
id = create_habit(user_id, name, times, unit, slot, note)
|
||||||
return Habit(id, user_id, name, note, times, unit, slot)
|
return Habit(id, user_id, name, note, times, unit, slot)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user