Topic CRUD (Admin) - masai-oss/Masai_Refresh GitHub Wiki
GET /api/topic/
- Header:
Authorization: Bearer <Token>
RESPONSE
Success : (Status Code: 200)
{
"error": false,
"data": [
{
"_id": "603d296ad6e83884ebcb0149",
"name": "CSS",
"icon": "./path",
"noOfQuestion": 54
},
{
"_id": "603d51f8c9e277c4ad97be82",
"name": "HTML",
"icon": "./path"
"noOfQuestion": 54
},
{
"_id": "603dadd4f9f62e1ffacc407f",
"name": "JAVASCRIPT",
"icon": "./path",
"noOfQuestion": 54
}
]
}
GET /api/topic/id/:id
-
Params:
id : <topic id>
-
Header:
Authorization: Bearer <Token>
RESPONSE
Success : (Status Code: 200)
{
"error": false,
"data": {
"_id": "603d51f8c9e277c4ad97be82",
"name": "HTML",
"icon": "./path",
"questions": [allQuestions]
}
}
Failure : (Status code: 400) - When given wrong ID
{
"error": true,
"message": {
"stringValue": "\"603d51f8c9e277c4ad97be8\"",
"kind": "ObjectId",
"value": "603d51f8c9e277c4ad97be8",
"path": "_id",
"reason": {}
}
}
GET /api/topic/name/:name
-
Params:
name : <topic name>
-
Header:
Authorization: Bearer <Token>
RESPONSE
Success : (Status Code: 200)
{
"error": false,
"data": {
"questions": [],
"_id": "603f97b5177f3ff20c119f05",
"name": "HTML",
"icon": "./path",
"questions": [allQuestions]
}
}
Failure : (Status code: 404) - When given the wrong name
{
"error": true,
"message": "Given topic name does not exist"
}
POST /api/topic/create
- Header:
Authorization: Bearer <Token>
- Body
{
"name": "REACT",
"icon" : "image" // acceptable format of svg/png/jpeg recommend using SVG
}
RESPONSE Success : (Status Code: 200)
{
"error": false,
"message": "The topic has been created."
}
FAILURE : (Status Code: 409) - If the topic name already exists
{
"error": true,
"message": "The topic cannot be created as it already exists."
}
- ---- CURRENTLY THIS API IS NOT OPERATIONAL ----
DELETE /api/topic/:id
- Header:
Authorization: Bearer <Token>
- Param
id: <topic_id>
RESPONSE Success : (Status Code: 200)
{
"error": false,
"message": "The topic has been deleted"
}
FAILURE : (Status Code: 404) - If the topic id does not exist
{
"error": true,
"message": "The Topic could not be deleted as the information provided could not match any record"
}
FAILURE : (Status Code: 400) - When Topic name does not match the available Enums
{
"error": true,
"message": {
"errors": {
"name": {
"name": "ValidatorError",
"message": "`NEW` is not a valid enum value for path `name`.",
"properties": {
"message": "`NEW` is not a valid enum value for path `name`.",
"type": "enum",
"enumValues": [
"JAVASCRIPT",
"CSS",
"HTML",
"DS_ALGO",
"REACT",
"EXPRESS",
"MONGO_DB",
"NODE_JS"
],
"path": "name",
"value": "NEW"
},
"kind": "enum",
"path": "name",
"value": "NEW"
}
},
"_message": "topics validation failed",
"name": "ValidationError",
"message": "topics validation failed: name: `NEW` is not a valid enum value for path `name`."
}
}
PATCH /api/topic/icon/:id
- Header:
Authorization: Bearer <Token>
- Param
id: <topic_id>
- Body
{
"icon" : "image" // acceptable format of svg/png/jpeg recommend using SVG
}
RESPONSE Success : (Status Code: 200)
{
"error": false,
"message": "The topic has been updated"
}
FAILURE : (Status Code: 400) - If the topic id does not exist
{
"error": true,
"message": {
"stringValue": "\"603fab3ae066580e7f71b0f\"",
"kind": "ObjectId",
"value": "603fab3ae066580e7f71b0f",
"path": "_id",
"reason": {}
}
}