adds calendars to sql database, calls backend to remap calendars to color accurate information

This commit is contained in:
2020-04-15 17:43:11 +00:00
parent 19bbf53282
commit 04942268a6
3 changed files with 97 additions and 21 deletions

View File

@ -4,3 +4,11 @@ CREATE TABLE user (
email TEXT UNIQUE NOT NULL,
profile_pic TEXT NOT NULL
);
CREATE TABLE calendar (
usr_id TEXT NOT NULL,
calendar_id TEXT PRIMARY KEY,
name TEXT NOT NULL,
toggle INT NOT NULL,
color TEXT
);

View File

@ -36,3 +36,37 @@ class User(UserMixin):
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
@staticmethod
def create(user_id, calendar_id, name, color, toggle = False):
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()