Skip to content

Documentation API

Maëlys Bühler edited this page Apr 26, 2024 · 47 revisions
GET /api/category/iq
Description Get all categories with the IQ of current User
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401

Success response exemple: (keys are category id)
{
"1": {
"category_name": "Animals",
"user_iq": 100
},
"2": {
"category_name": "Brain Teasers",
"user_iq": 100
}
}

GET /api/category/{category_id}/name
Description Get the name of the given category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters category_id: ID of the category
Success code 200 OK
Failure cases User is not authentificated - 401

Success response example:
{
"category_name": "Politics"
}

GET /api/category/{category_id}/image
Description Get category image
Result Type Image
Authentification mandatory? No
Controller
Parameters category_id: ID of the category
Success code 200 OK
Failure cases Category doesn't exist - 404

Success response:
return image

GET /category/{category_id}/user_iq
Description Get user IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters category_id: ID of the category
Success code 200 OK
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_iq": 108
}

GET /api/question/{category_id}/new
Description Set the current question for the user, and return the question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters category_id: ID of the question's category
Success code 200 OK
Failure cases User is not authentificated - 401 / Category does not exist - 404

Success response example {
"id": 623,
"text": "What is the Yorkshire Terriers average lifespan?\n",
"category": "Animals"
}

GET /api/question/{category_id}/options
Description Get the options for the user's current question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401 / No questions being answered at the moment - 400

Success response example:
{
"question_id":1,
"number_of_options":4,
"options:" {
"234:"the panther",
"432":"the cheetah",
"234":"the jaguar",
"324":"the leopard",
}
}

POST /api/question/new_community
Description add a question to the community category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 201 CREATED
Failure cases User is not authentificated - 401 / Body data invalid - 400

Request body example:
{
"question": "How old is Harry Potter at the beginning of the first book?",
"options": [
"11",
"15",
"He wasn't born"
],
"answer": "1"
}

Success response example: {
"text": "Howfdsfds old is Harry Potter at the beginning of the first book?", "category": "Community" }

POST /api/question/{category_id}/answer_option
Description Send answer to current question, as one of the proposed options
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - / User did not ask for options - 400 / No questions being answered at the moment - 400

request body example:
{
"answer":"232"
}

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

POST /api/question/{category_id}/answer_text
Description Send answer to current question, as text
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401 User already asked for options - 400 / No questions being answered at the moment - 400

Request body example: { "answer":"he wasn't born" }

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

GET /api/question/{category_id}/options_asked
Description Indicate if the user already asked for the options
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters
Failure cases User is not authentificated - 401 / No questions being answered at the moment - 400

Success response example
{
"options_asked":true
}

GET /api/rank/{category_id}/leaderboard
Description Get best players in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_iq":150 },
{
"user_id":3,
"user_name":"Krucksy",
"user_iq":136 },
...
]

GET /api/rank/{category_id}/user
Description Get user rank and IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_rank": 45,
"user_iq": 108
}

GET /api/rank/global_leaderboard
Description Get the 10 global best best players
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401

Success response infos:
JSON array are ordered. The first element of the list is the first player, and it then goes in descending order
The array must contains at maximum 10 entry. If there is less than 10 entry, it means that there is less than 10 players in the database.
Score calculation is still not decided, scores in example may not be representative of real data.

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_score":1890
},
{
"user_id":3,
"user_name":"Krucksy",
"user_score":1800
},
...
]

GET /api/rank/global_user
Description Get the position in leaderboard and score of current user
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Success code 200 OK
Failure cases User is not authentificated - 401
Success response example:
{
"user_rank": 45,
"user_score": 1000
}
POST /api-token-auth/
Description get user api token
Result Type JSON
Authentification mandatory? No
Controller
Parameters -
Success code 200 OK
Failure cases Login credentials unvalid - 400

request body example:
{
"username":"",
"password":""
}

success answer example: Code 200 {"token": "2252495dbe26f259ceb716f4a25caaf54fcafc36"}

failure answer example: Code 400 { "non_field_errors": [ "Unable to log in with provided credentials." ] }

POST /api/user/register
Description Create new user account
Result Type JSON
Authentification mandatory? No
Controller
Parameters -
Success code 201 CREATED
Failure cases Username already taken - 400

request body example:
{
"username":"",
"password":""
}

success answer example: Code 201 {"message":"Signup successful"}

failure answer example: Code 400 {"message":"Username already exists"}

NON IMPLEMENTE

GET /api/user/coffee
Description Brew a coffee for the user
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases The pot is a teapot - 418
Clone this wiki locally