Skip to content

Сontests

arcturus5340 edited this page May 28, 2021 · 5 revisions

Contests API

List available contests

Get a list of available contests in system.
GET /api/contests
Parameters:

Attribute Type Required Description
search string no Search keyword

Example request:

curl "https://julia-api-server.codes/api/contests/?search=example"

Example response:

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "title": "Contest",
            "description": "Description for example",
            "tasks": [
                1,
                2,
                3
            ],
            "start_time": 994166100,
            "duration": 7200
        }
    ]
}

Get a single contest

Get a specific contest identified by the contest id.
GET /api/contests/:id
Parameters:

Attribute Type Required Description
id int yes The contest ID

Example request:

curl "https://julia-api-server.codes/api/contests/2"

Example response:

{
    "id": 2,
    "title": "New Contest",
    "description": "Description for new contest",
    "start_time": 994166100,
    "duration": 3600000
}

Create a contest

Create a new contest by posting a JSON payload. Only for staff!
POST /api/contests
Parameters:

Attribute Type Required Description
title string yes Title of the contest being created, which size must be more than 3 characters but not exceed 64
description string yes Contest description
start_time int no Scheduled UNIX start time of the contest. If empty, then the contest starts with the creation time
duration int no Duration of the contest in seconds (default value 7200)

Example request:

PAYLOAD=$(cat << 'JSON'
{
    "title": "New Contest",
    "description": "Description for new contest",
    "duration": 3600000
}
JSON
)
curl --request POST --header "Authorization: JWT <access_token>" --header "Content-Type: application/json" --data "$PAYLOAD" "https://julia-api-server.codes/api/contests/"

Example response:

{
    "id": 2,
    "title": "New Contest",
    "description": "Description for new contest",
    "start_time": 994166100,
    "duration": 3600000
}

Partial update a contest

Partial update a contest data. Only for staff!
PATCH /api/contests/:id
Parameters:

Attribute Type Required Description
id int yes The contest ID
title string no Title of the contest being created, which size must be more than 3 characters but not exceed 64
description string no Contest description
start_time int no Scheduled UNIX start time of the contest. If empty, then the contest starts with the creation time
duration int no Duration of the contest in seconds (default value 7200)

Example request:

PAYLOAD=$(cat << 'JSON'
{
    "title": "New Contest (Edited)",
    "duration": 1800000
}
JSON
)
curl --request PATCH --header "Authorization: JWT <access_token>" --header "Content-Type: application/json" --data "$PAYLOAD" "https://julia-api-server.codes/api/contests/2"

Example response:

{
    "id": 2,
    "title": "New Contest (Edited)",
    "description": "Description for new contest",
    "start_time": 994166100,
    "duration": 1800000
}

Update a contest

Update a contest data. Only for staff!
PUT /api/contests/:id
Parameters:

Attribute Type Required Description
id int yes The contest ID
title string yes Title of the contest being created, which size must be more than 3 characters but not exceed 64
description string yes Contest description
start_time int yes Scheduled UNIX start time of the contest. If empty, then the contest starts with the creation time
duration int yes Duration of the contest in seconds (default value 7200)

Example request:

PAYLOAD=$(cat << 'JSON'
{
    "title": "New Updated Contest",
    "description": "Updated description for new contest",
    "start_time": 994166101,
    "duration": 1800000
}
JSON
)
curl --request PUT --header "Authorization: JWT <access_token>" --header "Content-Type: application/json" --data "$PAYLOAD" "https://julia-api-server.codes/api/contests/2"

Example response:

{}

Delete a contest

Delete a contest. Only for staff!
DELETE /api/contests/:id
Parameters:

Attribute Type Required Description
id int yes The contest ID

Example request:

curl --request DELETE --header "Authorization: JWT <access_token>" --header "Content-Type: application/json" "https://julia-api-server.codes/api/contests/2"

Example response:

{}

Get tasks included in the contest

Get all tasks included in the specified contest.
GET /api/contests/:id/tasks
Parameters:

Attribute Type Required Description
id int yes The contest ID

Example request:

curl "https://julia-api-server.codes/api/contests/1/tasks"

Example response:

{
    "count": 3,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "title": "Task 1",
            "content": "Add two numbers",
            "contest": 1,
            "tl": 3,
            "ml": 268435456,
            "samples": [
                [
                    "2 3",
                    "5"
                ],
                [
                    "4 5",
                    "9"
                ]
            ]
        },
        {
            "id": 2,
            "title": "Task 2",
            "content": "Multiply two numbers",
            "contest": 1,
            "tl": 3,
            "ml": 134217728,
            "samples": [
                [
                    "4 5",
                    "20"
                ]
            ]
        },
        {
            "id": 3,
            "title": "Task 3",
            "content": "Print 'Hello, world!'",
            "contest": 1,
            "tl": 1,
            "ml": 268435456,
            "samples": [
                [
                    "some input",
                    "Hello, world!"
                ],
                [
                    "blah-blah",
                    "Hello, world!"
                ]
            ]
        }
    ]
}

Get results of contest

Get the number and time of solving problems for the participating users.
GET /api/contests/:id/results
Parameters:

Attribute Type Required Description
id int no The contest ID

Example request:

curl "https://julia-api-server.codes/api/contests/1/tasks"

Example response:

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "user": 42,
            "attempts": [
                1,
                6,
                4
            ],
            "decision_time": [
                62802,
                63435,
                63659
            ]
        },
        {
            "user": 37,
            "attempts": [
                0,
                0,
                -3
            ],
            "decision_time": [
                null,
                null,
                null
            ]
        }
    ]
}