Skip to content

tarique-iqbal/fruits-and-vegetables

Repository files navigation

🍎 Fruits and 🥕 Vegetables REST API using Symfony

🎯 Goal

We want to build a service which will take a request.json sample file location: data/request.json and:

  • Process the file and create two separate collections for Fruits and Vegetables
  • Each collection has methods like add(), remove(), list();
  • Units have to be stored as grams;
  • Store the collections in a storage engine of your choice. (e.g. Database)
  • Provide an API endpoint to query the collections. As a bonus, this endpoint can accept filters to be applied to the returning collection.
  • Provide another API endpoint to add new items to the collections (i.e., your storage engine).
  • As a bonus you might:
    • consider giving option to decide which units are returned (kilograms/grams);
    • how to implement search() method collections;
    • use latest version of Symfony's to embed your logic

Load json file

Json file loaded via Symfony Console Command

bin/console app:import-fruit-vegetable path/file.json

Routes

POST /api/fruits

{
  "name": "Apples",
  "quantity": 20,
  "unit": "kg"
}

GET /api/fruits | /api/fruits?page=2 | /api/fruits?page=2&unit=kilogram

DELETE /api/fruits/{id}

POST /api/vegetables

{
  "name": "Carrot",
  "quantity": 10922,
  "unit": "g"
}

GET /api/vegetables | /api/vegetables?page=2 | /api/vegetables?page=2&unit=kilogram

DELETE /api/vegetables/{id}

Running the tests

$ cd /path/to/base/directory
$ bin/phpunit tests

Releases

No releases published

Packages

No packages published

Languages