Skip to content

Commit

Permalink
Исправляет и дополняет схемы для взаимодействия с уровнями
Browse files Browse the repository at this point in the history
  • Loading branch information
codEnjoyer committed Nov 18, 2023
1 parent 955a0dc commit 8b7858d
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 69 deletions.
13 changes: 9 additions & 4 deletions backend/src/game/levels/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

class __LevelBase(BaseModel):
module_id: UUID
name: str
title: str
theory_units_id: list[UUID] | None
task_units_id: list[UUID] | None

model_config = ConfigDict(from_attributes=True)


class LevelRead(__LevelBase):
id: UUID
is_accomplished: bool
theory_units_id: list[UUID]
task_units_id: list[UUID]


class LevelCreate(__LevelBase):
pass


class LevelUpdate(__LevelBase):
module_id: UUID | None
name: str | None
module_id: UUID | None = None
title: str | None = None
theory_units_id: list[UUID] | None = None
task_units_id: list[UUID] | None = None
8 changes: 6 additions & 2 deletions backend/src/game/map/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

from pydantic import BaseModel, ConfigDict

from game.modules.schemas import ModuleRead


class __MapBase(BaseModel):
name: str
title: str

model_config = ConfigDict(from_attributes=True)


class MapRead(__MapBase):
id: UUID
modules: list[ModuleRead]



class MapCreate(__MapBase):
pass


class MapUpdate(__MapBase):
name: str | None
title: str | None
14 changes: 8 additions & 6 deletions backend/src/game/modules/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@


class __ModuleBase(BaseModel):
previous_module_id: UUID
next_module_id: UUID
name: str
map_id: UUID
title: str
previous_module_id: UUID | None
next_module_id: UUID | None

model_config = ConfigDict(from_attributes=True)


class ModuleRead(__ModuleBase):
id: UUID
levels_id: list[UUID]


class ModuleCreate(__ModuleBase):
pass


class ModuleUpdate(__ModuleBase):
previous_module_id: UUID | None
next_module_id: UUID | None
name: str | None
title: str | None = None
previous_module_id: UUID | None = None
next_module_id: UUID | None = None
41 changes: 38 additions & 3 deletions backend/src/game/units/tasks/questions/schemas.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
import uuid
from uuid import UUID

from pydantic import BaseModel, ConfigDict

from game.units.tasks.questions.models import QuestionTypes


# region Question
class __QuestionBase(BaseModel):
task_id: UUID
type: QuestionTypes
question: str
possible_answers: list[str]

model_config = ConfigDict(from_attributes=True)

# TODO QuestionRead, QuestionCreate, QuestionUpdate

class QuestionRead(__QuestionBase):
id: UUID
possible_answers: list["AnswerRead"]


class QuestionCreate(__QuestionBase):
correct_answer: "AnswerCreate"
possible_answers: list["AnswerCreate"]


class QuestionUpdate(__QuestionBase):
type: QuestionTypes | None = None
question: str | None = None
possible_answers: list["AnswerUpdate"] | None = None


# endregion Question

# region Answer
class __AnswerBase(BaseModel):
content: str


class AnswerRead(__AnswerBase):
question_id: UUID


class AnswerCreate(__AnswerBase):
pass


class AnswerUpdate(__AnswerBase):
content: str | None = None
question_id: UUID | None = None
# endregion Answer
20 changes: 10 additions & 10 deletions backend/src/game/units/tasks/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

from fastapi import APIRouter

from game.units.tasks.schemas import TaskRead, TaskCreate, TaskUpdate
from game.units.tasks.schemas import TaskUnitRead, TaskUnitCreate, TaskUnitUpdate

router = APIRouter(prefix="/tasks", tags=["Task"])


@router.get("/")
async def root() -> list[TaskRead]:
async def root() -> list[TaskUnitRead]:
return []


@router.get("/{id}")
async def get_task(id: UUID) -> TaskRead:
return TaskRead()
async def get_task(id: UUID) -> TaskUnitRead:
return TaskUnitRead()


@router.post("/")
async def post_task(task_create: TaskCreate) -> TaskRead:
return TaskRead()
async def post_task(task_create: TaskUnitCreate) -> TaskUnitRead:
return TaskUnitRead()


@router.delete("/{id}")
async def delete_task(id: UUID) -> TaskRead:
return TaskRead()
async def delete_task(id: UUID) -> TaskUnitRead:
return TaskUnitRead()


@router.patch("/{id}")
async def update_task(id: UUID,
task_update: TaskUpdate) -> TaskRead:
return TaskRead()
task_update: TaskUnitUpdate) -> TaskUnitRead:
return TaskUnitRead()
25 changes: 16 additions & 9 deletions backend/src/game/units/tasks/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@

