[UPD] Added api to create Library
This commit is contained in:
6
app/routes/api/__init__.py
Normal file
6
app/routes/api/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .blueprint import api
|
||||
from .install import post_install
|
||||
|
||||
from .library import api_library
|
||||
|
||||
api.register_blueprint(api_library)
|
||||
3
app/routes/api/blueprint.py
Normal file
3
app/routes/api/blueprint.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
api = Blueprint("api", __name__, url_prefix="/api")
|
||||
24
app/routes/api/install.py
Normal file
24
app/routes/api/install.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from flask import request
|
||||
|
||||
from ...config import config, save_config
|
||||
from ...api.actions.install import install
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from .blueprint import api
|
||||
|
||||
@api.route("/install", methods=["POST"])
|
||||
def post_install():
|
||||
try:
|
||||
body = request.json
|
||||
except:
|
||||
logger.debug("Installing with config.ini params")
|
||||
else:
|
||||
if body.get("query_string"):
|
||||
config["DataBase"]["query"] = body.get("query_string")
|
||||
save_config()
|
||||
finally:
|
||||
install()
|
||||
return { "status": "ok" }, 200
|
||||
|
||||
2
app/routes/api/library/__init__.py
Normal file
2
app/routes/api/library/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .blueprint import api_library
|
||||
from .create import create_library
|
||||
3
app/routes/api/library/blueprint.py
Normal file
3
app/routes/api/library/blueprint.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
api_library = Blueprint("api_library", __name__, url_prefix="/library")
|
||||
28
app/routes/api/library/create.py
Normal file
28
app/routes/api/library/create.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from flask import request
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from .blueprint import api_library
|
||||
|
||||
from ....controller import LibraryController
|
||||
from ....schema.library.library import Library
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@api_library.route("/", methods=["POST"])
|
||||
def create_library():
|
||||
try:
|
||||
data = request.json
|
||||
except Exception as e:
|
||||
logger.debug(f"{e}")
|
||||
return { "status": "error", "error": "JSON Required" }, 415
|
||||
|
||||
with LibraryController() as controller:
|
||||
try:
|
||||
lib = Library(**data)
|
||||
library = controller.create(lib)
|
||||
except IntegrityError as e:
|
||||
logger.debug(f"DB Error Creating {e}")
|
||||
return { "status": "error", "error": f"{e.orig}" }, 400
|
||||
else:
|
||||
return { "status": "ok", "result": library.data.to_dict() }, 200
|
||||
Reference in New Issue
Block a user