Jon Solow commited on
Commit
1f6b17c
·
1 Parent(s): 69f6ae6

Create a table for user data

Browse files
Files changed (1) hide show
  1. src/data_storage.py +22 -1
src/data_storage.py CHANGED
@@ -14,6 +14,7 @@ def initialize_data_storage():
14
  with get_db_connection() as con:
15
  cur = con.cursor()
16
  cur.execute("CREATE TABLE IF NOT EXISTS user_rosters( user_id INTEGER, position_id TEXT, player_id TEXT)")
 
17
 
18
 
19
  def update_selection(user_id: str, position_id: str, player_id: str):
@@ -29,9 +30,29 @@ def update_selection(user_id: str, position_id: str, player_id: str):
29
  def get_user_team(user_id):
30
  with get_db_connection() as con:
31
  cur = con.cursor()
32
- cur = get_db_connection().cursor()
33
  team = cur.execute(f"select * from user_rosters where user_id = {user_id}").fetchall()
34
  if team:
35
  return {x[1]: x[2] for x in team}
36
  else:
37
  return {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  with get_db_connection() as con:
15
  cur = con.cursor()
16
  cur.execute("CREATE TABLE IF NOT EXISTS user_rosters( user_id INTEGER, position_id TEXT, player_id TEXT)")
17
+ cur.execute("CREATE TABLE IF NOT EXISTS users( user_id INTEGER PRIMARY KEY ASC, email TEXT, name TEXT)")
18
 
19
 
20
  def update_selection(user_id: str, position_id: str, player_id: str):
 
30
  def get_user_team(user_id):
31
  with get_db_connection() as con:
32
  cur = con.cursor()
 
33
  team = cur.execute(f"select * from user_rosters where user_id = {user_id}").fetchall()
34
  if team:
35
  return {x[1]: x[2] for x in team}
36
  else:
37
  return {}
38
+
39
+
40
+ def add_new_user(email: str, name: str):
41
+ with get_db_connection() as con:
42
+ cur = con.cursor()
43
+ cur.execute(
44
+ f"""INSERT INTO users (email, name )
45
+ VALUES('{email}', '{name}')
46
+ """
47
+ )
48
+
49
+
50
+ def get_user(user_id: int):
51
+ with get_db_connection() as con:
52
+ cur = con.cursor()
53
+ user_data = cur.execute(f"select * from users where user_id = {user_id}").fetchone()
54
+ return {
55
+ "user_id": user_data[0],
56
+ "email": user_data[1],
57
+ "name": user_data[2],
58
+ }