Skip to content

Zé delivery backend challenge, implementing a simple delivery application.

Notifications You must be signed in to change notification settings

marcosadriano05/delivery

Repository files navigation

Delivery application

Abstract

This project solves the backend challenge, who the main purpose is to create and find a partner and search for the nearest partner for the given latitude and longitude.

This project are made using Deno for the API, Wasmbuild to compiles a library in Rust code to WebAssembly, this library uses Geo crate to calculate if a pointer is inside a polygon.

API

Exemple of an partner in Json format:

{
  "id": 1,
  "tradingName": "Trading Name",
  "ownerName": "Owner Name",
  "document": "999999999999",
  "address": {
    "id": 1,
    "type": "Point",
    "coordinates": [
      -46.588654,
      -23.709635
    ]
  },
  "coverageArea": {
    "id": 1,
    "type": "MultiPolygon",
    "coordinates": [[[[10, 10], [10, 10]]]]
  }
}
  • /partner/:id GET

Returns an partner who matches the route param id.

  • /partner GET

Returns all partners in an json array.

  • /partner POST

Save a partner.

Body:

{
  "tradingName": "Trading Name",
  "ownerName": "Owner Name",
  "document": "999999999999",
  "address": {
    "type": "Point",
    "coordinates": [
      -46.588654,
      -23.709635
    ]
  },
  "coverageArea": {
    "type": "MultiPolygon",
    "coordinates": [[[[10, 10], [10, 10]]]]
  }
}
  • /partner/nearest POST

Returns the nearest partner who cover the given latitude and longitude.

Body:

{
  "lat": 10,
  "lon": 10
}

Develop

To run this project locally is necessary:

Rust (WebAssembly)

The Rust code is on the rs_lib directory, it contains the binding functions to interate with Javascript. The code uses the function of Geo crate to calculate if a point is inside a polygon.

To compile the Rust code to Wasm:

deno task wasmbuild

After this compilation, the lib directory is generated and the Wasm file and Javascript file with the functions who interates to wasm are in this folder.

To run the Rust tests of wasm-bindgen functions:

wasm-pack test --node rs_lib/

Deno

The application is built in on Deno, the code is structured to the outside libraries interact to user code through interfaces. This improve testability and facilitates to switching libraries if necessary.

To setup the project, is necessary to have a Postgres database running, the env.ts on root directory has default environment variables to connect to database that can be modified.

To create all the tables on the database, run the migrations by the command:

deno task migration:run

After this, the project is ready to run.

To run tests:

deno task test

To run the project:

deno task run

Points to improve

  • Create an script to setup an container Docker with Postgres to run integration tests on the database.

  • Integrate this setup and integration tests on Github Actions on push or pull on branch main.

  • Deploy on Deno Deploy and Supabase.

About

Zé delivery backend challenge, implementing a simple delivery application.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published