Browse Source

src: Add method to put new items into the inventory

master
Elis Hirwing 1 year ago
parent
commit
5b8ff2340d
Signed by: etu GPG Key ID: D57EFA625C9A925F
2 changed files with 18 additions and 0 deletions
  1. +4
    -0
      public/index.php
  2. +14
    -0
      src/Etu/Controller/Inventory.php

+ 4
- 0
public/index.php View File

@@ -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
- 0
src/Etu/Controller/Inventory.php View File

@@ -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