[WIP] Library REST API
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.api.cruds.base import create, read, update, delete
|
||||
from app.api.cruds.base import create, read, update, delete, read_all
|
||||
from app.schema.library import Library
|
||||
from ..db.config.config import get_engine_configuration
|
||||
|
||||
@@ -22,6 +22,9 @@ class LibraryController:
|
||||
self._library = None
|
||||
if library_id is not None:
|
||||
self.read(library_id)
|
||||
|
||||
self._libraries = []
|
||||
|
||||
|
||||
def __del__(self):
|
||||
self.session.close()
|
||||
@@ -49,6 +52,19 @@ class LibraryController:
|
||||
def session(self):
|
||||
return self._session
|
||||
|
||||
@property
|
||||
def libraries(self):
|
||||
if self._library and len(self._libraries) == 0:
|
||||
self._libraries = [self._library]
|
||||
return self._libraries
|
||||
|
||||
def set_library(self, _id):
|
||||
libraries = filter(lambda x: x.get("id") == _id, self.libraries)
|
||||
if len(libraries) == 1:
|
||||
self._library = libraries[0]
|
||||
return True
|
||||
return False
|
||||
|
||||
def create(self, library:Library):
|
||||
self._library = create(self.session, library)
|
||||
return self
|
||||
@@ -56,6 +72,9 @@ class LibraryController:
|
||||
def read(self, _id):
|
||||
self._library = read(self.session, _id, Library)
|
||||
return self
|
||||
|
||||
def read_all(self):
|
||||
self._libraries = read_all(self.session, Library)
|
||||
|
||||
def update(self):
|
||||
self.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user