Save active recipe to recipe book

This commit is contained in:
avollkopf 2021-05-27 20:35:10 +02:00
parent e187c9f047
commit 40020ba64d
4 changed files with 29 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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