mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 02:47:10 +00:00
add basic openapi scheme for competitions tasks
This commit is contained in:
@@ -6,6 +6,7 @@ from api.v1 import handlers
|
||||
from api.v1.auth import BearerAuth
|
||||
from api.v1.competition.views import router as competition_router
|
||||
from api.v1.ping.views import router as ping_router
|
||||
from api.v1.task.views import router as task_router
|
||||
from api.v1.user.views import router as user_router
|
||||
|
||||
router = NinjaAPI(
|
||||
@@ -29,6 +30,10 @@ router.add_router(
|
||||
"",
|
||||
competition_router,
|
||||
)
|
||||
router.add_router(
|
||||
"",
|
||||
task_router,
|
||||
)
|
||||
|
||||
|
||||
for exception, handler in handlers.exception_handlers:
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
from ninja import ModelSchema, Schema
|
||||
|
||||
from apps.competition.models import State
|
||||
from apps.task.models import CompetitionTask
|
||||
|
||||
|
||||
class TaskOutSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = CompetitionTask
|
||||
fields = ["id", "competition", "title", "description", "type"]
|
||||
@@ -0,0 +1,64 @@
|
||||
from http import HTTPStatus as status
|
||||
|
||||
from ninja import Router
|
||||
|
||||
from api.v1.schemas import NotFoundError, UnauthorizedError, ForbiddenError
|
||||
from api.v1.ping.schemas import PingOut
|
||||
from api.v1.task.schemas import TaskOutSchema
|
||||
|
||||
router = Router(tags=["competition"])
|
||||
|
||||
|
||||
@router.post(
|
||||
"competitions/{competition_id}/start",
|
||||
description="Start a competition completing (open access to tasks)",
|
||||
response={
|
||||
status.OK: PingOut,
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
},
|
||||
)
|
||||
def start_competition(request, competition_id: str) -> PingOut:
|
||||
...
|
||||
|
||||
|
||||
@router.get(
|
||||
"competitions/{competition_id}/tasks",
|
||||
description="Get all tasks of competition (works only if user started competition)",
|
||||
response={
|
||||
status.OK: list[TaskOutSchema],
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
)
|
||||
def get_competition_tasks(request, competition_id: str) -> list[TaskOutSchema]:
|
||||
...
|
||||
|
||||
|
||||
@router.get(
|
||||
"competitions/{competition_id}/tasks/{task_id}",
|
||||
description="Get a task of competition task",
|
||||
response={
|
||||
status.OK: TaskOutSchema,
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
)
|
||||
def get_task(request, competition_id: str, task_id: str) -> TaskOutSchema:
|
||||
...
|
||||
|
||||
|
||||
@router.post(
|
||||
"competitions/{competition_id}/tasks/{task_id}/submit",
|
||||
description="Submit task solution",
|
||||
response={
|
||||
status.OK: PingOut, # todo maybe I should write an other schema for this
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
)
|
||||
def submit_task(request, competition_id: str, task_id: str) -> PingOut:
|
||||
...
|
||||
Reference in New Issue
Block a user