Skip to content

Commit

Permalink
✨ Add domain
Browse files Browse the repository at this point in the history
  • Loading branch information
BeaverNotACat committed Jul 22, 2024
1 parent abb1449 commit 7bdac6a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
Empty file added app/__init__.py
Empty file.
Empty file added app/adapters/__init__.py
Empty file.
Empty file added app/application/__init__.py
Empty file.
Empty file added app/domain/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions app/domain/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from dataclasses import dataclass
from typing import NewType
from uuid import UUID


ParameterId = NewType("ParameterId", UUID)
FormId = NewType("FormId", UUID)
FormPopulationId = NewType("FormPopulationId", UUID)
UserId = NewType("UserId", str)


@dataclass
class _BaseParameter:
field: str
answer: str

@dataclass
class UnidentificatedParameter(_BaseParameter):
...

@dataclass
class IdentificatedParameter(_BaseParameter):
id: ParameterId

type Parameter = UnidentificatedParameter | IdentificatedParameter


@dataclass
class _BaseFormPopulation:
user_id: UserId
form_id: FormId
parameters: list[Parameter]

@dataclass
class UnidentificatedFormPopulation(_BaseFormPopulation):
...

@dataclass
class IdentificatedFormPopulation(_BaseFormPopulation):
id: FormPopulationId

type FormPopulation = UnidentificatedFormPopulation | IdentificatedFormPopulation
47 changes: 47 additions & 0 deletions app/domain/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import typing

from .models import (
FormPopulation,
UnidentificatedFormPopulation,
Parameter,
UnidentificatedParameter,
UserId,
FormId,
)


_sentinel: typing.Any = object()


class FormPopulationService:
@staticmethod
def create(
user_id: UserId, form_id: FormId, parameters: list[Parameter] = []
) -> FormPopulation:
return UnidentificatedFormPopulation(
user_id=user_id,
form_id=form_id,
parameters=parameters,
)

@staticmethod
def add_parameter(form_population: FormPopulation, parameter: Parameter) -> None:
form_population.parameters.append(parameter)


class ParameterService:
@staticmethod
def create(field: str, answer: str) -> Parameter:
return UnidentificatedParameter(field=field, answer=answer)

@staticmethod
def update(
parameter: Parameter,
new_field: str = _sentinel,
new_answer: str = _sentinel,
) -> None:
if new_field is not _sentinel:
parameter.field = new_field

if new_answer is not _sentinel:
parameter.answer = new_answer

0 comments on commit 7bdac6a

Please sign in to comment.