mirror of
https://github.com/Manuel83/craftbeerpi3
synced 2026-08-10 02:55:27 +02:00
First Refactoring
- Major API Changes in Core Module - Will be changed further. Still work in progress
This commit is contained in:
@@ -2,18 +2,28 @@ from flask import json, request
|
||||
from flask_classy import FlaskView, route
|
||||
from git import Repo, Git
|
||||
import sqlite3
|
||||
from modules.app_config import cbpi
|
||||
from modules.core.core import cbpi
|
||||
from werkzeug.utils import secure_filename
|
||||
import pprint
|
||||
import time
|
||||
import os
|
||||
from modules.steps import Step,StepView
|
||||
from modules.step import Step,StepView
|
||||
import xml.etree.ElementTree
|
||||
|
||||
class BeerXMLImport(FlaskView):
|
||||
BEER_XML_FILE = "./upload/beer.xml"
|
||||
@route('/', methods=['GET'])
|
||||
def get(self):
|
||||
|
||||
"""
|
||||
Get BeerXML
|
||||
---
|
||||
tags:
|
||||
- beerxml
|
||||
responses:
|
||||
200:
|
||||
description: BeerXML file stored in CraftBeerPI
|
||||
"""
|
||||
if not os.path.exists(self.BEER_XML_FILE):
|
||||
self.api.notify(headline="File Not Found", message="Please upload a Beer.xml File",
|
||||
type="danger")
|
||||
@@ -31,6 +41,16 @@ class BeerXMLImport(FlaskView):
|
||||
|
||||
@route('/upload', methods=['POST'])
|
||||
def upload_file(self):
|
||||
"""
|
||||
Upload BeerXML File
|
||||
---
|
||||
tags:
|
||||
- beerxml
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: BeerXML File Uploaded
|
||||
"""
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
file = request.files['file']
|
||||
@@ -46,6 +66,23 @@ class BeerXMLImport(FlaskView):
|
||||
@route('/<int:id>', methods=['POST'])
|
||||
def load(self, id):
|
||||
|
||||
"""
|
||||
Load Recipe from BeerXML
|
||||
---
|
||||
tags:
|
||||
- beerxml
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
required: true
|
||||
description: Recipe ID from BeerXML
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: Recipe loaed
|
||||
"""
|
||||
|
||||
steps = self.getSteps(id)
|
||||
name = self.getRecipeName(id)
|
||||
@@ -103,8 +140,8 @@ class BeerXMLImport(FlaskView):
|
||||
|
||||
return steps
|
||||
|
||||
@cbpi.initalizer()
|
||||
@cbpi.addon.core.initializer()
|
||||
def init(cbpi):
|
||||
|
||||
BeerXMLImport.api = cbpi
|
||||
BeerXMLImport.register(cbpi.app, route_base='/api/beerxml')
|
||||
BeerXMLImport.register(cbpi._app, route_base='/api/beerxml')
|
||||
|
||||
@@ -2,18 +2,28 @@ from flask import json, request
|
||||
from flask_classy import FlaskView, route
|
||||
from git import Repo, Git
|
||||
import sqlite3
|
||||
from modules.app_config import cbpi
|
||||
from modules.core.core import cbpi
|
||||
from werkzeug.utils import secure_filename
|
||||
import pprint
|
||||
import time
|
||||
import os
|
||||
from modules.steps import Step, StepView
|
||||
from modules.step import Step, StepView
|
||||
|
||||
|
||||
class KBH(FlaskView):
|
||||
|
||||
@route('/', methods=['GET'])
|
||||
def get(self):
|
||||
|
||||
"""
|
||||
Get all recipes from uploaded kleinerbrauhelfer database
|
||||
---
|
||||
tags:
|
||||
- kleinerbrauhelfer
|
||||
responses:
|
||||
200:
|
||||
description: Recipes from kleinerbrauhelfer database
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
if not os.path.exists(self.api.app.config['UPLOAD_FOLDER'] + '/kbh.db'):
|
||||
@@ -41,6 +51,16 @@ class KBH(FlaskView):
|
||||
|
||||
@route('/upload', methods=['POST'])
|
||||
def upload_file(self):
|
||||
"""
|
||||
Upload KleinerBrauhelfer Database File
|
||||
---
|
||||
tags:
|
||||
- kleinerbrauhelfer
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: File uploaed
|
||||
"""
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
file = request.files['file']
|
||||
@@ -57,6 +77,23 @@ class KBH(FlaskView):
|
||||
|
||||
@route('/<int:id>', methods=['POST'])
|
||||
def load(self, id):
|
||||
"""
|
||||
Load Recipe from Kleinerbrauhelfer Database
|
||||
---
|
||||
tags:
|
||||
- kleinerbrauhelfer
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
required: true
|
||||
description: Numeric ID of recipe
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: Recipe loaded
|
||||
"""
|
||||
mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
|
||||
mashinstep_type = cbpi.get_config_parameter("step_mashin", "MashInStep")
|
||||
chilstep_type = cbpi.get_config_parameter("step_chil", "ChilStep")
|
||||
@@ -102,8 +139,8 @@ class KBH(FlaskView):
|
||||
|
||||
|
||||
|
||||
@cbpi.initalizer()
|
||||
@cbpi.addon.core.initializer()
|
||||
def init(cbpi):
|
||||
|
||||
KBH.api = cbpi
|
||||
KBH.register(cbpi.app, route_base='/api/kbh')
|
||||
KBH.register(cbpi._app, route_base='/api/kbh')
|
||||
|
||||
@@ -2,12 +2,12 @@ from flask import json, request
|
||||
from flask_classy import FlaskView, route
|
||||
from git import Repo, Git
|
||||
import sqlite3
|
||||
from modules.app_config import cbpi
|
||||
from modules.core.core import cbpi
|
||||
from werkzeug.utils import secure_filename
|
||||
import pprint
|
||||
import time
|
||||
import os
|
||||
from modules.steps import Step,StepView
|
||||
from modules.step import Step,StepView
|
||||
import xml.etree.ElementTree
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class RESTImport(FlaskView):
|
||||
return ('', 204)
|
||||
|
||||
|
||||
@cbpi.initalizer()
|
||||
@cbpi.addon.core.initializer()
|
||||
def init(cbpi):
|
||||
RESTImport.api = cbpi
|
||||
RESTImport.register(cbpi.app, route_base='/api/recipe/import/v1')
|
||||
RESTImport.register(cbpi._app, route_base='/api/recipe/import/v1')
|
||||
|
||||
Reference in New Issue
Block a user