Skip to content

rune-brinckmeyer/peakon-cc

Repository files navigation

Peakon Code Challenge

Peakon code challenge. Implementing specified rest api as pr code challenge description.

The challenge was open ended in some regards, so the following choices has been made:

Language: The chosen language is Clojure with a http-kit web server.

Rest API: The rest api url and parameter names are unspecified. They are as follows:

  • Service Port: 8080 (configurable using HOST_PORT env var)

  • Service Path: The rest-api is available under /v1/employee/

  • Service Parameters: The service support the following parameters:

    • page - requested page index
    • per_page - number of items to return per page
  • Service Values A successful service call will return the following response, where the field names should be self-explanatory (items field replaced with ... for brevity):

    {
        "items": [...], 
        "items_total": 2,
        "page": 1,
        "prev_page": null,
        "next_page": null,
        "pages": 1,
        "per_page": 10,
        "search-term": "al"
    }

Pre-Built Binary

If Docker is installed, this implementation can be inspected with minimum hassle on a reviewer machine:

$ sudo docker pull runebrinckmeyer/peakon-cc:1.0.0
$ sudo docker run --rm -p 8080:8080 runebrinckmeyer/peakon-cc:1.0.0

Manual Building

Checkout code from this repository.

To run/build the code the following dependencies must be installed:

  • Java (8+)
  • Leiningen

This project is built using the build tool Leiningen which needs to be installed: https://leiningen.org/

Running Tests

Perform steps described under "Manual Building".

Tests are set up using the standard Clojure test framework. Eftest is added as a test-runner, while the standard test runner is available also.

Use either

$ lein eftest

or

$ lein test

to run tests.

The tests are divided into:

  • Verification of database integrity and query results
  • Verification of web-facing routes passing correct parameters

Running

Start service using prebuilt or manual method. Eg either

$ sudo docker run --rm -p 8080:8080 runebrinckmeyer:peakon-cc:1.0.0

or

$ lein run

Point your browser to http://localhost:8080 to verify that it is running or test the rest-api directly using eg. curl:

$ curl http://localhost:8080/v1/employee/donald

Starting in REPL

In case an IDE REPL launcher is not available, a REPL can be started using

$ lein repl

server startup / shutdown is done via the pair of functions:

(start-app)
(stop-app)

Running tests from with the REPL:

rest-api.core=> (require '[eftest.runner :refer [find-tests run-tests]])
nil
rest-api.core=> (run-tests (find-tests "test"))
...

Code Organization

The code pertaining the test is implemented 3 files:

  • app.clj
  • core.clj
  • db.clj

core.clj is responsible for launching the application. app.clj sets up the routes and web server. db.clj contains the loading and prepping of the actual data as well as the search function.

app.clj route /v1/employee/:search-string maps through to search-employee()

About

Peakon Code Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages