https://github.com/marktopper/interflora
https://github.com/marktopper/interflora
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/marktopper/interflora
- Owner: marktopper
- Created: 2022-05-02T17:23:07.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-02T19:02:29.000Z (about 4 years ago)
- Last Synced: 2025-03-24T05:16:10.685Z (over 1 year ago)
- Language: PHP
- Size: 76.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# Exercice
We in Interflora Denmark, need to model how our company is structured so we can help our new employees have a better overview of our
company structure.
We have our root node (only one, in our case the CEO) and several child nodes.
Each of these nodes may have its own children.
It can be structured as something like this:
```
root
/ \
a b
|
c
/ \
d e
```
# Requirements
- Laravel Valet
- PHP 8.0
- Composer
- MySQL
- SQLite (for automatic tests in memory)
# Install
Use Laravel Valet or similar with the public path to be `public/`.
Install composer dependencies.
```shell
composer install
```
Copy `.env.example` to `.env` and update the database credentials.
Migrate and seed the database:
```shell
php artisan migrate --seed
```
# API Documentation
## Add a new node to the tree.
Request:
```
curl --location --request POST '/api/nodes' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Awesome Node",
"parent_id": 1,
"programming_language": "php",
"department": "Development"
}'
```
Response:
```
{
"data": {
"id": 2,
"name": "Awesome Node",
"department": "Development",
"programming_language": "php",
"parent_id": 1,
"height": 2,
"children": []
}
}
```
## Get all child nodes of a given node from the tree. (Just 1 layer of children)
Request:
```
curl --location --request GET '/api/nodes/1'
```
Response:
```
{
"data": {
"id": 1,
"name": "R00T",
"department": null,
"programming_language": null,
"parent_id": 1,
"height": 0,
"children": [
{
"id": 2,
"name": "a",
"department": null,
"programming_language": null
},
{
"id": 3,
"name": "b",
"department": null,
"programming_language": null
}
]
}
}
```
## Change the parent node of a given node.
Request:
```
curl --location --request PATCH '/api/nodes/3' \
--header 'Content-Type: application/json' \
--data-raw '{
"parent_id": 1
}'
```
Response:
```
{
"data": {
"id": 3,
"name": "Awesome Node",
"department": null,
"programming_language": null,
"parent_id": 1,
"height": 1,
"children": []
}
}
```
# Testing
This application is fully automatic tested.
```shell
/vendor/bin/phpunit
PHPUnit 9.5.20 #StandWithUkraine
............ 12 / 12 (100%)
Time: 00:00.273, Memory: 32.00 MB
OK (12 tests, 22 assertions)
```
# Questions
## Should the identifier be string-based?
We could easily convert the Node identifier to be string based in order to support the strings being like `root`, `a`,
`b` and so on. That might make sense in this case, but I wouldn't overcomplicate this
by during so if it wasn't intended.
## Should Nodes have roles?
From the description it sounds like there could be a use-case for roles, here including Developers and Managers
to define their access to the additional `department` and `programming_language` field.
## Only one root node?
Should we make a limit to allow only one root node to exists?
# Improve
What would I improve if I had more time.
I would clean-up the request classes and the tests even further.
I would add some database indexes and query improvements.
Add cache for Node's for better performance.
Add pagination and other API enhancements.