fix(submissions): fix upload + bucket path
This commit is contained in:
@@ -37,6 +37,29 @@ def create_submission(
|
||||
return submission
|
||||
|
||||
|
||||
@router.get("/user", response=list[SubmissionOut])
|
||||
def list_user_submissions(request: HttpRequest, game_path: str):
|
||||
game = get_object_or_404(Game, path=game_path)
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
return 403, {"detail": "Authentication required"}
|
||||
|
||||
submissions = Submission.objects.filter(game=game, user=request.user).order_by(
|
||||
"-created_at"
|
||||
)
|
||||
return submissions
|
||||
|
||||
|
||||
@router.get("/game", response=list[SubmissionOut])
|
||||
def list_submissions_by_game(request: HttpRequest, game_path: str):
|
||||
game = get_object_or_404(Game, path=game_path)
|
||||
|
||||
if not request.user.is_staff:
|
||||
return 403, {"detail": "Admin access required"}
|
||||
|
||||
return Submission.objects.filter(game=game)
|
||||
|
||||
|
||||
@router.get("/{submission_id}", response=SubmissionOut)
|
||||
def get_submission(request: HttpRequest, submission_id: str):
|
||||
submission = get_object_or_404(Submission, id=submission_id)
|
||||
@@ -45,14 +68,3 @@ def get_submission(request: HttpRequest, submission_id: str):
|
||||
return 403, {"detail": "Not authorized"}
|
||||
|
||||
return submission
|
||||
|
||||
|
||||
@router.get("/game/{game_path}")
|
||||
def list_submissions_by_game(request: HttpRequest, game_path: str):
|
||||
game = get_object_or_404(Game, path=game_path)
|
||||
|
||||
if not request.user.is_staff:
|
||||
return 403, {"detail": "Admin access required"}
|
||||
|
||||
submissions = Submission.objects.filter(game=game)
|
||||
return [SubmissionOut.from_orm(s) for s in submissions]
|
||||
|
||||
@@ -18,8 +18,10 @@ def submission_file_upload_path(instance, filename):
|
||||
ext = filename.split(".")[-1] if "." in filename else ""
|
||||
|
||||
new_filename = f"{instance.id}_{filename}" if ext else str(instance.id)
|
||||
date = instance.created_at.strftime("%Y/%m/%d")
|
||||
user = instance.submission.user.username
|
||||
|
||||
return f"submissions/{instance.submission.id}/{new_filename}"
|
||||
return f"{instance.submission.game.path.lstrip('/')}/{date}/{user}/{instance.submission.id}/{new_filename}"
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
from ninja import Schema
|
||||
|
||||
|
||||
class SubmissionFileOut(Schema):
|
||||
id: str
|
||||
id: UUID
|
||||
original_filename: str
|
||||
file_size: int
|
||||
content_type: str
|
||||
@@ -12,9 +14,9 @@ class SubmissionFileOut(Schema):
|
||||
|
||||
|
||||
class SubmissionOut(Schema):
|
||||
id: str
|
||||
id: UUID
|
||||
game_id: Optional[int] = None
|
||||
notes: Optional[str] = None
|
||||
files: list[SubmissionFileOut] = []
|
||||
created_at: str
|
||||
updated_at: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
Reference in New Issue
Block a user