Implement the two /application endpoints described below.
For each endpoint, create a pull request (PR) and merge your PR into main for your repository. Implementing both endpoints will require writing code and verifying that the written test cases pass as expected. All tests are located in test_backend_engineer_interview.py
Below are acceptance criteria for 4 endpoints. The first 2 endpoints have already been implemented and have passing tests.
- In your first PR, implement the third endpoint (POST application), ensuring the existing tests pass.
- In your second PR, implement the fourth endpoint (GET application), adding any tests you feel are necessary to confirm the working functionality.
- As a user I would like to retrieve an employee by ID with fields:
- id
- first_name
- last_name
- date_of_birth
- I should not be able to see the employee's secret
- If the ID does not exist in the DB, I expect to receive a 404
- As a user, I should be able to change an employees first and last name
- The first and last name must be at least 1 character long and cannot be empty
- As a user, I would like to receive a 400 status and the relevant error if the request is invalid
- As a user, I should receive a 404 if the ID of the employee to patch does not exist
- As a user, I should be able to POST a new application with the following fields
- leave_start_date
- leave_end_date
- the ID of an employee
- I should receive a 400 if the POST body is invalid
- Missing fields
- Employee ID does not exist
- As a user, I would like to be able to search for applications
- I should be able to search by either first name, last name or employee ID
- If I don't provide any search parameters, I should get all the applications
- As a user, I would like to have paginated results returned
- Install python@3.12. This can be managed with asdf and asdf-python
- Install uv
- Run
uv sync --extra devto install dependencies - Run
uv run uvicorn backend_engineer_interview.__main__:app --reloadto bring up the API server
backend-engineer-interview/
backend_engineer_interview/
app.py
handlers.py - Routes should be implemented here
models.py - Database models, new models should be added here
tests/
test_backend_engineer_interview.py - Test cases for the endpoints
app.db - initialized sqlite db
openapi.yaml - Open API specifications- There is a helper
db_sessionthat can be used to query the db; see the status endpoint for an example - Connexion works by using the
operationIddefined in the openAPI spec to find a correspondingly named python function to use as the handler- See how
/v1/statusis connected to thestatushandler as an example
- See how
- Connexion can automatically perform request and response validation based on the open API spec
- For the last two endpoints, you'll need to implement a new openAPI specification; you can refer to the one for patching an employee as an example
- How do I reset the database?
Delete the app.db file and run
uv run alembic upgrade head - What URL are the docs at? http://localhost:8000/v1/ui
- How do I see an example response?
If you would like to see the example response generated from the open API definition. Simply comment out
operationId. - How do I create new tables from models?
New tables can be generated by running
uv run alembic revision --autogenerate -m "Revision name"and thenuv run alembic upgrade head