Merge branch 'feature/tasks' of gitlab.prodcontest.ru:team-15/project into feature/tasks

This commit is contained in:
ITQ
2025-03-01 13:12:11 +03:00
60 changed files with 1128 additions and 119 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ MINIO_CUSTOM_ENDPOINT_URL=
MINIO_ACCESS_KEY=
MINIO_SECRET_KEY=
MINIO_USE_HTTPS=False
MINIO_MEDIA_BUCKET_NAME=projectname-media
MINIO_MEDIA_BUCKET_NAME=datarush-media
# Applyable if you installing using docker compose
+10 -10
View File
@@ -1,4 +1,4 @@
# project_name Backend
# DataRush Backend
## Prerequisites
@@ -15,13 +15,13 @@ Ensure you have the following installed on your system:
#### Clone the project
```bash
git clone project_name
git clone git@gitlab.prodcontest.ru:team-15/project.git
```
#### Go to the project directory
```bash
cd project_name/services/backend
cd project/services/backend
```
#### Customize environment
@@ -79,19 +79,19 @@ uv run gunicorn config.wsgi
### Clone the project
```bash
git clone project_name
git clone git@gitlab.prodcontest.ru:team-15/project.git
```
### Go to the project directory
```bash
cd project_name/services/backend
cd project/services/backend
```
### Build docker image
```bash
docker build -t project_name-backend .
docker build -t datarush-backend .
```
### Customize environment
@@ -103,13 +103,13 @@ Customize environment with `docker run` command (or bind .env file to container)
#### Backend
```bash
docker run -p 8080:8080 --name project_name-backend project_name-backend
docker run -p 8080:8080 --name datarush-backend datarush-backend
```
#### Celery worker
```bash
docker run --name project_name-celery-worker project_name-backend celery -A config worker -l INFO
docker run --name datarush-celery-worker datarush-backend celery -A config worker -l INFO
```
Backend will be available on [127.0.0.1:8080](http://127.0.0.1:8080).
@@ -119,13 +119,13 @@ Backend will be available on [127.0.0.1:8080](http://127.0.0.1:8080).
### Clone the project
```bash
git clone project_name
git clone git@gitlab.prodcontest.ru:team-15/project.git
```
### Go to the project directory
```bash
cd project_name/services/backend
cd project/services/backend
```
### Install dependencies
+2 -2
View File
@@ -4,7 +4,7 @@ from health_check.views import MainView
from api.v1.router import router as api_v1_router
urlpatterns = [
path("", api_v1_router.urls),
path("api/v1/", api_v1_router.urls),
# Health endpoint
path("health", MainView.as_view(), name="health_check_home"),
path("api/health", MainView.as_view(), name="health_check_home"),
]
@@ -11,7 +11,7 @@ class CompetitionOut(ModelSchema):
class Meta:
model = Competition
fields = "__all__"
exclude = ("participants",)
class StateOut(ModelSchema):
+3 -2
View File
@@ -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)
+2 -1
View File
@@ -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(
"",
+18 -4
View File
@@ -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(
+1 -1
View File
@@ -22,4 +22,4 @@ class LoginSchema(ModelSchema):
class UserSchema(ModelSchema):
class Meta:
model = User
fields = ["email", "username"]
fields = ["id", "email", "username"]
+10
View File
@@ -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={
@@ -0,0 +1,19 @@
# Generated by Django 5.1.6 on 2025-03-01 08:10
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('competition', '0003_state'),
]
operations = [
migrations.AddField(
model_name='state',
name='changed_at',
field=models.DateTimeField(default=datetime.datetime.now),
),
]
@@ -1,3 +1,5 @@
from datetime import datetime
from django.db import models
from apps.core.models import BaseModel
@@ -49,3 +51,4 @@ class State(BaseModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
state = models.CharField(choices=StateChoices.choices, max_length=11)
changed_at = models.DateTimeField(default=datetime.now)
+1 -1
View File
@@ -1,4 +1,4 @@
"""ASGI config for project_name."""
"""ASGI config for datarush."""
import os
+1 -1
View File
@@ -4,7 +4,7 @@ from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
app = Celery("project_name")
app = Celery("datarush")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
+3 -3
View File
@@ -1,4 +1,4 @@
"""Django settings for project_name."""
"""Django settings for datarush."""
import contextlib
import logging
@@ -141,7 +141,7 @@ MINIO_STORAGE_SECRET_KEY = env("MINIO_SECRET_KEY", default=None)
MINIO_STORAGE_USE_HTTPS = env("MINIO_USE_HTTPS", default=False)
MINIO_STORAGE_MEDIA_BUCKET_NAME = env(
"MINIO_MEDIA_BUCKET_NAME", default="projectname-media"
"MINIO_MEDIA_BUCKET_NAME", default="datarush-media"
)
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET = True
@@ -300,7 +300,7 @@ WSGI_APPLICATION = "config.wsgi.application"
# Logging
LOGGER_NAME = "project_name"
LOGGER_NAME = "datarush"
LOGGER = logging.getLogger(LOGGER_NAME)
+4 -4
View File
@@ -1,4 +1,4 @@
"""URL configuration for project_name."""
"""URL configuration for datarush."""
from django.conf import settings
from django.contrib import admin
@@ -6,9 +6,9 @@ from django.urls import include, path
from config import handlers
admin.site.site_title = "project_name"
admin.site.site_header = "project_name"
admin.site.index_title = "project_name"
admin.site.site_title = "DataRush"
admin.site.site_header = "DataRush"
admin.site.index_title = "DataRush"
urlpatterns = [
+1 -1
View File
@@ -1,4 +1,4 @@
"""WSGI config for project_name."""
"""WSGI config for datarush."""
import os
+1 -1
View File
@@ -1,5 +1,5 @@
[project]
name = "project_name-backend"
name = "datarush-backend"
version = "0.1.0"
readme = "README.md"
requires-python = ">=3.10,<3.12"