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):
|
async def save(self, name, data):
|
||||||
path = os.path.join(".", 'config', "recipes", "{}.yaml".format(name))
|
path = os.path.join(".", 'config', "recipes", "{}.yaml".format(name))
|
||||||
|
logging.info(data)
|
||||||
with open(path, "w") as file:
|
with open(path, "w") as file:
|
||||||
yaml.dump(data, file, indent=4, sort_keys=True)
|
yaml.dump(data, file, indent=4, sort_keys=True)
|
||||||
|
|
||||||
|
@ -82,4 +83,4 @@ class RecipeController:
|
||||||
new_id = shortuuid.uuid()
|
new_id = shortuuid.uuid()
|
||||||
await self.save(new_id, data)
|
await self.save(new_id, data)
|
||||||
|
|
||||||
return new_id
|
return new_id
|
||||||
|
|
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
import cbpi
|
import cbpi
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
@ -307,3 +308,11 @@ class StepController:
|
||||||
self.load()
|
self.load()
|
||||||
self.push_udpate(complete=True)
|
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()
|
data = await request.json()
|
||||||
name = request.match_info['name']
|
name = request.match_info['name']
|
||||||
await self.controller.save(name, data)
|
await self.controller.save(name, data)
|
||||||
|
print(data)
|
||||||
return web.Response(status=204)
|
return web.Response(status=204)
|
||||||
|
|
||||||
@request_mapping(path="/{name}", method="DELETE", auth_required=False)
|
@request_mapping(path="/{name}", method="DELETE", auth_required=False)
|
||||||
|
@ -167,4 +168,4 @@ class RecipeHttpEndpoints():
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
|
|
||||||
return web.json_response(dict(id=await self.controller.clone(id, data.get("name"))))
|
return web.json_response(dict(id=await self.controller.clone(id, data.get("name"))))
|
||||||
|
|
||||||
|
|
|
@ -270,8 +270,23 @@ class StepHttpEndpoints():
|
||||||
await self.controller.clear()
|
await self.controller.clear()
|
||||||
return web.Response(status=204)
|
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