mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 05:07:10 +00:00
lint: linted
This commit is contained in:
@@ -13,16 +13,17 @@ class CompetitionOut(ModelSchema):
|
||||
model = Competition
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class StateOut(ModelSchema):
|
||||
class Meta:
|
||||
model = State
|
||||
fields = (
|
||||
"state",
|
||||
)
|
||||
fields = ("state",)
|
||||
|
||||
|
||||
class StateIn(Schema):
|
||||
state: Literal["started", "not_started", "finished"]
|
||||
|
||||
|
||||
class CompetitionListInstanceOut(ModelSchema):
|
||||
id: UUID
|
||||
is_participating: bool
|
||||
@@ -36,7 +37,9 @@ class CompetitionListInstanceOut(ModelSchema):
|
||||
@staticmethod
|
||||
def resolve_completed(self, context):
|
||||
user = context["request"].auth
|
||||
return State.objects.filter(competition=self, user=user, state="finished").exists()
|
||||
return State.objects.filter(
|
||||
competition=self, user=user, state="finished"
|
||||
).exists()
|
||||
|
||||
class Meta:
|
||||
model = Competition
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from http import HTTPStatus as status
|
||||
from typing import Literal
|
||||
from uuid import UUID
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.http import HttpRequest, Http404
|
||||
from ninja import Router
|
||||
|
||||
import api.v1.schemas as global_schemas
|
||||
from api.v1.auth import BearerAuth
|
||||
from api.v1.competition import schemas
|
||||
from apps.competition.models import Competition, State
|
||||
|
||||
@@ -46,13 +45,14 @@ def list_competitions(
|
||||
competitions = Competition.objects.exclude(participants=user)
|
||||
return status.OK, competitions
|
||||
|
||||
|
||||
@router.post(
|
||||
"competitions/{competition_id}/state",
|
||||
response={
|
||||
status.OK: schemas.StateOut,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
}
|
||||
},
|
||||
)
|
||||
def change_competition_state(
|
||||
request: HttpRequest,
|
||||
@@ -63,8 +63,6 @@ def change_competition_state(
|
||||
competition = get_object_or_404(Competition, id=competition_id)
|
||||
|
||||
state_obj, _ = State.objects.update_or_create(
|
||||
user=user,
|
||||
competition=competition,
|
||||
state=state.state
|
||||
user=user, competition=competition, state=state.state
|
||||
)
|
||||
return status.OK, schemas.StateOut.from_orm(state_obj)
|
||||
|
||||
@@ -13,7 +13,7 @@ router = NinjaAPI(
|
||||
version="1",
|
||||
description="API docs for DataRush",
|
||||
openapi_url="/docs/openapi.json",
|
||||
auth=BearerAuth()
|
||||
auth=BearerAuth(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,14 @@ from http import HTTPStatus as status
|
||||
from ninja import Router
|
||||
from ninja.errors import AuthenticationError
|
||||
|
||||
from api.v1.user.schemas import LoginSchema, RegisterSchema, TokenSchema, UserSchema
|
||||
from api.v1.auth import BearerAuth
|
||||
from api.v1.schemas import BadRequestError, ForbiddenError, NotFoundError
|
||||
from api.v1.user.schemas import (
|
||||
LoginSchema,
|
||||
RegisterSchema,
|
||||
TokenSchema,
|
||||
UserSchema,
|
||||
)
|
||||
from apps.user.models import User
|
||||
|
||||
router = Router(tags=["user"])
|
||||
@@ -56,5 +61,4 @@ def sign_in(request, data: LoginSchema):
|
||||
status.NOT_FOUND: NotFoundError,
|
||||
},
|
||||
)
|
||||
def get_user(request, user_id: str):
|
||||
...
|
||||
def get_user(request, user_id: str): ...
|
||||
|
||||
Reference in New Issue
Block a user