Practice Api - masai-oss/Masai_Refresh GitHub Wiki
GET /api/practice/topics
PARAMS
- Header :
Bearer <Token>
RESPONSE
Success (Status code: 200)
{
"error": false,
"data": [
{
"_id": "60bc997c946b8458d607d9d2",
"name": "JAVASCRIPT",
"icon": "2021-04-02T09:36:50.961Zjavascript.svg",
"total_questions": 420
},
{
"_id": "60bc99c02fa23a596f1d69d1",
"name": "REACT",
"icon": "2021-04-02T08:01:56.310Zreact.svg",
"total_questions": 327
}
]
}
Failure (Status Code: 500)
{
"error" : true,
"message" : "Something went wrong",
"reason" : err
}
POST /api/practice/create
PARAMS
- Header:
Bearer <Token>
- Body:
{
"topic_id" : "605260bac9992fec733acc3f",
"size" : 15 // Optional, if not passed it takes 5 by default
}
RESPONSE
Success: (Status Code: 200)
{
"error": false,
"questions": [
"60ba55d4e3c5c4050d2a5e24",
"60ba55d4e3c5c4050d2a5c86",
"60ba55d4e3c5c4050d2a5d55",
"60ba55d4e3c5c4050d2a5d04",
"60ba55d4e3c5c4050d2a5d30"
]
}
Failure:
- If topic id not sent (Status code: 400)
{
"error": true,
"message": "Send a topic id"
}
- If topic id is not a valid mongo id (Status code: 400)
{
"error": true,
"message": "Invalid topic id"
}
- If topic id doesn't match with any topic (Status code: 400)
{
"error": true,
"message": "No such topic id"
}
- Others (Status code: 500)
{
"error" : true,
"message" : "Something went wrong",
"reason" : err
}
POST /api/practice/question
PARAMS
- Headers:
Bearer <Token>
- Body:
{
"topic_id" : "605260bac9992fec733acc3f",
"question_id" : "60ba55d4e3c5c4050d2a5e15"
}
RESPONSE
Success (Status code: 200)
{
"error": false,
"data": {
"question_id": "60ba55d4e3c5c4050d2a5e15",
"source": "https://github.com/sudheerj/reactjs-interview-questions",
"statement": "What is an observable",
"explanation": "N/A",
"answer": "An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method. Let's look at a simple example of an Observable\n\n import { Observable } from \"rxjs\";\n \n const observable = new Observable((observer) => {\n setTimeout(() => {\n observer.next(\"Message from a Observable!\");\n }, 3000);\n });\n \n observable.subscribe((value) => console.log(value));\n \n\n**Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language",
"likes": 0, // total likes for the question
"like_flag": false, // flag to indicate whether user had already liked it or not
"bookmark_flag": false // flag to indicate whether user had already bookmarked it or not
}
}
Failure
- If topic id or question id is not passed (Status code: 400)
{
"error": true,
"message": "Send both topic and question id"
}
- If topic id or question id is not a valid mongo id (Status code: 400)
{
"error": true,
"message": "Invalid topic or question id"
}
- If topic id doesn't match with any topic or question id doesn't match with any question(Status code: 400)
{
"error": true,
"message": "No such topic or question id"
}
- Others (Status code: 500)
{
"error" : true,
"message" : "Something went wrong",
"reason" : err
}
(Note: If the question is already bookmarked, it removes the question from bookmark else it adds to bookmark)
POST /api/practice/question_bookmark
PARAMS
- Header:
Bearer <Token>
- Body:
{
"question_id" : "60ba55d4e3c5c4050d2a5d92"
}
RESPONSE
Success (Status code: 200)
{
"error": false,
"bookmark_flag": false,
"message": "Action successful"
}
Failure
- If question id is not passed (Status code: 400)
{
"error": true,
"message": "Send a question id"
}
- If question id is not a valid mongo id (Status code: 400)
{
"error": true,
"message": "Invalid question id"
}
- If question id doesn't match with any question (Status code: 400)
{
"error": true,
"message": "No such question id"
}
- Others (Status code: 500)
{
"error" : true,
"message" : "Something went wrong",
"reason" : err
}
(Note: If the question is already liked, it dislikes, else it likes the question)
POST /api/practice/question_like
PARAMS
- Header:
Bearer <Token>
- Body:
{
"question_id" : "60ba55d4e3c5c4050d2a5e15"
}
RESPONSE
Success (Status code: 200)
{
"error": false,
"like_flag": true,
"message": "Action successful"
}
Failure
- If question id is not passed (Status code: 400)
{
"error": true,
"message": "Send a question id"
}
- If question id is not a valid mongo id (Status code: 400)
{
"error": true,
"message": "Invalid question id"
}
- If question id doesn't match with any question (Status code: 400)
{
"error": true,
"message": "No such question id"
}
- Others (Status code: 500)
{
"error" : true,
"message" : "Something went wrong",
"reason" : err
}
(Note: A user can report a question only once)
POST /api/practice/report/:question_id
PARAMS
- Header:
Bearer Token
- Params:
question_id
- Body:
{
reason: ["Question Unclear", "Insufficient Data", "Explanation not clear", "Others"] // length : min 1, max 4,
description: "Lorem ipsum, Lorem ipsum" // length : min 1, max: 255
}
RESPONSE
Success
- If the user hasn't reported the same question previously (Status Code: 200)
{
error: false,
message: "Question reported successfully"
}
- If the user had reported the same question previously (Status Code: 200)
{
error: false,
message: "You already reported the question"
}
Failure
- If request body validation failure (Status code: 400)
{
"error": true,
"message": error // relevant message explaining the error
}
- If question id is not a valid mongo id (Status code: 400)
{
"error": true,
"message": "Invalid question id"
}
- If question id doesn't match with any question (Status code: 400)
{
"error": true,
"message": "No such question id"
}
- Others (Status code: 500)
{
error: true,
message: "Something went wrong",
reason: err,
}