remove pydantic from nkode_api.py
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
from pydantic import BaseModel
|
from typing import Dict, List, Tuple
|
||||||
|
|
||||||
from src.customer import Customer
|
from src.customer import Customer
|
||||||
from src.models import NKodePolicy, KeypadSize
|
from src.models import NKodePolicy, KeypadSize
|
||||||
from src.user import User
|
from src.user import User
|
||||||
@@ -9,9 +11,10 @@ from src.user_interface import UserInterface
|
|||||||
from src.customer_attributes import CustomerAttributes
|
from src.customer_attributes import CustomerAttributes
|
||||||
|
|
||||||
|
|
||||||
class NKodeAPI(BaseModel):
|
@dataclass
|
||||||
customers: dict[UUID, Customer] = {}
|
class NKodeAPI:
|
||||||
signup_sessions: dict[UUID, UserSignupSession] = {}
|
customers: Dict[UUID, Customer] = field(default_factory=dict)
|
||||||
|
signup_sessions: Dict[UUID, UserSignupSession] = field(default_factory=dict)
|
||||||
|
|
||||||
def create_new_customer(self, keypad_size: KeypadSize, nkode_policy: NKodePolicy) -> UUID:
|
def create_new_customer(self, keypad_size: KeypadSize, nkode_policy: NKodePolicy) -> UUID:
|
||||||
new_customer = Customer(
|
new_customer = Customer(
|
||||||
@@ -23,7 +26,7 @@ class NKodeAPI(BaseModel):
|
|||||||
self.customers[new_customer.customer_id] = new_customer
|
self.customers[new_customer.customer_id] = new_customer
|
||||||
return new_customer.customer_id
|
return new_customer.customer_id
|
||||||
|
|
||||||
def generate_signup_interface(self, customer_id: UUID) -> tuple[UUID, list[int]]:
|
def generate_signup_interface(self, customer_id: UUID) -> Tuple[UUID, List[int]]:
|
||||||
if customer_id not in self.customers.keys():
|
if customer_id not in self.customers.keys():
|
||||||
raise ValueError(f"Customer with ID '{customer_id}' does not exist")
|
raise ValueError(f"Customer with ID '{customer_id}' does not exist")
|
||||||
customer = self.customers[customer_id]
|
customer = self.customers[customer_id]
|
||||||
@@ -43,9 +46,9 @@ class NKodeAPI(BaseModel):
|
|||||||
self,
|
self,
|
||||||
username: str,
|
username: str,
|
||||||
customer_id: UUID,
|
customer_id: UUID,
|
||||||
key_selection: list[int],
|
key_selection: List[int],
|
||||||
session_id: UUID
|
session_id: UUID
|
||||||
) -> list[int]:
|
) -> List[int]:
|
||||||
if customer_id not in self.customers.keys():
|
if customer_id not in self.customers.keys():
|
||||||
raise ValueError(f"Customer ID {customer_id} not found")
|
raise ValueError(f"Customer ID {customer_id} not found")
|
||||||
customer = self.customers[customer_id]
|
customer = self.customers[customer_id]
|
||||||
@@ -60,7 +63,7 @@ class NKodeAPI(BaseModel):
|
|||||||
self,
|
self,
|
||||||
username: str,
|
username: str,
|
||||||
customer_id: UUID,
|
customer_id: UUID,
|
||||||
confirm_key_entry: list[int],
|
confirm_key_entry: List[int],
|
||||||
session_id: UUID
|
session_id: UUID
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if session_id not in self.signup_sessions.keys():
|
if session_id not in self.signup_sessions.keys():
|
||||||
@@ -88,7 +91,7 @@ class NKodeAPI(BaseModel):
|
|||||||
del self.signup_sessions[session_id]
|
del self.signup_sessions[session_id]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_login_interface(self, username: str, customer_id: UUID) -> list[int]:
|
def get_login_interface(self, username: str, customer_id: UUID) -> List[int]:
|
||||||
if customer_id not in self.customers.keys():
|
if customer_id not in self.customers.keys():
|
||||||
raise ValueError("Customer ID not found")
|
raise ValueError("Customer ID not found")
|
||||||
customer = self.customers[customer_id]
|
customer = self.customers[customer_id]
|
||||||
@@ -98,7 +101,7 @@ class NKodeAPI(BaseModel):
|
|||||||
user.user_interface.partial_interface_shuffle()
|
user.user_interface.partial_interface_shuffle()
|
||||||
return user.user_interface.interface
|
return user.user_interface.interface
|
||||||
|
|
||||||
def login(self, customer_id: UUID, username: str, key_selection: list[int]) -> bool:
|
def login(self, customer_id: UUID, username: str, key_selection: List[int]) -> bool:
|
||||||
if customer_id not in self.customers.keys():
|
if customer_id not in self.customers.keys():
|
||||||
raise ValueError("Customer ID not found")
|
raise ValueError("Customer ID not found")
|
||||||
customer = self.customers[customer_id]
|
customer = self.customers[customer_id]
|
||||||
|
|||||||
Reference in New Issue
Block a user