diff --git a/app/domain/__init__.py b/app/domain/__init__.py index b73080e7..908fbe13 100644 --- a/app/domain/__init__.py +++ b/app/domain/__init__.py @@ -1 +1,5 @@ from domain.message import IrisMessage, IrisMessageRole +from domain.course import Course +from domain.exercise import ProgrammingExercise +from domain.submission import ProgrammingSubmission +from domain.codehint import CodeHint diff --git a/app/domain/codehint.py b/app/domain/codehint.py new file mode 100644 index 00000000..45a16d8a --- /dev/null +++ b/app/domain/codehint.py @@ -0,0 +1,28 @@ +from pydantic import BaseModel + + +class ProgrammingExerciseSolutionEntry(BaseModel): + file_path: str + previous_line: int + line: int + previous_code: str + code: str + + def __str__(self): + return ( + f'ProgrammingExerciseSolutionEntry(file_path="{self.file_path}", previous_line={self.previous_line}, ' + f'line={self.line}, previous_code="{self.previous_code}", code="{self.code}")' + ) + + +class CodeHint(BaseModel): + title: str + description: str + content: str + solution_entries: [ProgrammingExerciseSolutionEntry] + + def __str__(self): + return ( + f'CodeHint(title="{self.title}", description="{self.description}", content="{self.content}", ' + f"solution_entries={self.solution_entries})" + ) diff --git a/app/domain/course.py b/app/domain/course.py new file mode 100644 index 00000000..c88511dc --- /dev/null +++ b/app/domain/course.py @@ -0,0 +1,9 @@ +from pydantic import BaseModel + + +class Course(BaseModel): + title: str + description: str + + def __str__(self): + return f'Course(title="{self.title}", description="{self.description}")' diff --git a/app/domain/dtos.py b/app/domain/dtos.py new file mode 100644 index 00000000..eb723f8f --- /dev/null +++ b/app/domain/dtos.py @@ -0,0 +1,60 @@ +from pydantic import BaseModel + +from domain import ( + Course, + ProgrammingExercise, + IrisMessage, + ProgrammingSubmission, + CodeHint, +) + + +class ProgrammingExerciseTutorChatDTO(BaseModel): + course: Course + exercise: ProgrammingExercise + submission: ProgrammingSubmission + chat_history: [IrisMessage] + + def __str__(self): + return ( + f"ProgrammingExerciseTutorChatDTO(course={self.course}, exercise={self.exercise}, " + f"submission={self.submission}, chat_history={self.chat_history})" + ) + + +class CodeEditorChatDTO(BaseModel): + problem_statement: str + solution_repository: dict[str, str] + template_repository: dict[str, str] + test_repository: dict[str, str] + chat_history: [IrisMessage] + + def __str__(self): + return ( + f'CodeEditorChatDTO(problem_statement="{self.problem_statement}", ' + f"solution_repository={self.solution_repository}, template_repository={self.template_repository}, " + f"test_repository={self.test_repository}, chat_history={self.chat_history})" + ) + + +class CodeEditorAdaptDTO(BaseModel): + problem_statement: str + solution_repository: dict[str, str] + template_repository: dict[str, str] + test_repository: dict[str, str] + instructions: str + + def __str__(self): + return ( + f'CodeEditorAdaptDTO(problem_statement="{self.problem_statement}", ' + f"solution_repository={self.solution_repository}, template_repository={self.template_repository}, " + f'test_repository={self.test_repository}, instructions="{self.instructions}")' + ) + + +class HestiaDTO(BaseModel): + code_hint: CodeHint + exercise: ProgrammingExercise + + def __str__(self): + return f"HestiaDTO(code_hint={self.code_hint}, exercise={self.exercise})" diff --git a/app/domain/exercise.py b/app/domain/exercise.py new file mode 100644 index 00000000..be195e2c --- /dev/null +++ b/app/domain/exercise.py @@ -0,0 +1,9 @@ +from pydantic import BaseModel + + +class ProgrammingExercise(BaseModel): + title: str + problem_statement: str + + def __str__(self): + return f'ProgrammingExercise(title="{self.title}", problem_statement="{self.problem_statement}")' diff --git a/app/domain/message.py b/app/domain/message.py index b1f521cc..9867138e 100644 --- a/app/domain/message.py +++ b/app/domain/message.py @@ -1,5 +1,7 @@ from enum import Enum +from pydantic import BaseModel + class IrisMessageRole(Enum): USER = "user" @@ -7,13 +9,12 @@ class IrisMessageRole(Enum): SYSTEM = "system" -class IrisMessage: +class IrisMessage(BaseModel): role: IrisMessageRole text: str def __init__(self, role: IrisMessageRole, text: str): - self.role = role - self.text = text + super().__init__(role=role, text=text) def __str__(self): return f"IrisMessage(role={self.role.value}, text='{self.text}')" diff --git a/app/domain/submission.py b/app/domain/submission.py new file mode 100644 index 00000000..e64b8a4b --- /dev/null +++ b/app/domain/submission.py @@ -0,0 +1,21 @@ +from pydantic import BaseModel + + +class BuildLogEntry(BaseModel): + time: str + message: str + + def __str__(self): + return f'BuildLogEntry(time="{self.time}", message="{self.message}")' + + +class ProgrammingSubmission(BaseModel): + commit_hash: str + build_failed: bool + build_log_entries: [BuildLogEntry] + + def __str__(self): + return ( + f'ProgrammingSubmission(commit_hash="{self.commit_hash}", build_failed={self.build_failed}, ' + f"build_log_entries={self.build_log_entries})" + )