Skip to content

Commit

Permalink
Fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard committed Aug 3, 2024
1 parent 666ac7b commit d8ffed2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cg/server/dto/samples/samples_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from cg.constants.subject import Sex


class CustomerDto(BaseModel):
internal_id: str
name: str


class SampleDTO(BaseModel):
name: str | None = None
internal_id: str | None = None
Expand Down Expand Up @@ -38,7 +43,7 @@ class SampleDTO(BaseModel):
status: str | None = None
tumour: bool | None = None
reference_genome: str | None = None
customer: str | None = None
customer: CustomerDto | None = None


class SamplesResponse(BaseModel):
Expand Down
8 changes: 6 additions & 2 deletions cg/services/sample_service/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from cg.server.dto.samples.samples_response import SampleDTO, SamplesResponse
from cg.server.dto.samples.samples_response import CustomerDto, SampleDTO, SamplesResponse
from cg.store.models import Sample


Expand All @@ -27,9 +27,13 @@ def create_samples_response(samples: list[Sample]) -> SamplesResponse:


def create_sample_dto(sample: Sample) -> SampleDTO:
customer = CustomerDto(
internal_id=sample.customer.internal_id,
name=sample.customer.name,
)
return SampleDTO(
comment=sample.comment,
customer=sample.customer.internal_id,
customer=customer,
internal_id=sample.internal_id,
name=sample.name,
phenotype_groups=sample.phenotype_groups,
Expand Down

0 comments on commit d8ffed2

Please sign in to comment.