Commit 183f4e63 authored by Guillaume Wauquier's avatar Guillaume Wauquier
Browse files

De quoi ajouter modifier les produits et catégories

parent 72728726
<?php
use Pasteque\Server\System\API\APICaller;
use Pasteque\Server\System\API\APIResult;
/**
* GET categoryGetAllGet
* GET categoryGetAll
* Summary:
* Notes: Get an array of all Categories
* Output-Formats: [application/json]
......@@ -10,8 +10,47 @@ use Pasteque\Server\System\API\APIResult;
$app->GET('/api/category/getAll', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','getAll'));
});
/**
* GET categoryGetChildrens
* Summary:
* Notes: Get an array of Categories from a parent Category Id
* Output-Formats: [application/json]
* * @SWG\Get(
* path="/api/category/getChildrens",
* @SWG\Response(response="200", description="Get an array of Categories from a parent Category Id")
* )
*/
$app->GET('/api/category/getChildrens', function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$parentId = $queryParams['parentId'];
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','getChildren',[$parentId]));
});
/**
* GET categoryId
* Summary:
* Notes: Get a Category
* Output-Formats: [application/json]
* @SWG\Get(
* path="/api/category/{id}",
* @SWG\Response(response="200", description="get a category")
* )
*/
$app->GET('/api/category/{id}', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','get',$args));
});
......@@ -46,6 +46,7 @@ $app->GET('/api/product/getByCode/{code}', function($request, $response, $args)
*/
$app->GET('/api/product/getByReference/{reference}', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'product', 'getByReference', $args['reference']));
});
......@@ -60,3 +61,53 @@ $app->GET('/api/product/{id}', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'product', 'get', $args['id']));
});
/**
* PUT productCreateupdate
* Summary:
* Notes: create or modify a product
* Output-Formats: [application/json]
* @SWG\Put(
* path="/api/product",
* tags={"product"},
* operationId="updateProduct",
* summary="Update an existing product",
* description="",
* consumes={"application/json", "application/xml"},
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* name="body",
* in="body",
* description="Product object that needs to be added",
* required=true,
* @SWG\Schema(ref="#/definitions/Product"),
* ),
* @SWG\Response(
* response=400,
* description="Invalid ID supplied",
* ),
* @SWG\Response(
* response=404,
* description="Product not found",
* ),
* @SWG\Response(
* response=405,
* description="Validation exception",
* ),
* security={{"pasteque_auth":{"write:products", "read:products"}}}
* )
*/
$app->PUT('/api/product', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
// $ptApp->getLogger()->info(json_encode($tab));
$product = \Pasteque\Server\Model\Product::fromStruct($tab,$ptApp->getDao());
// $ptApp->getLogger()->info($product->getId());
return $response->withApiResult(APICaller::run($ptApp, 'product', 'write', $product));
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment