Skip to content

focusconsulting/focus-engineering-backend-take-home

Repository files navigation

Focus Backend Engineer Exercise

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

Endpoints

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.

1. GET employee

Acceptance Criteria

  • 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

2. PATCH employee

Acceptance Criteria:

  • 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

3. POST application

Acceptance Criteria:

  • 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

4. GET application

Acceptance Criteria:

  • 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

Setup Instructions

  1. Install python@3.12. This can be managed with asdf and asdf-python
  2. Install uv
  3. Run uv sync --extra dev to install dependencies
  4. Run uv run uvicorn backend_engineer_interview.__main__:app --reload to bring up the API server

Project Structure

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

Implementation Notes

  • There is a helper db_session that can be used to query the db; see the status endpoint for an example
  • Connexion works by using the operationId defined in the openAPI spec to find a correspondingly named python function to use as the handler
    • See how /v1/status is connected to the status handler as an example
  • 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

Useful documentation

FAQ

  • 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 then uv run alembic upgrade head

About

Focus Consulting Backend Engineer Take-Home Exercise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors