Skip to content

Commit c4ff53b

Browse files
committed
feat: update observed var schema
1 parent 4dbcdc4 commit c4ff53b

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/model/method.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
if TYPE_CHECKING:
1414
from src.model.device import Device
15+
from src.model.observed_variable import ObservedVariable
1516
from src.model.vocabulary import Vocabulary
1617

1718

@@ -23,8 +24,15 @@ class Method(Base):
2324
# Relationships:
2425
method_reference_id: Mapped[UUID | None] = mapped_column(ForeignKey("vocabulary_table.id", ondelete="SET NULL"))
2526
method_reference: Mapped[Optional["Vocabulary"]] = relationship(
26-
back_populates="method", lazy=None, info=dto_field("read-only"),
27+
back_populates="method",
28+
lazy=None,
29+
info=dto_field("read-only"),
2730
)
2831

2932
device_id: Mapped[UUID | None] = mapped_column(ForeignKey("device_table.id", ondelete="SET NULL"))
3033
device: Mapped[Optional["Device"]] = relationship(lazy=None, info=dto_field("read-only"))
34+
observed_variable: Mapped[Optional["ObservedVariable"]] = relationship(
35+
"ObservedVariable",
36+
lazy=None,
37+
info=dto_field("read-only"),
38+
)

src/model/observed_variable.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
if TYPE_CHECKING:
15+
from src.model.method import Method
1516
from src.model.vocabulary import Vocabulary
1617

1718

@@ -21,6 +22,13 @@ class ObservedVariable(Variable):
2122
id: Mapped[UUID] = mapped_column(ForeignKey("variable_table.id"), primary_key=True, info=dto_field("read-only"))
2223

2324
title: Mapped[str] = mapped_column(nullable=False)
25+
method_id: Mapped[UUID | None] = mapped_column(ForeignKey("method_table.id", ondelete="SET NULL"))
26+
method: Mapped[Optional["Method"]] = relationship(
27+
"Method",
28+
lazy=None,
29+
back_populates="observed_variable",
30+
info=dto_field("read-only"),
31+
)
2432
trait_reference_id: Mapped[UUID | None] = mapped_column(ForeignKey("vocabulary_table.id", ondelete="SET NULL"))
2533
trait_reference: Mapped[Optional["Vocabulary"]] = relationship(
2634
"Vocabulary",
@@ -34,4 +42,5 @@ class ObservedVariable(Variable):
3442
@dataclass(kw_only=True)
3543
class ObservedVariableDataclass(VariableDataclass):
3644
title: str
45+
method_id: UUID | None = field(default=None)
3746
trait_reference_id: UUID | None = field(default=None)

src/router/observed_variable.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
from src.model import ObservedVariable
2-
from src.router.base import BaseController
1+
from litestar.dto import DataclassDTO, DTOConfig
2+
3+
from src.model.observed_variable import ObservedVariable, ObservedVariableDataclass
4+
from src.model.study import Study
5+
from src.router.base import DataclassController
36
from src.router.utils.dto import DTOGenerator
47

58
__all__ = ("ObservedVariableController",)
69

710

8-
ObservedVariableDTO = DTOGenerator[ObservedVariable]()
11+
class ObservedVariableDTO(DataclassDTO[ObservedVariableDataclass]):
12+
config = DTOConfig(rename_strategy="camel")
13+
14+
15+
ObservedVariableReturnDTO = DTOGenerator[ObservedVariable]()
916

1017

11-
class ObservedVariableController(BaseController[ObservedVariable]):
18+
class ObservedVariableController(DataclassController[ObservedVariable, ObservedVariableDataclass]):
1219
path = "/observedVariable"
13-
dto = ObservedVariableDTO.write_dto
14-
return_dto = ObservedVariableDTO.read_dto
20+
dto = ObservedVariableDTO
21+
return_dto = ObservedVariableDTO
22+
attr_map = {"studies": ("study_id", Study)}
23+
selectinload_attrs = [ObservedVariable.studies]

0 commit comments

Comments
 (0)