def delete(self, request): session = App.get_db().session try: self._service.delete( self._entity_adapter.to_dto_from_request(request)) session.commit() session.flush() return jsonify([]), 204 except Exception as exception: session.rollback() raise exception
def create(self, request): session = App.get_db().session try: entity = self._service.create( self._entity_adapter.to_dto_from_request(request)) session.commit() session.flush() response = self._entity_adapter.to_response_data_from_entity( entity) return jsonify(response), 201 except Exception as exception: session.rollback() raise exception
def delete(self, entity: BaseModel) -> None: App.get_db().session.delete(entity)
def save(self, entity: BaseModel): App.get_db().session.add(entity)
def find_all(self) -> List[BaseModel]: return App.get_db().session.query(self._class_of_model).all()
def find(self, id: Union[int, str, None]) -> BaseModel: return App.get_db().session.query(self._class_of_model).get(id)