Skip to content

Build-Week-Testify/Back-End

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Back-End Documentation for Testify API

The base URL for all axios requests: https://testify-backend.herokuapp.com/api/

POST Request - Register a new user
METHOD - POST
Endpoint: /auth/register

Requires an object in the request body with the following shape:
{
	"username": "sally",
	"password": "1234"
}
POST Request - Login an existing user
METHOD - POST
Endpoint: /auth/login

Requires an object in the request body with the following shape:
{
	"username": "sally",
	"password": "1234"
}
GET Request - Get a user by their id
METHOD - GET
Endpoint: /users/:id Example: /users/2

Returns a response object with the following shape:
{
    "user": {
        "id": 1,
        "username": "sally789",
        "password": "$2a$10$2NsVlP/CyRevz4afAGgI6.e7bHCnhrd6pFOtyxtLJ58YbYbBRroXu",
        "name": null,
        "email": null,
        "isTeacher": 0,
        "tests": [
            {
                "id": 2,
                "title": "Alegbra test",
                "score": 10,
                "created_at": "2019-10-23 22:17:13",
                "user_id": 1,
                "questions": [
                    {
                        "id": 1,
                        "text": "what is 2 x 2?",
                        "test_id": 2
                    },
                    {
                        "id": 2,
                        "text": "what is 2 x 3?",
                        "test_id": 2
                    }
                ]
            }
        ]
    }
}
GET Request - Get a list of all tests
METHOD - GET
Endpoint: /tests

Returns a response array with the following shape:
[
    {
        "id": 2,
        "title": "Alegbra test",
        "score": 10,
        "created_at": "2019-10-23 22:17:13",
        "user_id": 1,
        "username": "sally789",
        "name": null
    },
     {
        "id": 2,
        "title": "Spelling test",
        "score": 10,
        "created_at": "2019-10-23 22:17:13",
        "user_id": 1,
        "username": "sally789",
        "name": null
    }
]
GET Request - Get a test by test id
METHOD - GET
Endpoint: /tests/:id Example: /tests/2

Returns a response object with the following shape:
{
    "test": {
        "id": 2,
        "title": "Alegbra test",
        "score": 10,
        "created_at": "2019-10-23 22:17:13",
        "user_id": 1,
        "questions": [
            {
                "id": 1,
                "text": "what is 2 x 2?",
                "test_id": 2,
                "answers": [
                    {
                        "id": 1,
                        "option": "4",
                        "isCorrect": 1,
                        "question_id": 1
                    },
                    {
                        "id": 2,
                        "option": "6",
                        "isCorrect": 0,
                        "question_id": 1
                    },
                    {
                        "id": 3,
                        "option": "8",
                        "isCorrect": 0,
                        "question_id": 1
                    }
                ]
            },
            {
                "id": 2,
                "text": "what is 2 x 3?",
                "test_id": 2,
                "answers": []
            }
        ]
    }
}
POST Request - Create a new test
METHOD - POST
Endpoint: /tests

Will allow for all fields (except user_id) to be null and will return a new id. Requires a request body with the following shape:
{
    "user_id": 2
}

Once successful, will return a response object with the following shape:

{
    "newTest": {
        "id": 1,
        "title": null,
        "score": null,
        "created_at": "2019-10-24 04:37:01",
        "user_id": 1
    }
}
PUT Request - Edit an existing test
METHOD - PUT
Endpoint: /tests/:id Example: /tests/2

Will allow for title and score fields to be updated
{
    "title": "",
    "score": ""
}

Once successful, will return a response object with the following shape:

{
    "id": 1,
    "title": "Math Test",
    "score": 100,
    "created_at": "2019-10-24 04:37:01",
    "user_id": 1
}
POST Request - Post an array of test question objects
METHOD - POST
Endpoint: /questions

Will allow for text and test_id fields to be updated
[
{
	"text": "What is 1 + 2",
	"test_id": 1
},
{
	"text": "What is 7 * 4",
	"test_id": 1
},
{
	"text": "What is 18 / 2",
	"test_id": 1
}
]
POST Request - Post an array of answers to a question
METHOD - POST
Endpoint: /answers

Will allow for text and test_id fields to be updated
[
{
	"option": "3",
	"isCorrect": true,
	"question_id": 1
},
{
	"option": "2",
	"isCorrect": false,
	"question_id": 1
},
{
	"option": "1",
	"isCorrect": false,
	"question_id": 1
}
]

Table entities

User

attribute data type required
id integer auto-assigns
username string Yes
password string Yes
name string No
email string No
isTeacher boolean No

Test

attribute data type required
id integer auto-assigns
title string No
score integer No
created_at timestamp auto-assigns
user_id integer Yes

Question

attribute data type required
id integer auto-assigns
text string No
test_id integer Yes

Answer

attribute data type required
id integer auto-assigns
isCorrect boolean No
option string No
question_id integer Yes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors