def create(auth_id): try: session = create_autocommit_session(db) with session.begin(): obj = User(auth_id=auth_id) session.add(obj) except Exception as e: raise
def update(id, new_visits): try: session = create_autocommit_session(db) with session.begin(): page_info = session.query(PageInfo).filter_by(id=id).first() page_info.visits = new_visits except Exception as e: raise
def get_auth_id(auth_id): try: session = create_autocommit_session(db) with session.begin(): user = session.query(User).filter_by(auth_id=auth_id).first() user_fields = ('id', 'auth_id') user_schema = UserSchema(many=False, only=user_fields) return user_schema.dump(user).data except Exception as e: raise
def get_id(id): try: session = create_autocommit_session(db) with session.begin(): page_info = session.query(PageInfo).filter_by(id=id).first() page_info_fields = ('id', 'visits') page_info_schema = PageInfoSchema(many=False, only=page_info_fields) return page_info_schema.dump(page_info).data except Exception as e: raise
def get_all(user_id): try: session = create_autocommit_session(db) with session.begin(): loans = session.query(Loans).all() loans_fields = ('id', 'count_id', 'value', 'interest', 'sold_percent', 'investor', 'product_type') loans_schema = LoanSchema(many=True, only=loans_fields) return loans_schema.dump(loans).data except Exception as e: raise
def create(loan_data, user_id): try: session = create_autocommit_session(db) with session.begin(): obj = Loans(count_id=LoanManager.__get_max_code(), value=loan_data['value'], interest=loan_data['interest'], sold_percent=loan_data['sold_percent'], investor=loan_data['investor'], product_type=loan_data['product_type'], user_id=user_id) session.add(obj) except Exception as e: raise