Skip to content

WebDaMa/teamleader

Repository files navigation

#Problem 1: Discounts


General Info:

The App is written in Laravel 5.5. It has API methods to import data and calculate discounts on orders.

Setup

  1. Download and install Laravel here
  2. Download and install The v6.2.2 Homestead environment
  3. Follow the above instructions for Homestead and run Vagrant up
  4. Map this directory to Homestead like this
  5. Go to the folder via SSH
  6. Get needed files via composer:$ composer update

Testing

You can test the use Cases as well as the API calls.

Testing everything:

  1. Migrate the database: $ php artisan migrate:refresh
  2. Run tests: $ phpunit

Testing single test:

  1. Find your test method at: tests/Unit for Discounts and tests/Feature for API tests
  2. Run $ phpunit --filter <methodNameThatStartsWithTest>

API

Currently there are two methods accessible: Importing products:

POST: /products/mass

Example:

  {
    "id": "A101",
    "description": "Screwdriver",
    "category": "1",
    "price": "9.75"
  },
  {
    "id": "A102",
    "description": "Electric screwdriver",
    "category": "1",
    "price": "49.50"
  },
  {
    "id": "B101",
    "description": "Basic on-off switchs",
    "category": "2",
    "price": "4.99"
  },
  {
    "id": "B102",
    "description": "Press button",
    "category": "2",
    "price": "4.99"
  },
  {
    "id": "B103",
    "description": "Switch with motion detector",
    "category": "2",
    "price": "12.95"
  }
]

Importing an order:

POST: /orders

Example:

 {
  "id": "2",
  "customer-id": "1",
  "items": [
    {
      "product-id": "A102",
      "quantity": "10",
      "unit-price": "49.50",
      "total": "495.90"
    },
    {
      "product-id": "A101",
      "quantity": "1",
      "unit-price": "9.75",
      "total": "9.75"
    },
    {
      "product-id": "B102",
      "quantity": "10",
      "unit-price": "4.99",
      "total": "49.90"
    }
  ],
  "total": "495.90"
}

Note: The Product and Customer must first been inserted to insert an order. To seed the database with Products and Customers simply run:

$ php artisan db:seed

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages