Skip to content

Commit

Permalink
feat(domain): add question entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Mala1180 committed Mar 18, 2024
1 parent dc8eba6 commit 9ef6f3f
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 4 deletions.
Empty file added app/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions app/domain/core/Question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import List

from app.domain.core.Answer import Answer
from app.domain.core.QuestionId import QuestionId
from app.domain.core.enum.Action import Action
from app.domain.core.enum.QuestionType import QuestionType


class Question:

def __init__(
self,
question_id: QuestionId,
text: str,
question_type: QuestionType,
available_answers: List[Answer],
selected_answer: List[Answer] = [],
action_needed: Action = None,
):
self._id = question_id
self._text = text
self._type = question_type
self._availableAnswers = available_answers
self._selectedAnswer = selected_answer
self._actionNeeded = action_needed
14 changes: 14 additions & 0 deletions app/domain/core/QuestionId.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class QuestionId:

def __init__(self, code: str):
self._code = code

@property
def code(self):
return self._code

def __eq__(self, other):
return self.code == other.code

def __str__(self):
return f"QuestionId(code={self.code})"
5 changes: 5 additions & 0 deletions app/domain/core/enum/Action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum


class Action(Enum):
METRICS_CHECK = 0
8 changes: 8 additions & 0 deletions app/domain/core/enum/QuestionType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class QuestionType(Enum):
BOOLEAN = 0
SINGLE_CHOICE = 1
MULTIPLE_CHOICE = 2
RATING = 3
Empty file.
48 changes: 48 additions & 0 deletions app/domain/factories/QuestionFactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import List

from app.domain.core.Answer import Answer
from app.domain.core.Question import Question
from app.domain.core.QuestionId import QuestionId
from app.domain.core.enum.Action import Action
from app.domain.core.enum.QuestionType import QuestionType
from app.domain.factories.AnswerFactory import AnswerFactory


class QuestionFactory:

def __init__(self):
self._answer_factory = AnswerFactory()

def create_question(
self,
question_id: QuestionId,
text: str,
question_type: QuestionType,
available_answers: List[Answer],
selected_answer: List[Answer],
action_needed: Action,
) -> Question:
return Question(
question_id,
text,
question_type,
available_answers,
selected_answer,
action_needed,
)

def create_boolean_question(
self, question_id: QuestionId, text: str, action_needed: Action = None
) -> Question:
available_answers: List[Answer] = [
self._answer_factory.create_boolean_answer(True),
self._answer_factory.create_boolean_answer(False),
]
return Question(
question_id,
text,
QuestionType.BOOLEAN,
available_answers,
[],
action_needed,
)
10 changes: 6 additions & 4 deletions test/unit/domain/test_TestQuestion.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest

from app.domain.core.Question import Question
from app.domain.factories.QuestionFactory import QuestionFactory


class TestQuestion(unittest.TestCase):

def setUp(self):
self.question = Question("What is your name?")



self.question = QuestionFactory().create_boolean_question(
"1", "Is this a test?"
)

0 comments on commit 9ef6f3f

Please sign in to comment.