[UPD] Exception handling
This commit is contained in:
@@ -6,7 +6,11 @@ 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
|
||||
|
||||
from sqlalchemy.exc import NoResultFound
|
||||
|
||||
from .exceptions import LibraryCreationException
|
||||
from .exceptions import LibraryReadException
|
||||
from .exceptions import LibraryUpdateException
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@@ -67,7 +71,8 @@ class LibraryController:
|
||||
self._library = libraries[0]
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
#CRUDS
|
||||
def create(self, library:Library):
|
||||
try:
|
||||
self._library = create(self.session, library)
|
||||
@@ -76,20 +81,35 @@ class LibraryController:
|
||||
"Cannot create library",
|
||||
f"{e.orig}",
|
||||
"library",
|
||||
str(library),
|
||||
400
|
||||
str(library)
|
||||
)
|
||||
return self
|
||||
|
||||
def read(self, _id):
|
||||
self._library = read(self.session, _id, Library)
|
||||
try:
|
||||
self._library = read(self.session, _id, Library)
|
||||
except NoResultFound as e:
|
||||
raise LibraryReadException(
|
||||
f"Cannot read Library with id {_id}",
|
||||
f"{e}",
|
||||
"library",
|
||||
_id
|
||||
)
|
||||
return self
|
||||
|
||||
def read_all(self):
|
||||
self._libraries = read_all(self.session, Library)
|
||||
|
||||
def update(self):
|
||||
self.session.commit()
|
||||
try:
|
||||
self.session.commit()
|
||||
except IntegrityError as e:
|
||||
raise LibraryUpdateException(
|
||||
f"Cannot update Library",
|
||||
f"{e}",
|
||||
"library",
|
||||
None
|
||||
)
|
||||
|
||||
def delete(self):
|
||||
delete(self.session, self.data)
|
||||
|
||||
Reference in New Issue
Block a user