Skip to content

nzauabraham/api-requirements

 
 

Repository files navigation

api-requirements

Description

We want you to implement a REST API endpoint that given a list of products, applies some discounts to them and can be filtered. You are free to choose whatever language and tools you are most comfortable with, but, we value you to use laravel since our main platform is also on laravel / php. We will value your ability to apply the following rules on the corresponding layers following Domain Driven Design. Please add instructions on how to run it and publish it on your fork.

Deliverable

Fork the project, work on the solution and send us back a link to your forked GitHub project to examine your answer to this test.

Conditions

The prices are integers for example, 100.00€ would be 10000.

  1. You can store the products as you see fit (json file, in memory, rdbms of choice)
  2. Products in the "insurance" category have a 30% discount.
  3. The product with sku = 000003 has a 15% discount.
  4. Provide a single endpoint. GET /products.
  5. Can be filtered by category as a query string parameter.
  6. (optional) Can be filtered by price as a query string parameter, this filter applies before discounts are applied.
  7. Returns a list of Products with the given discounts applied when necessary Product model.
  8. price.currency is always EUR.
  9. When a product does not have a discount, price.final and price.original should be the same number and discount_percentage should be null.
  10. When a product has a discount, price.original is the original price, price.final is the amount with the discount applied and discount_percentage represents the applied discount with the % sign.

Example product with a discount of 30% applied:
{ "sku": "000001", "name": "Full coverage insurance", "category": "insurance", "price": { "original": 89000, "final": 62300, "discount_percentage": "30%", "currency": "EUR" } }

Example product without a discount:

  `{
    "sku": "000002",
    "name": "Compact Car X3",
    "category": "vehicle",
    "price": {
        "original": 89000,
        "final": 89000,
        "discount_percentage": null,
        "currency": "EUR"
    }
  }`

Dataset.

The following dataset is the only dataset you need to be able to serve on the API:

{ "products": [ { "sku": "000001", "name": "Full coverage insurance", "category": "insurance", "price": 89000 }, { "sku": "000002", "name": "Compact Car X3", "category": "vehicle", "price": 99000 }, { "sku": "000003", "name": "SUV Vehicle, high end", "category": "vehicle", "price": 150000 }, { "sku": "000004", "name": "Basic coverage", "category": "insurance", "price": 20000 }, { "sku": "000005", "name": "Convertible X2, Electric", "category": "vehicle", "price": 250000 } ] }

Instructions

How to Run

  • After git pull, set up your .env file
  • Run composer install
  • Run php artisan migrate to create table
  • Run php artisan migrate --seed to create product entries

Usage

  • To get all Products: /products
  • To specify a category: /products?category=vehicle
  • To define a category and minimum price range /products?category=vehicle&minprice=70000
  • To define a category, minim price range a maximum price range: /products?category=vehicle&minprice=70000&maxprice=100000

About

Api Requirements.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 83.0%
  • Blade 15.9%
  • Other 1.1%