28 lines
868 B
Python
28 lines
868 B
Python
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 |