The goal of this exercise is to test that you know your way around Django and REST APIs. Approach it the way you would an actual long-term project.
The idea is to build a platform on which your users can buy and sell Starships. To make this process more transparent, it has been decided to source some technical information about the Starships on sale from the Starship API.
A Django project some initial data models have been created already. You may need to do some additional data modelling to satify the requirements.
- This test works with either Docker or Vagrant
- Get the code from
https://github.com/ostmodern/python-code-test - Do all your work in your own
developbranch - Once you have downloaded the code the following commands will get the site up and running
# For Docker
docker-compose up
# You can run `manage.py` commands using the `./manapy` wrapper
# For Vagrant
vagrant up
vagrant ssh
# Inside the box
./manage.py runserver 0.0.0.0:8008- The default Django "It worked!" page should now be available at http://localhost:8008/
Your task is to build a JSON-based REST API for your frontend developers to consume. You have built a list of user stories with your colleagues, but you get to decide how to design the API. Remember that the frontend developers will need some documentation of your API to understand how to use it.
We do not need you to implement users or authentication, to reduce the amount of time this exercise will take to complete. You may use any external libraries you require.
- We need to be able to import all existing Starships to the provided Starship Model
- A potential buyer can browse all Starships
- A potential buyer can browse all the listings for a given
starship_class - A potential buyer can sort listings by price or time of listing
- To list a Starship as for sale, the user should supply the Starship name and list price
- A seller can deactivate and reactivate their listing
After you are done, create a release branch in your repo and send us the link.
-
See import_starships management command.
You can check this yourself by running
./manapy import_starshipsthen check
http://0.0.0.0:8080/starships/and you will see: -
See test_browse_starships test.
Run these tests via
./manapy test -v2 shiptrader
You can also set up some dummy listings conveniently via ./manapy dummy_populate,
then run docker-compose up and visit http://0.0.0.0:8080/listings/:
- Upgraded project to work with latest LTS Django version (2.2).
- Did not use swapi's Python SDK as it is Python2.7.x and this project is using Python3.6.
- Wiped previous migration file as project still brand new and assume never populated with relevant data.
- Some 'niceties' like a view-specific custom search param is not supported yet officially in DRF 2.2 at the time. A solution via a drf-suggested third party lib would require diving deeper into the rabbithole.
- No considerations around other environments like prod or staging were made.
- Endpoints were not fine-tuned to restrict functionality to merely what was asked. As implemented you can e.g. also make a listing or starship detail call.
- With DRF would be simple to add pagination if requested.
- A next level would be implementing users who can buy and sell. You would also want authentication and restrict user api access appropriately like allowing a user to only deactivate their own listing entries.
- If the swapi starship list would have been something that grew over time, it would be nice to run the import via a cron task and as a batch process (as multiple pages) via Celery.
- See commit messages for more details about rationale behind changes.



