mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 01:37:11 +00:00
<type>(scope): <description>
[body] [footer(s)]
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
from http import HTTPStatus as status
|
||||
|
||||
from ninja import Router
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.v1.schemas import NotFoundError, UnauthorizedError, ForbiddenError
|
||||
from api.v1.ping.schemas import PingOut
|
||||
from api.v1.task.schemas import TaskOutSchema
|
||||
from api.v1.task.schemas import (
|
||||
TaskOutSchema,
|
||||
TaskSubmissionOut,
|
||||
TaskSubmissionIn,
|
||||
)
|
||||
from apps.task.models import (
|
||||
Competition,
|
||||
CompetitionTask,
|
||||
CompetetionTaskSumbission,
|
||||
)
|
||||
|
||||
router = Router(tags=["competition"])
|
||||
|
||||
@@ -18,8 +28,7 @@ router = Router(tags=["competition"])
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
},
|
||||
)
|
||||
def start_competition(request, competition_id: str) -> PingOut:
|
||||
...
|
||||
def start_competition(request, competition_id: str) -> PingOut: ...
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -30,10 +39,11 @@ def start_competition(request, competition_id: str) -> PingOut:
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
},
|
||||
)
|
||||
def get_competition_tasks(request, competition_id: str) -> list[TaskOutSchema]:
|
||||
...
|
||||
def get_competition_tasks(
|
||||
request, competition_id: str
|
||||
) -> list[TaskOutSchema]: ...
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -44,21 +54,48 @@ def get_competition_tasks(request, competition_id: str) -> list[TaskOutSchema]:
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
},
|
||||
)
|
||||
def get_task(request, competition_id: str, task_id: str) -> TaskOutSchema:
|
||||
...
|
||||
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.OK: TaskSubmissionOut,
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
status.FORBIDDEN: ForbiddenError,
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
}
|
||||
},
|
||||
)
|
||||
def submit_task(request, competition_id: str, task_id: str) -> PingOut:
|
||||
...
|
||||
def submit_task(
|
||||
request, competition_id: str, task_id: str, submission: TaskSubmissionIn
|
||||
) -> PingOut:
|
||||
user = request.auth
|
||||
competetion = get_object_or_404(Competition, id=competition_id)
|
||||
task = get_object_or_404(
|
||||
CompetitionTask, competetion=competetion, id=task_id
|
||||
)
|
||||
|
||||
if task.type == CompetitionTask.CompetitionTaskType.INPUT:
|
||||
CompetetionTaskSumbission.objects.create(
|
||||
user=user,
|
||||
task=task,
|
||||
status=CompetetionTaskSumbission.StatusChoices.CHECKED,
|
||||
result={"correct": submission.content == task.answer_file_path},
|
||||
)
|
||||
if task.type == CompetitionTask.CompetitionTaskType.REVIEW:
|
||||
CompetetionTaskSumbission.objects.create(
|
||||
user=user,
|
||||
task=task,
|
||||
status=CompetetionTaskSumbission.StatusChoices.SENT,
|
||||
)
|
||||
if task.type == CompetitionTask.CompetitionTaskType.CHECKER:
|
||||
CompetetionTaskSumbission.objects.create(
|
||||
user=user,
|
||||
task=task,
|
||||
status=CompetetionTaskSumbission.StatusChoices.CHECKING,
|
||||
)
|
||||
|
||||
return TaskSubmissionOut(id=CompetetionTaskSumbission.id)
|
||||
|
||||
Reference in New Issue
Block a user