mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Slightly modified new recipe stock fulfillment API endpoints (references #289)
This commit is contained in:
parent
ddef58e2a9
commit
482a520062
@ -2,3 +2,4 @@
|
|||||||
- Fixed that "Track date only" chores were always tracked today, regardless of the given date
|
- Fixed that "Track date only" chores were always tracked today, regardless of the given date
|
||||||
- Fixed that the "week costs" were wrong after removing a meal plan entry
|
- Fixed that the "week costs" were wrong after removing a meal plan entry
|
||||||
- Fixed wrong recipes costs calculation with nested recipes when the base recipe servings are > 1 (also affected the meal plan when adding such a recipe there)
|
- Fixed wrong recipes costs calculation with nested recipes when the base recipe servings are > 1 (also affected the meal plan when adding such a recipe there)
|
||||||
|
- Improved recipes API - added new endpoints to get stock fulfillment information (thanks @Aerex)
|
||||||
|
@ -41,23 +41,28 @@ class RecipesApiController extends BaseApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRecipeRequirements(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
public function GetRecipeFulfillment(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
if(!$args['recipeId']){
|
{
|
||||||
return $this->ApiResponse($this->RecipesService->GetRecipesResolved());
|
if(!isset($args['recipeId']))
|
||||||
}
|
{
|
||||||
$recipeResolved = FindObjectInArrayByPropertyValue($this->RecipesService->GetRecipesResolved(), 'recipe_id', $args['recipeId']);
|
return $this->ApiResponse($this->RecipesService->GetRecipesResolved());
|
||||||
if(!$recipeResolved) {
|
}
|
||||||
$errorMsg ='Recipe requirments do not exist for recipe_id ' . $args['recipe_id'];
|
|
||||||
$GenericError = $this->GenericErrorResponse($response, $errorMsg);
|
$recipeResolved = FindObjectInArrayByPropertyValue($this->RecipesService->GetRecipesResolved(), 'recipe_id', $args['recipeId']);
|
||||||
return $GenericError;
|
if(!$recipeResolved)
|
||||||
}
|
{
|
||||||
return $this->ApiResponse($recipeResolved);
|
throw new \Exception('Recipe does not exist');
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
else
|
||||||
{
|
{
|
||||||
|
return $this->ApiResponse($recipeResolved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $ex)
|
||||||
|
{
|
||||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1663,6 +1663,47 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/recipes/{recipeId}/fulfillment": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Get stock fulfillment information for the given recipe",
|
||||||
|
"tags": [
|
||||||
|
"Recipes"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"in": "path",
|
||||||
|
"name": "recipeId",
|
||||||
|
"required": true,
|
||||||
|
"description": "A valid recipe id",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "A RecipeFulfillmentResponse object",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/RecipeFulfillmentResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "The operation was not successful",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/recipes/{recipeId}/consume": {
|
"/recipes/{recipeId}/consume": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Consumes all products of the given recipe",
|
"summary": "Consumes all products of the given recipe",
|
||||||
@ -1687,84 +1728,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/recipes/{recipeId}/requirements": {
|
"/recipes/fulfillment": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Get requirements for recipe",
|
"summary": "Get stock fulfillment information for all recipe",
|
||||||
"tags": [
|
"tags": [
|
||||||
"Recipes"
|
"Recipes"
|
||||||
],
|
],
|
||||||
"parameters": [
|
"responses": {
|
||||||
{
|
"200": {
|
||||||
"in": "path",
|
"description": "An array of RecipeFulfillmentResponse objects",
|
||||||
"name": "recipeId",
|
"content": {
|
||||||
"required": true,
|
"application/json": {
|
||||||
"description": "A valid recipe id",
|
"schema": {
|
||||||
"schema": {
|
"type": "array",
|
||||||
"type": "string"
|
"items": {
|
||||||
}
|
"$ref": "#/components/schemas/RecipeFulfillmentResponse"
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
"responses": {
|
}
|
||||||
"200": {
|
}
|
||||||
"description": "A requirements recipe object",
|
},
|
||||||
"content": {
|
"400": {
|
||||||
"application/json": {
|
"description": "The operation was not successful",
|
||||||
"schema": {
|
"content": {
|
||||||
"$ref": "#/components/schemas/RecipeRequirements"
|
"application/json": {
|
||||||
}
|
"schema": {
|
||||||
}
|
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"400": {
|
}
|
||||||
"description": "The operation was not successful",
|
}
|
||||||
"content": {
|
}
|
||||||
"application/json": {
|
}
|
||||||
"schema": {
|
},
|
||||||
"$ref": "#/components/schemas/GenericErrorResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/recipes/requirements": {
|
|
||||||
"get": {
|
|
||||||
"summary": "Get all requirements for recipes",
|
|
||||||
"tags": [
|
|
||||||
"Recipes"
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "An array of requirements recipe objects",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/RecipeRequirements"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "The operation was not successful",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/GenericErrorResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/chores": {
|
"/chores": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Returns all chores incl. the next estimated execution time per chore",
|
"summary": "Returns all chores incl. the next estimated execution time per chore",
|
||||||
@ -2453,34 +2449,34 @@
|
|||||||
"location_id": "4"
|
"location_id": "4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"RecipeRequirements": {
|
"RecipeFulfillmentResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"recipe_id": {
|
"recipe_id": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"need_fulfilled": {
|
"need_fulfilled": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"need_fulfilled_with_shopping_list": {
|
"need_fulfilled_with_shopping_list": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"missing_products_count": {
|
"missing_products_count": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"costs": {
|
"costs": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"format": "double"
|
"format": "double"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"example": {
|
"example": {
|
||||||
"recipe_id": "1",
|
"recipe_id": "1",
|
||||||
"need_fulfilled": "0",
|
"need_fulfilled": "0",
|
||||||
"need_fulfilled_with_shopping_list": "0",
|
"need_fulfilled_with_shopping_list": "0",
|
||||||
"missing_products_count": "2",
|
"missing_products_count": "2",
|
||||||
"costs": "17.74"
|
"costs": "17.74"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ProductDetailsResponse": {
|
"ProductDetailsResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -173,9 +173,9 @@ $app->group('/api', function()
|
|||||||
if (GROCY_FEATURE_FLAG_RECIPES)
|
if (GROCY_FEATURE_FLAG_RECIPES)
|
||||||
{
|
{
|
||||||
$this->post('/recipes/{recipeId}/add-not-fulfilled-products-to-shoppinglist', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList');
|
$this->post('/recipes/{recipeId}/add-not-fulfilled-products-to-shoppinglist', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList');
|
||||||
$this->get('/recipes/{recipeId}/requirements', '\Grocy\Controllers\RecipesApiController:GetRecipeRequirements');
|
$this->get('/recipes/{recipeId}/fulfillment', '\Grocy\Controllers\RecipesApiController:GetRecipeFulfillment');
|
||||||
$this->get('/recipes/requirements', '\Grocy\Controllers\RecipesApiController:GetRecipeRequirements');
|
|
||||||
$this->post('/recipes/{recipeId}/consume', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe');
|
$this->post('/recipes/{recipeId}/consume', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe');
|
||||||
|
$this->get('/recipes/fulfillment', '\Grocy\Controllers\RecipesApiController:GetRecipeFulfillment');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chores
|
// Chores
|
||||||
|
Loading…
x
Reference in New Issue
Block a user