mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Added grocycode for recipes (closes #1562)
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace Grocy\Controllers;
|
||||
|
||||
use Grocy\Controllers\Users\User;
|
||||
use Grocy\Helpers\WebhookRunner;
|
||||
use Grocy\Helpers\Grocycode;
|
||||
|
||||
class RecipesApiController extends BaseApiController
|
||||
{
|
||||
@@ -76,4 +78,28 @@ class RecipesApiController extends BaseApiController
|
||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function RecipePrintLabel(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$recipe = $this->getDatabase()->recipes()->where('id', $args['recipeId'])->fetch();
|
||||
|
||||
$webhookData = array_merge([
|
||||
'recipe' => $recipe->name,
|
||||
'grocycode' => (string)(new Grocycode(Grocycode::RECIPE, $args['recipeId'])),
|
||||
], GROCY_LABEL_PRINTER_PARAMS);
|
||||
|
||||
if (GROCY_LABEL_PRINTER_RUN_SERVER)
|
||||
{
|
||||
(new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
|
||||
}
|
||||
|
||||
return $this->ApiResponse($response, $webhookData);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,12 @@
|
||||
namespace Grocy\Controllers;
|
||||
|
||||
use Grocy\Services\RecipesService;
|
||||
use Grocy\Helpers\Grocycode;
|
||||
|
||||
class RecipesController extends BaseController
|
||||
{
|
||||
use GrocycodeTrait;
|
||||
|
||||
public function MealPlan(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$start = date('Y-m-d');
|
||||
@@ -213,4 +216,10 @@ class RecipesController extends BaseController
|
||||
'mealplanSections' => $this->getDatabase()->meal_plan_sections()->where('id > 0')->orderBy('sort_number')
|
||||
]);
|
||||
}
|
||||
|
||||
public function RecipeGrocycodeImage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$gc = new Grocycode(Grocycode::RECIPE, $args['recipeId']);
|
||||
return $this->ServeGrocycodeImage($request, $response, $gc);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user