remove pydantic from nkode_api.py

This commit is contained in:
2025-03-09 09:22:32 -05:00
parent 94cab10aff
commit 75787b7142

View File

@@ -1,5 +1,7 @@
from dataclasses import dataclass, field
from uuid import UUID, uuid4
from pydantic import BaseModel
from typing import Dict, List, Tuple
from src.customer import Customer
from src.models import NKodePolicy, KeypadSize
from src.user import User
@@ -9,9 +11,10 @@ from src.user_interface import UserInterface
from src.customer_attributes import CustomerAttributes
class NKodeAPI(BaseModel):
customers: dict[UUID, Customer] = {}
signup_sessions: dict[UUID, UserSignupSession] = {}
@dataclass
class NKodeAPI:
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:
new_customer = Customer(
@@ -23,7 +26,7 @@ class NKodeAPI(BaseModel):
self.customers[new_customer.customer_id] = new_customer
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():
raise ValueError(f"Customer with ID '{customer_id}' does not exist")
customer = self.customers[customer_id]
@@ -43,9 +46,9 @@ class NKodeAPI(BaseModel):
self,
username: str,
customer_id: UUID,
key_selection: list[int],
key_selection: List[int],
session_id: UUID
) -> list[int]:
) -> List[int]:
if customer_id not in self.customers.keys():
raise ValueError(f"Customer ID {customer_id} not found")
customer = self.customers[customer_id]
@@ -60,7 +63,7 @@ class NKodeAPI(BaseModel):
self,
username: str,
customer_id: UUID,
confirm_key_entry: list[int],
confirm_key_entry: List[int],
session_id: UUID
) -> bool:
if session_id not in self.signup_sessions.keys():
@@ -88,7 +91,7 @@ class NKodeAPI(BaseModel):
del self.signup_sessions[session_id]
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():
raise ValueError("Customer ID not found")
customer = self.customers[customer_id]
@@ -98,7 +101,7 @@ class NKodeAPI(BaseModel):
user.user_interface.partial_interface_shuffle()
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():
raise ValueError("Customer ID not found")
customer = self.customers[customer_id]