mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 05:07:10 +00:00
feat: added achievements
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from ninja import ModelSchema, Schema
|
||||
|
||||
from api.v1.achievement.schemas import UserAchievementSchema
|
||||
from apps.achievement.models import UserAchievement
|
||||
from apps.user.models import User
|
||||
|
||||
|
||||
@@ -20,9 +22,17 @@ class LoginSchema(ModelSchema):
|
||||
|
||||
|
||||
class UserSchema(ModelSchema):
|
||||
achievements: list[UserAchievementSchema] = None
|
||||
|
||||
@staticmethod
|
||||
def resolve_achievements(self, context):
|
||||
return UserAchievement.objects.filter(
|
||||
user=context.get("request").auth
|
||||
).order_by("-received_at")
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["id", "email", "username", "created_at", "achievements"]
|
||||
fields = ["id", "email", "username", "created_at"]
|
||||
|
||||
|
||||
class StatSchema(Schema):
|
||||
|
||||
@@ -11,17 +11,18 @@ from api.v1.schemas import (
|
||||
BadRequestError,
|
||||
ConflictError,
|
||||
ForbiddenError,
|
||||
NotFoundError, UnauthorizedError,
|
||||
NotFoundError,
|
||||
UnauthorizedError,
|
||||
)
|
||||
from api.v1.user.schemas import (
|
||||
LoginSchema,
|
||||
RegisterSchema,
|
||||
StatSchema,
|
||||
TokenSchema,
|
||||
UserSchema,
|
||||
StatSchema
|
||||
)
|
||||
from apps.task.models import CompetitionTaskSubmission
|
||||
from apps.user.models import User
|
||||
from apps.task.models import CompetitionTaskSubmission, ReviewStatusChoices
|
||||
|
||||
router = Router(tags=["user"])
|
||||
|
||||
@@ -91,16 +92,15 @@ def get_user(request, user_id: str):
|
||||
|
||||
@router.get(
|
||||
"/me/stat",
|
||||
response={
|
||||
status.OK: StatSchema,
|
||||
status.UNAUTHORIZED: UnauthorizedError
|
||||
},
|
||||
response={status.OK: StatSchema, status.UNAUTHORIZED: UnauthorizedError},
|
||||
)
|
||||
def get_my_stat(request):
|
||||
user_submissions = CompetitionTaskSubmission.objects.filter(
|
||||
user=request.auth
|
||||
)
|
||||
checked_attempts = user_submissions.filter(status=CompetitionTaskSubmission.StatusChoices.CHECKED).all()
|
||||
checked_attempts = user_submissions.filter(
|
||||
status=CompetitionTaskSubmission.StatusChoices.CHECKED
|
||||
).all()
|
||||
success_attempts_cnt = 0
|
||||
|
||||
for attempt in checked_attempts:
|
||||
@@ -112,6 +112,5 @@ def get_my_stat(request):
|
||||
success_attempts_cnt += 1
|
||||
|
||||
return StatSchema(
|
||||
total_attempts=len(user_submissions),
|
||||
solved_tasks=success_attempts_cnt
|
||||
total_attempts=len(user_submissions), solved_tasks=success_attempts_cnt
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user