Browse Source

src: Add method to put new items into the inventory

master
Elis Hirwing 3 years ago
parent
commit
5b8ff2340d
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 4
      public/index.php
  2. 14
      src/Etu/Controller/Inventory.php

4
public/index.php

@ -20,6 +20,10 @@ $app->delete('/inventory/{item}/{amount}', function (Request $request, Response
return $this[InventoryController::class]->delete($request, $response, $args);
});
$app->put('/inventory/{item}/{amount}', function (Request $request, Response $response, array $args) {
return $this[InventoryController::class]->put($request, $response, $args);
});
/**
* Set up dependencies
*/

14
src/Etu/Controller/Inventory.php

@ -69,4 +69,18 @@ class Inventory
return $response->withJson(['status' => 'success']);
}
public function put(Request $request, Response $response, array $args)
{
$item = $this->inventoryHelper->get($args['item']);
// No such item
if (!$item) {
$this->inventoryHelper->addItem($args['item'], $args['amount']);
} else {
$this->inventoryHelper->setAmount($item->item_name, ($item->item_stock + $args['amount']));
}
return $response->withJson(['status' => 'success']);
}
}
Loading…
Cancel
Save