Compare commits

..

No commits in common. "eb8badd3aeead2bb797c9246bfeb72380516151d" and "03eec7bd4afa0c5eccc81292e5ad320ea3f5318d" have entirely different histories.

4 changed files with 6 additions and 49 deletions

30
app.py
View File

@ -5,7 +5,6 @@ from flask import Flask, render_template, redirect, url_for, request
from flask_login import login_required, LoginManager, login_user, logout_user, current_user
from models.Habit import Habit
from models.HabitTrackings import HabitTrackings
from models.User import User
from utils import anonymous_required
@ -224,33 +223,8 @@ def habit_create():
@app.route('/check', methods=['POST'])
@login_required
def check_habit():
habit_id = request.get_json()["habitId"]
habit = Habit.get(habit_id)
if habit is None:
return {"error": "Habit not found"}
# Check if habit belongs to user
if habit.user_id != current_user.id:
return {"error": "Habit does not belong to user"}
trackings = habit.get_habitTrackings()
# Check if habit has been tracked today
unchecked = False
for tracking in trackings:
if tracking.created_at.date() == datetime.date.today():
tracking.delete()
unchecked = True
if not unchecked:
HabitTrackings.create(habit_id, 1)
return {
"habitId": habit_id,
"unchecked": unchecked,
}
habit = request.get_json()["habitId"]
return {}
# Run the application

View File

@ -140,16 +140,6 @@ def get_habitTrackings(id: int):
return habit_tracking
def get_habitTrackings_by_habit_id(habit_id: int):
query = f"SELECT * FROM habit_trackings WHERE habit_id = {habit_id};"
conn = con3()
cursor = conn.cursor()
cursor.execute(query)
habit_trackings = cursor.fetchall()
conn.close()
return habit_trackings
def delete_habitTrackings(id: int):
query = f"DELETE FROM habit_trackings WHERE id = {id};"
conn = con3()

View File

@ -1,7 +1,5 @@
from dataclasses import dataclass
from db.SQLiteClient import create_habit, get_habit, delete_habit, get_next_slot, get_habitTrackings_by_habit_id
from models.HabitTrackings import HabitTrackings
from models.User import User
from db.SQLiteClient import create_habit, get_habit, delete_habit, get_next_slot
# Unit wird als Integers wie folgt gemessen:
@ -34,9 +32,3 @@ class Habit:
@staticmethod
def delete(id: int):
delete_habit(id)
def get_user(self):
return User.get(self.user_id)
def get_habitTrackings(self) -> list[HabitTrackings]:
return get_habitTrackings_by_habit_id(self.id)

View File

@ -18,5 +18,6 @@ class HabitTrackings:
habitTrackings = get_habitTrackings(id)
return HabitTrackings(habitTrackings[0], habitTrackings[1], habitTrackings[2]) if habitTrackings else None
def delete(self):
delete_habitTrackings(self.id)
@staticmethod
def delete(id: int):
delete_habitTrackings(id)