35 lines
801 B
Python
35 lines
801 B
Python
|
from typing import Generator
|
||
|
|
||
|
from pydantic.dataclasses import dataclass
|
||
|
|
||
|
|
||
|
@dataclass(frozen=True)
|
||
|
class Laboratory:
|
||
|
id: int
|
||
|
name: str
|
||
|
pi_name: str
|
||
|
full_name: str
|
||
|
|
||
|
|
||
|
@dataclass(frozen=True)
|
||
|
class Laboratories:
|
||
|
items: list[Laboratory]
|
||
|
|
||
|
def __iter__(self) -> Generator[Laboratory, None, None]:
|
||
|
yield from self.items
|
||
|
|
||
|
def empty(self) -> bool:
|
||
|
return len(self.items) == 0
|
||
|
|
||
|
def clear(self) -> None:
|
||
|
self.items.clear()
|
||
|
|
||
|
def append(self, item: Laboratory) -> None:
|
||
|
self.items.append(item)
|
||
|
|
||
|
def find_by_id(self, id: int) -> Laboratory | None:
|
||
|
return next((x for x in self.items if x.id == id), None)
|
||
|
|
||
|
def find_by_name(self, name: str) -> Laboratory | None:
|
||
|
return next((x for x in self.items if x.name == name), None)
|