[WIP] Library REST API
This commit is contained in:
27
app/routes/api/library/read.py
Normal file
27
app/routes/api/library/read.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from flask import request
|
||||
from sqlalchemy.exc import NoResultFound
|
||||
|
||||
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=["GET"])
|
||||
def read_libraries():
|
||||
library = LibraryController()
|
||||
library.read_all()
|
||||
return { "status": "ok", "results": [lib.to_dict() for lib in library.libraries] }, 200
|
||||
|
||||
@api_library.route("/<_id>", methods=["GET"])
|
||||
def read_library(_id):
|
||||
try:
|
||||
library = LibraryController(_id)
|
||||
except NoResultFound as e:
|
||||
logger.debug(f"No result found for Library wid id {_id}")
|
||||
logger.debug(f"Error {e}")
|
||||
logger.debug(f"Error {dir(e)}")
|
||||
return { "status": "error", "result": "Library not found"}, 404
|
||||
return { "status": "ok", "result": library.data.to_dict() }, 200
|
||||
Reference in New Issue
Block a user