Name refactoring

This commit is contained in:
Eden Kirin
2023-02-17 09:43:33 +01:00
parent ba64cd947a
commit 16c99a1efc
4 changed files with 3 additions and 4 deletions

View File

@ -0,0 +1,37 @@
from dataclasses import dataclass
from typing import List, Optional
@dataclass
class UserBase:
id: int
first_name: str
last_name: str
@dataclass
class Employee(UserBase):
department: str
@dataclass
class Partner(UserBase):
company: str
class UserContainer(list):
def get_user_by_id(self, id: int) -> Optional[UserBase]:
for user in self:
if user.id == id:
return user
return None
class EmployeeContainer(UserContainer):
def get_by_department(self, department: str) -> List[Employee]:
return [user for user in self if user.department == department]
class PartnerContainer(UserContainer):
def get_by_company(self, company: str) -> List[Partner]:
return [user for user in self if user.company == company]