[UPD] Added api to create Library
This commit is contained in:
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