Jon Solow
commited on
Commit
·
98ed27b
1
Parent(s):
ba2be41
Get admin page to load
Browse files- src/data_storage.py +23 -43
src/data_storage.py
CHANGED
@@ -1,37 +1,22 @@
|
|
1 |
-
import os
|
2 |
from secrets import token_urlsafe
|
3 |
import streamlit as st
|
4 |
-
import sqlite3
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
DB_PATH = os.path.join(DATA_DIR, "data.db")
|
9 |
-
|
10 |
-
|
11 |
-
def get_db_connection():
|
12 |
-
return sqlite3.connect(DB_PATH)
|
13 |
-
|
14 |
-
|
15 |
-
def initialize_data_storage():
|
16 |
-
with get_db_connection() as con:
|
17 |
-
cur = con.cursor()
|
18 |
-
cur.execute("CREATE TABLE IF NOT EXISTS user_rosters( user_id INTEGER, position_id TEXT, player_id TEXT)")
|
19 |
-
cur.execute("CREATE TABLE IF NOT EXISTS users( user_id INTEGER PRIMARY KEY ASC, email TEXT, name TEXT)")
|
20 |
-
cur.execute("CREATE TABLE IF NOT EXISTS tokens( user_id INTEGER PRIMARY KEY, token TEXT)")
|
21 |
|
22 |
|
23 |
def update_selection(user_id: str | int, position_id: str, player_id: str):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
|
37 |
def get_user_team(user_id):
|
@@ -55,16 +40,16 @@ def add_new_user(email: str, name: str):
|
|
55 |
|
56 |
|
57 |
def get_user(user_id: int):
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
if not user_data:
|
62 |
return {}
|
63 |
-
return
|
64 |
-
"user_id": user_data[0],
|
65 |
-
"email": user_data[1],
|
66 |
-
"name": user_data[2],
|
67 |
-
}
|
68 |
|
69 |
|
70 |
def get_user_id_if_email_exists(email: str) -> int | None:
|
@@ -79,6 +64,7 @@ def get_user_id_if_email_exists(email: str) -> int | None:
|
|
79 |
|
80 |
|
81 |
def is_admin(user_id: int):
|
|
|
82 |
# Replace with db data field later
|
83 |
return user_id == 1
|
84 |
|
@@ -97,6 +83,7 @@ def login_by_token(token: str):
|
|
97 |
|
98 |
|
99 |
def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
|
|
100 |
# returns true if logged in successfully
|
101 |
token = token_urlsafe(32)
|
102 |
with get_db_connection() as con:
|
@@ -115,13 +102,6 @@ def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
|
115 |
return token
|
116 |
|
117 |
|
118 |
-
def drop_tables():
|
119 |
-
with get_db_connection() as con:
|
120 |
-
cur = con.cursor()
|
121 |
-
cur.execute("DROP TABLE user_rosters")
|
122 |
-
cur.execute("DROP TABLE users")
|
123 |
-
cur.execute("DROP TABLE tokens")
|
124 |
-
|
125 |
|
126 |
def get_all_users(columns_included: list[str] = ["user_id", "name", "email"]):
|
127 |
columns_as_str = ",".join(columns_included)
|
|
|
|
|
1 |
from secrets import token_urlsafe
|
2 |
import streamlit as st
|
|
|
3 |
|
4 |
+
from queries.supabase_db.client import supabase_client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
def update_selection(user_id: str | int, position_id: str, player_id: str):
|
8 |
+
pass
|
9 |
+
# with get_db_connection() as con:
|
10 |
+
# cur = con.cursor()
|
11 |
+
# cur.execute(
|
12 |
+
# f"""DELETE FROM user_rosters where user_id = {user_id} and position_id = '{position_id}'
|
13 |
+
# """
|
14 |
+
# )
|
15 |
+
# cur.execute(
|
16 |
+
# f"""INSERT INTO user_rosters (user_id, position_id, player_id )
|
17 |
+
# VALUES({user_id}, '{position_id}', '{player_id}')
|
18 |
+
# """
|
19 |
+
# )
|
20 |
|
21 |
|
22 |
def get_user_team(user_id):
|
|
|
40 |
|
41 |
|
42 |
def get_user(user_id: int):
|
43 |
+
user_data = (
|
44 |
+
supabase_client.table("npcs_users")
|
45 |
+
.select("user_id", "email", "name")
|
46 |
+
.eq("user_id", user_id)
|
47 |
+
.execute()
|
48 |
+
.data
|
49 |
+
)
|
50 |
if not user_data:
|
51 |
return {}
|
52 |
+
return user_data[0]
|
|
|
|
|
|
|
|
|
53 |
|
54 |
|
55 |
def get_user_id_if_email_exists(email: str) -> int | None:
|
|
|
64 |
|
65 |
|
66 |
def is_admin(user_id: int):
|
67 |
+
return True
|
68 |
# Replace with db data field later
|
69 |
return user_id == 1
|
70 |
|
|
|
83 |
|
84 |
|
85 |
def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
86 |
+
return {}
|
87 |
# returns true if logged in successfully
|
88 |
token = token_urlsafe(32)
|
89 |
with get_db_connection() as con:
|
|
|
102 |
return token
|
103 |
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def get_all_users(columns_included: list[str] = ["user_id", "name", "email"]):
|
107 |
columns_as_str = ",".join(columns_included)
|