It's an Laravel API for generate a graph and the nodes and the relation between the nodes.
- Graphs with attributes id, name, description, created_at and updated_at
- Nodes with attributes id, graph_id
- Relations with attributes node_parent_id, node_child_id
- GET /graphs and /nodes
- DELETE /graphs/ and /nodes/
- POST /graphs and /nodes
- PATCH /graphs/ and /nodes/
- One test for success behavior of each endpoint
- One test for error behavior of each endpoint
- At least two tests of admin access
- Clone the repository with git clone
- Copy .env.example file to .env and edit database credentials there
- npm install
- Run composer install
- Run php artisan key:generate
- Run php artisan jwt:secret
- Run php artisan migrate --seed (it has some seeded data for your testing)
- Run the Application php artisan serve
To run the tests, run
php artisan test
- Base URL: Base URL: Actually, this app can be run locally . The backend app is hosted at the default,
http://127.0.0.1:8000/
, which is set as a proxy in the frontend configuration. - you can change the default port by php artisan serve --port=8888
- Authentication: This version of the application require authentication or API keys using Auth0 (Ps: The setup is givin in setup Auth0 section)
php artisan graph:gen --nbNodes={$nbNodes}
This command create a random graph with $nbNodes nodes and random relations.
php artisan graph:clear This command delete all empty graphs.
php artisan graph:stats --gid={$graphId}
This command display graphs stats (display the graph meta data, number of nodes, number of relations) by graph id.
Errors are returned as JSON object in the following format:
{
"success": False,
"error": 400,
"message": "bad request"
}
The API will return four(04) error types when requests fail:
- 400: Bad Request
- 404: Resource Not Found
- 405: Method Not allowed
- 422: Not Processable
- 401: AuthError Unauthorized error
- 403: AuthError Permission not found
- GET '/graphs'
- GET '/nodes'
- GET '/graphs/{graph}'
- GET '/nodes/{node}'
- POST '/graphs/create'
- POST '/nodes/create'
- PATCH '/graphs/{graph}/update'
- PATCH '/nodes/{node}/update'
- DELETE '/graphs/{graph}'
- DELETE '/nodes/{node}'
- Returns a list of actors
return response()->json({
'success': True,
'graphs': $graphs
})
Here is a returned sample fromat meta data (name, description)
[
{
"id": 1,
"name": "first graph",
"description": "description content"
},
{
"id": 2,
"name": "second graph",
"description": "second description"
},
{
"id": 4,
"name": "third graph",
"description": "third description"
}
]
- Returns a specific graph and it's proprities
return response()->json([
'graph' => $graph
]);
Here is a returned sample fromat to a specific graph
{
"graph": {
"id": 2,
"name": "second graph",
"description": "second description",
"nodes": [
{
"id": 4,
"graph_id": 2,
"parents": [
{
"id": 5,
"node_parent_id": 3,
"node_child_id": 4
}
],
"childs": [
{
"id": 6,
"node_parent_id": 4,
"node_child_id": 3
}
]
}
]
}
}
- Create a new row in the graphs table
returns status code 200 and json
{"success": True, "graphs": graph}
where graph an array containing only the newly created graph or appropriate status code indicating reason for failure.
Here is a result sample format:
{
"status": true,
"message": "Added Successfuly",
"options": [],
"new graph": {
"id": 2,
"name": "new_name",
"description": "new_description"
}
}
if the name is Alreaty taken return 400 error , like This exaample
{
"status": false,
"errNum": "Error",
"message": {
"name": [
"The name has already been taken."
]
}
}
- Update an existing row in the graphs table
returns status code 200 and json
{"success": True, "graphs": graph}
where graph an array containing only the updated graph or appropriate status code indicating reason for failure
He is a sample for a modified actor in a format:
{
"status": true,
"message": "Updated Successfuly",
"options": [],
"updated": {
"id": 2,
"name": "updated_name",
"description": "updated_description"
}
}
if the name is Alreaty taken return 400 error , like This exaample
{
"status": false,
"errNum": "Error",
"message": {
"name": [
"The name has already been taken."
]
}
}
- Delete the corresponding row for
<graph_id>
where<graph_id>
is the existing model id - Respond with a 404 error if
<graph_id>
is not found - Returns status code 200 and json
{"success": True, "deleted": graph_id}
where id is the id of the deleted record or appropriate status code indicating reason for failure
return $this->returnData(
'item', $graph,
'Deleted Successful'
);
the result return
{
"status": true,
"message": "Deleted Successful",
"options": [],
"item": {
"id": 20,
"name": "Torey Christiansen",
"description": "Quos ut et."
}
}
return $this->returnData(
'item', $node,
'Added Successful'
);
body must has two value parent_id, child_id
return $this->returnData(
'Relation', $relation,
'Added Successful'
);