Test work for %companyname%, written in July 2018.
We are building a competitor to Amazon S3 offering, You are to create an API that will support the following:
- List the existing folders Content of the bucket can contain other folders and files There is no limit on the number of items within a folder There is no limit to number of subfolders
- Manage folders You should ensure the following constrains: the name of the folder is uniq between siblings deleting a folder will automatically delete all of the content within it
- File Management Folder element is optional, if null should be placed as root Any file type and size is allowed
Please keep the implementation as simple as possible given that part of face to face interview will be refactoring of this code. Please document areas that are open to interpretation and potential debate so we could make a point to discuss them during face to face interview
-
PHP used as main application language;
-
MySQL used as database server;
-
Slim used as base framework for API application (https://www.slimframework.com);
-
Propel as ORM engine (http://propelorm.org).
- Folder listing
GET /path/to/folder
- return json with status and folder contents, or with error code if path is not found
Success request example:
GET /
response
{ "status": "ok", "folder": "root", "subfolders": [ "myfolder", "mysecondfolder", "myanotherfolder" ], "files": [ "todo.txt", "thedoor" ] }
Error response example:
GET /path/not/exists
response
{ "status": "error", "code": "path not found" }
- File content
GET /path/to/file.ext
- returns file content
- Making a folder
For making a folder send an POST request to parent folder, with content type multipart/form-data
.
Name of creating folder passed in a folder
field of request body
POST /path/to/parent/folder
In response you will get JSON with listing of created folder (it may already exists), or error code.
- Uploading a file
For upload a file, send an POST request to parent folder, with content type multipart/form-data
.
Uploading file must passed in a file
field of request body
POST /path/to/parent/folder
In response you will get JSON with listing of file's parent folder, or error code, if file already exists, or has uploading errors.
- Uploading a file to new folder
This is a combination of two previous methods. If you pass in request's body both folder
and file
fields, than subfolder will create first at requested path, and after that, file will be stored to created subfolder.
- Deleting file
DELETE /path/to/file
- deletes requested file (if it exists).
In response you will get JSON with listing file's folder.
- Deleting folders
DELETE /path/to/folder
- recursively deletes requested folder with all child objects (subfolders and files - both in current folder and all its subfolders)
In response you will get JSON with listing of parent folder.
While this app based on slim skeleton application and Propel generated code, so not all code is written manually by myself.
Files with manually written code are:
- storage-api/actions/StorageApi.php
- storage-api/actions/ActionGet.php
- storage-api/actions/ActionPost.php
- storage-api/actions/ActionDelete.php
- storage-api/propel.yml
- storage-api/schema.xml
- src/routes.php
- and edited public/index.php
-
Clone repository form github
-
Run
composer install
to install app dependencies -
Go to atorage-api folder and edit database connection params in propel.yml file
-
Run
propel config:convert
to convert config to runtime format -
Run
mysqladmin -u root -p create storage_api
to create empty DB (if it's not exists yet) -
Run
propel sql:insert
for create tables in DB -
Go back to project root
-
Run
php -S localhost:8080 -t public
to start PHP internal webserver -
Check url
http://localhost:8080
in your browser