adjust variant-getter methods to handle invalid inputs

This commit is contained in:
Maximilian Keßler 2023-05-13 19:52:32 +02:00
parent 4e373be425
commit 0ffb323b7f
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -1,32 +1,38 @@
import enum import enum
from typing import List from typing import List, Optional
from hanabi import DeckCard, ActionType from hanabi import DeckCard, ActionType
from database.database import cur from database.database import cur
def variant_id(name): def variant_id(name) -> Optional[int]:
cur.execute( cur.execute(
"SELECT id FROM variants WHERE name = %s", "SELECT id FROM variants WHERE name = %s",
(name,) (name,)
) )
return cur.fetchone()[0] var_id = cur.fetchone()
if var_id is not None:
return var_id[0]
def variant_name(var_id): def variant_name(var_id) -> Optional[int]:
cur.execute( cur.execute(
"SELECT name FROM variants WHERE id = %s", "SELECT name FROM variants WHERE id = %s",
(var_id,) (var_id,)
) )
return cur.fetchone()[0] name = cur.fetchone()
if name is not None:
return name[0]
def num_suits(var_id): def num_suits(var_id) -> Optional[int]:
cur.execute( cur.execute(
"SELECT num_suits FROM variants WHERE id = %s", "SELECT num_suits FROM variants WHERE id = %s",
(var_id,) (var_id,)
) )
return cur.fetchone()[0] num = cur.fetchone()
if num is not None:
return num
class ClueBehaviour(enum.Enum): class ClueBehaviour(enum.Enum):