mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
Save active recipe to recipe book
This commit is contained in:
parent
e187c9f047
commit
40020ba64d
4 changed files with 29 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -270,6 +270,21 @@ 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)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue