mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 17:57:10 +00:00
Merge branch 'feature/tasks' of gitlab.prodcontest.ru:team-15/project into feature/tasks
This commit is contained in:
@@ -11,7 +11,7 @@ class CompetitionOut(ModelSchema):
|
||||
|
||||
class Meta:
|
||||
model = Competition
|
||||
fields = "__all__"
|
||||
exclude = ("participants",)
|
||||
|
||||
|
||||
class StateOut(ModelSchema):
|
||||
|
||||
@@ -18,6 +18,7 @@ router = Router(tags=["competition"])
|
||||
status.OK: schemas.CompetitionOut,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
status.NOT_FOUND: global_schemas.NotFoundError,
|
||||
},
|
||||
)
|
||||
def get_competition(
|
||||
@@ -30,14 +31,14 @@ def get_competition(
|
||||
@router.get(
|
||||
"competitions",
|
||||
response={
|
||||
status.OK: list[schemas.CompetitionListInstanceOut],
|
||||
status.OK: list[schemas.CompetitionOut],
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
},
|
||||
)
|
||||
def list_competitions(
|
||||
request: HttpRequest, is_participating: bool
|
||||
) -> tuple[status, list[schemas.CompetitionListInstanceOut]]:
|
||||
) -> tuple[status, list[schemas.CompetitionOut]]:
|
||||
user = request.auth
|
||||
if is_participating:
|
||||
competitions = Competition.objects.filter(participants=user)
|
||||
|
||||
@@ -14,7 +14,6 @@ router = NinjaAPI(
|
||||
version="1",
|
||||
description="API docs for DataRush",
|
||||
openapi_url="/docs/openapi.json",
|
||||
auth=BearerAuth(),
|
||||
)
|
||||
|
||||
|
||||
@@ -25,10 +24,12 @@ router.add_router(
|
||||
router.add_router(
|
||||
"",
|
||||
user_router,
|
||||
auth=BearerAuth(),
|
||||
)
|
||||
router.add_router(
|
||||
"",
|
||||
competition_router,
|
||||
auth=BearerAuth(),
|
||||
)
|
||||
router.add_router(
|
||||
"",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from http import HTTPStatus as status
|
||||
from uuid import UUID
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from ninja import Router
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
@@ -15,6 +17,7 @@ from apps.task.models import (
|
||||
CompetitionTask,
|
||||
CompetetionTaskSumbission,
|
||||
)
|
||||
from apps.competition.models import State
|
||||
|
||||
router = Router(tags=["competition"])
|
||||
|
||||
@@ -28,7 +31,12 @@ router = Router(tags=["competition"])
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
},
|
||||
)
|
||||
def start_competition(request, competition_id: str) -> PingOut: ...
|
||||
def start_competition(request, competition_id: UUID) -> PingOut:
|
||||
competition = get_object_or_404(Competition, pk=competition_id)
|
||||
state_obj, _ = State.objects.update_or_create(
|
||||
user=request.auth, competition=competition, state="started"
|
||||
)
|
||||
return status.OK, PingOut()
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -41,9 +49,15 @@ def start_competition(request, competition_id: str) -> PingOut: ...
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
},
|
||||
)
|
||||
def get_competition_tasks(
|
||||
request, competition_id: str
|
||||
) -> list[TaskOutSchema]: ...
|
||||
def get_competition_tasks(request, competition_id: UUID) -> list[TaskOutSchema]:
|
||||
competition = get_object_or_404(Competition, pk=competition_id)
|
||||
state = State.objects.filter(
|
||||
user=request.auth, competition=competition, state="started"
|
||||
).first()
|
||||
if not state:
|
||||
return 403, ForbiddenError()
|
||||
|
||||
return status.OK, CompetitionTask.objects.filter(competition=competition).all()
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
@@ -22,4 +22,4 @@ class LoginSchema(ModelSchema):
|
||||
class UserSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["email", "username"]
|
||||
fields = ["id", "email", "username"]
|
||||
|
||||
@@ -54,6 +54,16 @@ def sign_in(request, data: LoginSchema):
|
||||
return status.OK, TokenSchema(token=token)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/me",
|
||||
response={
|
||||
status.OK: UserSchema,
|
||||
status.UNAUTHORIZED: ForbiddenError,
|
||||
},
|
||||
)
|
||||
def get_me(request):
|
||||
return 200, request.auth
|
||||
|
||||
@router.get(
|
||||
path="/user/{user_id}",
|
||||
response={
|
||||
|
||||
Reference in New Issue
Block a user