Skip to content

Commit

Permalink
Created contests API
Browse files Browse the repository at this point in the history
closes #10

note: it does need better filtering implemented
  • Loading branch information
JasonLovesDoggo committed Apr 5, 2024
1 parent 7f8d1c6 commit 4e455b8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gameserver/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ninja import NinjaAPI, Schema
from typing import List, Any

import datetime

def unicode_safe(string):
return string.encode("unicode_escape").decode()
Expand All @@ -14,6 +15,16 @@ def unicode_safe(string):
api = NinjaAPI()


class ContestOutSchema(Schema):
name: str
slug: str
start_time: datetime.datetime
end_time: datetime.datetime
max_team_size: int | None
description: str
summary: str


class CTFSchema(Schema):
pos: int
team: Any = None
Expand Down Expand Up @@ -73,3 +84,10 @@ def ctftime_standings(request, contest_name: str):
)

return {"standings": standings, "tasks": task_names}

@api.get("/contests", response=List[ContestOutSchema])
def contests(request):
return (
Contest.objects.filter(is_public=True)
.values("name", "slug", "start_time", "end_time", "max_team_size", "description", "summary")
)

0 comments on commit 4e455b8

Please sign in to comment.