from flask_login import UserMixin from pathlib import Path from database.db import get_db class User(UserMixin): def __init__(self, id_, name, email, profile_pic): self.id = id_ self.name = name self.email = email self.profile_pic = profile_pic @staticmethod def get(user_id): db = get_db() user = db.execute( "SELECT * FROM user WHERE id = ?", (user_id,) ).fetchone() if not user: return None user = User( id_=user[0], name=user[1], email=user[2], profile_pic=user[3] ) return user @staticmethod def create(id_, name, email, profile_pic): db = get_db() db.execute( "INSERT INTO user (id, name, email, profile_pic) " "VALUES (?, ?, ?, ?)", (id_, name, email, profile_pic), ) db.commit() Path(f"userinfo/{id_}").mkdir(parents=True, exist_ok=True) class dbCalendar(): def __init__(self, id_, name, toggle, color): self.usr_id = id_ self.name = name self.toggle = toggle self.color = color @staticmethod def getCalendars(user_id): db = get_db() calendars = db.execute( "SELECT * FROM calendar WHERE usr_id = ?", (user_id,) ).fetchall() return calendars @staticmethod def getCalendar(user_id, calendar_id): db = get_db() calendar = db.execute( "SELECT * FROM calendar WHERE usr_id = ? AND calendar_id = ?", (user_id, calendar_id) ).fetchone() if not calendar: return None return calendar @staticmethod def updateCalendar(user_id, calendar_name, toggle=None, color=None): db = get_db() print("updating") if(toggle != None): print(toggle) db.execute( "UPDATE calendar SET toggle = ? WHERE usr_id = ? AND name = ?", (toggle, user_id, calendar_name) ) db.commit() if(color != None): db.execute( "UPDATE calendar SET color = ? WHERE usr_id = ? AND name = ?", (color, user_id, calendar_name) ) db.commit() @staticmethod def create(user_id, calendar_id, name, color, toggle = 'True'): db = get_db() db.execute( "INSERT INTO calendar (usr_id, calendar_id, name, toggle, color) " "VALUES (?, ?, ?, ?, ?)", (user_id, calendar_id, name, toggle, color), ) db.commit()