def save(cls, obj): try: session.add(obj) session.commit() except Exception: session.rollback() raise
def remove(cls, obj): try: session.delete(obj) session.commit() except Exception: session.rollback() raise
def update(cls, obj, **kwargs): try: for key, value in kwargs.items(): setattr(obj, key, value) session.commit() except Exception: session.rollback() raise
def get_gifts(self, giver_id): try: dreams = self.model.query.filter_by(giver_id=giver_id, is_fulfilled=False).all() session.commit() except Exception: session.rollback() raise return dreams
def get_all(self, user_id): try: dreams = self.model.query.filter_by(owner_id=user_id).all() session.commit() except Exception: session.rollback() raise return dreams
def get_unfulfilled_dreams(self, user_id): try: dreams = self.model.query.filter_by(owner_id=user_id, is_fulfilled=False).all() session.commit() except Exception: session.rollback() raise return dreams
def get_gift(self, giver_id, dream_id): try: gift = self.model.query.filter_by(id=dream_id, giver_id=giver_id, is_fulfilled=False).first() session.commit() except Exception: session.rollback() raise return gift
def get_by_id_only(self, dream_id): try: dream = self.model.query.filter_by(id=dream_id).first() if not dream: raise Exception('Not found this dream') session.commit() except Exception: session.rollback() raise return dream