from pydantic import BaseModel, ConfigDict

from game.units.tasks.models import TaskTypes
from game.units.tasks.questions.schemas import QuestionRead, QuestionCreate, QuestionUpdate

class __TaskBase(BaseModel):
content: str

class __TaskUnitBase(BaseModel):
questions: list[QuestionRead]
type: TaskTypes
score_reward: int
requires_review: bool

model_config = ConfigDict(from_attributes=True)


class TaskRead(__TaskBase):
class TaskUnitRead(__TaskUnitBase):
id: UUID
is_accomplished: bool


class TaskCreate(__TaskBase):
pass
class TaskUnitCreate(__TaskUnitBase):
questions: list[QuestionCreate]


class TaskUnitUpdate(__TaskUnitBase):
questions: list[QuestionUpdate] | None = None
type: TaskTypes | None = None
score_reward: int | None = None
requires_review: bool | None = None

class TaskUpdate(__TaskBase):
content: str | None
score_reward: int | None
20 changes: 10 additions & 10 deletions backend/src/game/units/theory/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

from fastapi import APIRouter

from game.units.theory.schemas import (TheoryRead, TheoryCreate, TheoryUpdate,
from game.units.theory.schemas import (TheoryUnitRead, TheoryUnitCreate, TheoryUnitUpdate,
TheoryVideoRead, TheoryVideoCreate, TheoryVideoUpdate)

router = APIRouter(prefix="/theory", tags=["Theory"])


@router.get("/")
async def root() -> list[TheoryRead]:
async def root() -> list[TheoryUnitRead]:
return []


@router.get("/{id}")
async def get_theory_block(id: UUID) -> TheoryRead:
return TheoryRead()
async def get_theory_block(id: UUID) -> TheoryUnitRead:
return TheoryUnitRead()


@router.get("/videos/{id}")
Expand All @@ -24,8 +24,8 @@ async def get_theory_block_videos(id: UUID) -> list[TheoryVideoRead]:


@router.post("/")
async def post_theory_block(theory_create: TheoryCreate) -> TheoryRead:
return TheoryRead()
async def post_theory_block(theory_create: TheoryUnitCreate) -> TheoryUnitRead:
return TheoryUnitRead()


@router.post("/videos/")
Expand All @@ -34,8 +34,8 @@ async def post_theory_block_video(theory_video_create: TheoryVideoCreate) -> The


@router.delete("/{id}")
async def delete_theory_block(id: UUID) -> TheoryRead:
return TheoryRead()
async def delete_theory_block(id: UUID) -> TheoryUnitRead:
return TheoryUnitRead()


@router.delete("/videos/{id}")
Expand All @@ -45,8 +45,8 @@ async def delete_theory_block_video(id: UUID) -> TheoryVideoRead:

@router.patch("/{id}")
async def update_theory_block(id: UUID,
theory_update: TheoryUpdate) -> TheoryRead:
return TheoryRead()
theory_update: TheoryUnitUpdate) -> TheoryUnitRead:
return TheoryUnitRead()


@router.patch("/videos/{id}")
Expand Down
50 changes: 25 additions & 25 deletions backend/src/game/units/theory/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@


# region Theory
class __TheoryBase(BaseModel):
theme: str
class __TheoryUnitBase(BaseModel):
title: str
content: str

model_config = ConfigDict(from_attributes=True)


class TheoryRead(__TheoryBase):
class TheoryUnitRead(__TheoryUnitBase):
id: UUID


class TheoryCreate(__TheoryBase):
class TheoryUnitCreate(__TheoryUnitBase):
pass


class TheoryUpdate(__TheoryBase):
theme: str | None
content: str | None
class TheoryUnitUpdate(__TheoryUnitBase):
title: str | None = None
content: str | None = None


# endregion

class __TheoryVideoBase(BaseModel):
theory_id: UUID
url: Url

model_config = ConfigDict(from_attributes=True)


class TheoryVideoRead(__TheoryVideoBase):
id: UUID


class TheoryVideoCreate(__TheoryVideoBase):
pass


class TheoryVideoUpdate(__TheoryVideoBase):
theory_id: UUID | None
url: Url | None
# class __TheoryVideoBase(BaseModel):
# theory_id: UUID
# url: Url
#
# model_config = ConfigDict(from_attributes=True)
#
#
# class TheoryVideoRead(__TheoryVideoBase):
# id: UUID
#
#
# class TheoryVideoCreate(__TheoryVideoBase):
# pass
#
#
# class TheoryVideoUpdate(__TheoryVideoBase):
# theory_id: UUID | None
# url: Url | None

0 comments on commit 8b7858d

Please sign in to comment.