From 40020ba64d7d648bf56b93bd1352e9e4bc4accf8 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 27 May 2021 20:35:10 +0200 Subject: [PATCH] Save active recipe to recipe book --- cbpi/controller/recipe_controller.py | 3 ++- cbpi/controller/step_controller.py | 9 +++++++++ cbpi/http_endpoints/http_recipe.py | 3 ++- cbpi/http_endpoints/http_step.py | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cbpi/controller/recipe_controller.py b/cbpi/controller/recipe_controller.py index c8d6bc9..d668291 100644 --- a/cbpi/controller/recipe_controller.py +++ b/cbpi/controller/recipe_controller.py @@ -37,6 +37,7 @@ class RecipeController: async def save(self, name, data): path = os.path.join(".", 'config', "recipes", "{}.yaml".format(name)) + logging.info(data) with open(path, "w") as file: yaml.dump(data, file, indent=4, sort_keys=True) @@ -82,4 +83,4 @@ class RecipeController: new_id = shortuuid.uuid() await self.save(new_id, data) - return new_id \ No newline at end of file + return new_id diff --git a/cbpi/controller/step_controller.py b/cbpi/controller/step_controller.py index aefbf3b..c5caaf9 100644 --- a/cbpi/controller/step_controller.py +++ b/cbpi/controller/step_controller.py @@ -2,6 +2,7 @@ import asyncio import cbpi import copy import json +import yaml import logging import os.path from os import listdir @@ -307,3 +308,11 @@ class StepController: self.load() self.push_udpate(complete=True) + async def savetobook(self): + name = shortuuid.uuid() + path = os.path.join(".", 'config', "recipes", "{}.yaml".format(name)) + data = dict(basic=self.basic_data, steps=list(map(lambda item: item.to_dict(), self.profile))) + with open(path, "w") as file: + yaml.dump(data, file) + self.push_udpate() + diff --git a/cbpi/http_endpoints/http_recipe.py b/cbpi/http_endpoints/http_recipe.py index 39f5b50..734149b 100644 --- a/cbpi/http_endpoints/http_recipe.py +++ b/cbpi/http_endpoints/http_recipe.py @@ -89,6 +89,7 @@ class RecipeHttpEndpoints(): data = await request.json() name = request.match_info['name'] await self.controller.save(name, data) + print(data) return web.Response(status=204) @request_mapping(path="/{name}", method="DELETE", auth_required=False) @@ -167,4 +168,4 @@ class RecipeHttpEndpoints(): data = await request.json() return web.json_response(dict(id=await self.controller.clone(id, data.get("name")))) - \ No newline at end of file + diff --git a/cbpi/http_endpoints/http_step.py b/cbpi/http_endpoints/http_step.py index 9a3568f..c499d36 100644 --- a/cbpi/http_endpoints/http_step.py +++ b/cbpi/http_endpoints/http_step.py @@ -270,8 +270,23 @@ class StepHttpEndpoints(): await self.controller.clear() return web.Response(status=204) + @request_mapping(path="/savetobook", method="POST", auth_required=False) + async def http_savetobook(self, request): + + """ + + --- + description: Save Active Recipe to Recipe Book + tags: + - Step + responses: + "204": + description: successful operation + """ + await self.controller.savetobook() + return web.Response(status=204) - \ No newline at end of file +