Task implemented using fastapi server + peewee ORM.
First one is quite beautiful, the second one is beautiful as well. The only drawdown of this ORM is that it's a sync one.
Nevertheless I suppose it will be more than enough to satisfy task requirements.
Tests implemented with pytest.
Small hack has been used to avoid writing multiple levels of fixtures, since app isn't dependent on database object directly.
Therefore you need to set a DB_URI env pointing to test database. Added foolproofing to tests to avoid modifying production database.
- Create a virtual environment. (App was crated in Python 3.10.4)
- Run
pip install -r requirements.txton order to install dependencies. - Use command
make testto run tests. - Use
make runto run server locally, usually as port 8000.
Repo contains everything needed to run it in docker/k8s.
docker-compose upruns dockerized application built from local source. Database used is Sqlite3 mounted at ./database repo folder. You can check it during process if needed.- Also repo contains k8s manifest:
kubectl apply -f manifest.yml. You can use it in any environment, DB_URI is stored in k8s secret, it's pointing to my own Postgres server. In task mentioned most secure way to run app. It's obviously not the case. It I was focused on security I would run DB in isolated k8s subnetwork, unreachable from outside.
The task was quite interesting. Tough points was:
- Testing. Namely implementing fixtures for endpoint testing. Ended up with setting test database externally. Because it was too much to write multi-level fixtures for endpoints. Models testing weren't complicated though.
- Custom sorting - ended up with a raw SQL, it's a bit tough to transcribe complex SQL with joins and unions into ORM syntax.
- Writing docstrings (: I hope you'll like it. Wording is quite challenging task sometimes as well.
Currenly instance of this API is running at my node. You can reach it by address http://51.15.60.207:31600 (Yep, I don't have a domain name, and don't really want to set up an ingress in fact (: ) Hopefully, you'll like the result.
- Added small CI/CD script - testing on pushes to main. Just a showcase (:
Kind regards, Mikhail.