Skip to content

Commit

Permalink
feat: #52 created schemas for newest models
Browse files Browse the repository at this point in the history
- updated the schemas in order to meet the new architecture

- cleaned the dependencies at `requirements.txt`

- include code coverage for actions
  • Loading branch information
miguelcsx committed Sep 2, 2024
1 parent 8844f54 commit d229973
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 116 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pr-conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
uses: ytanikin/[email protected]
uses: ytanikin/[email protected]
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
task_types: '["feat","fix","docs","test","ci","refac",
"perf","chore","revert"]'
add_label: 'false'
26 changes: 19 additions & 7 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
Expand All @@ -19,25 +16,40 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest black
pip install flake8 pytest black coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
-name: Format with black
- name: Format with black
run: |
black .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
- name: Run tests with coverage
run: |
coverage run -m pytest
- name: Generate coverage report
run: |
pytest
coverage report
coverage html
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: htmlcov/
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ repos:
language: system
pass_filenames: false

- id: format-yaml
name: Format YAML Files
entry: yamlfmt
language: python
types: [yaml]
files: \.(yml|yaml)$
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ indent-string = ' '
indent-after-paren = 4

# Maximum number of characters on a single line.
max-line-length = 120
max-line-length = 80
msg-template = "{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
output-format = colorized

Expand Down
42 changes: 42 additions & 0 deletions app/schemas/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# app/schemas/activity.py

from typing import Optional
from enum import Enum
from datetime import datetime
from pydantic import BaseModel
from app.database.models import Question


class ActivityType(str, Enum):
question = "question"


class ActivityBase(BaseModel):
type: ActivityType
activity: str
created_at: datetime


class ActivityCreate(ActivityBase):
pass


class ActivityUpdate(ActivityBase):
pass


class ActivityInDBBase(ActivityBase):
id: int
user_id: int
study_session_id: int

class Config:
orm_mode = True


class Activity(ActivityInDBBase):
question: Optional["Question"] = None


class ActivityInDB(ActivityInDBBase):
pass
37 changes: 37 additions & 0 deletions app/schemas/answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# app/schemas/answer.py

from typing import (
Optional,
List,
)
from pydantic import BaseModel


class AnswerBase(BaseModel):
answer: str


class AnswerCreate(AnswerBase):
pass


class AnswerUpdate(AnswerBase):
pass


class AnswerInDBBase(AnswerBase):
id: int
user_id: int
question_id: int

class Config:
orm_mode = True


class Answer(AnswerInDBBase):
parent_answer: Optional["Answer"] = None
child_answers: Optional[List["Answer"]] = []


class AnswerInDB(AnswerInDBBase):
pass
35 changes: 35 additions & 0 deletions app/schemas/question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import (
Optional,
List,
)
from pydantic import BaseModel
from app.database.models import Answer


class QuestionBase(BaseModel):
question: str


class QuestionCreate(QuestionBase):
pass


class QuestionUpdate(QuestionBase):
pass


class QuestionInDBBase(QuestionBase):
id: int
user_id: int
activity_id: int

class Config:
orm_mode = True


class Question(QuestionInDBBase):
answers: Optional[List["Answer"]] = []


class QuestionInDB(QuestionInDBBase):
pass
38 changes: 38 additions & 0 deletions app/schemas/study_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# app/schemas/study_session.py

from typing import (
List,
Optional,
)
from datetime import datetime
from pydantic import BaseModel
from app.database.models import Activity


class StudySessionBase(BaseModel):
start_time: datetime
end_time: Optional[datetime] = None


class StudySessionCreate(StudySessionBase):
pass


class StudySessionUpdate(StudySessionBase):
pass


class StudySessionInDBBase(StudySessionBase):
id: int
user_id: int

class Config:
orm_mode = True


class StudySession(StudySessionInDBBase):
activities: Optional[List["Activity"]] = []


class StudySessionInDB(StudySessionInDBBase):
pass
15 changes: 15 additions & 0 deletions app/schemas/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# app/schemas/user.py

from typing import (
List,
Optional,
)
from datetime import datetime
from pydantic import BaseModel
from app.database.models import Activity, Answer, Question, StudySession


class UserBase(BaseModel):
Expand All @@ -19,6 +25,15 @@ class UserUpdate(UserBase):

class UserInDBBase(UserBase):
id: int
created_at: datetime
updated_at: datetime

class Config:
orm_mode = True


class User(UserInDBBase):
study_sessions: Optional[List["StudySession"]] = []
activities: Optional[List["Activity"]] = []
questions: Optional[List["Question"]] = []
answers: Optional[List["Answer"]] = []
Loading

0 comments on commit d229973

Please sign in to comment.