def get(self, id):
        """Gives the data of single transaction type  with selected transaction type id """

        try:
            transaction = TransactionType.query.filter(
                TransactionType.id == id).first()
            output = transaction_type_schema.dump(transaction)
            if transaction:
                logger.info('transaction type returned successfully')
                response = ResponseGenerator(
                    data=output,
                    message="transaction type returned successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
예제 #2
0
 def post(self):
     """create a user type"""
     try:
         userdata = request.get_json()
         result = user_type_schema.validate(userdata)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         user = UserType(user_type=userdata['user_type'])
         db.session.add(user)
         db.session.commit()
         output = user_type_schema.dump(user)
         logger.info("User type  successfully created")
         response = ResponseGenerator(data=output,
                                      message="User added  successfully",
                                      success=True,
                                      status=status.HTTP_201_CREATED)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def post(self):
     """Add branch_details in the BranchDetails table"""
     try:
         branch_data = request.get_json()
         result = branch_detail_schema.validate(branch_data)
         if result:
             logger.exception(result)
             response = ResponseGenerator(data={},
                                          message=result,
                                          success=False,
                                          status=status.HTTP_404_NOT_FOUND)
             return response.error_response()
         branch = BranchDetails(
             branch_name=branch_data['branch_name'],
             branch_address=branch_data['branch_address'])
         db.session.add(branch)
         db.session.commit()
         output = branch_detail_schema.dump(branch)
         logger.info("Branch data successfully created")
         response = ResponseGenerator(
             data=output,
             message="Branch data successfully created",
             success=True,
             status=status.HTTP_201_CREATED)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def delete(self, id):
     """Delete the user"""
     try:
         user = User.query.get(id)
         if user:
             if user.is_deleted == 1:
                 logger.info("User is already deleted")
                 return "User is already deleted"
             elif user.is_deleted == 0:
                 user.is_deleted = 1
                 db.session.commit()
                 logger.info("User data deleted successfully")
                 response = ResponseGenerator(
                     data=user,
                     message="User data deleted successfully",
                     success=True,
                     status=status.HTTP_200_OK)
                 return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self, id):
     """Gives the data of single user with selected user_id """
     try:
         user = User.query.filter(User.id == id,
                                  User.is_deleted == 0).first()
         output = user_schema.dump(user)
         logger.info('User data returned successfully')
         if user:
             response = ResponseGenerator(
                 data=output,
                 message="User data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self, id):
     """Gives the data of single branch detail with selected branch id """
     try:
         branch = BranchDetails.query.filter(BranchDetails.id == id).first()
         output = branch_detail_schema.dump(branch)
         logger.info('Branch data returned successfully')
         if branch:
             response = ResponseGenerator(
                 data=output,
                 message="Branch data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
    def get(self, id):
        """Gives the data of single fund transfer  with selected fund transfer id """

        try:
            fund = FundTransfer.query.filter(FundTransfer.id == id).first()
            output = fund_transfer_schema.dump(fund)
            if fund:
                logger.info('fund transfer returned successfully')
                response = ResponseGenerator(
                    data=output,
                    message="fund transfer returned successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
    def post(self):
        """Add transaction type in the TransactionType table"""

        try:
            transaction_data = request.get_json()
            result = transaction_type_schema.validate(transaction_data)
            if result:
                logger.exception(result)
                response = ResponseGenerator(
                    data={},
                    message=result,
                    success=False,
                    status=status.HTTP_400_BAD_REQUEST)
                return response.error_response()
            account = TransactionType(
                transaction_type=transaction_data['transaction_type'])
            db.session.add(account)
            db.session.commit()
            output = transaction_type_schema.dump(account)
            logger.info("transaction type details successfully created")
            response = ResponseGenerator(
                data=output,
                message="transaction type details successfully created",
                success=True,
                status=status.HTTP_201_CREATED)
            return response.success_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
예제 #9
0
 def get(self, id):
     """Gives the data of bank account of selected bank account id """
     try:
         account = BankAccount.query.filter(
             BankAccount.id == id, BankAccount.deleted == 0).first()
         output = bank_account_schema.dump(account)
         if account:
             logger.info('bank account data returned successfully')
             response = ResponseGenerator(
                 data=output,
                 message="bank account data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #10
0
 def get(self, id):
     """Gives the detail of first 10 transactions of selected bank account  id """
     try:
         account_transaction = BankAccount.query.filter(
             BankAccount.id == id).first()
         if account_transaction:
             mini_statement = AccountTransactionDetails.query.filter(
                 AccountTransactionDetails.bank_account_id == id).order_by(
                     desc(AccountTransactionDetails.id)).limit(10)
             if not mini_statement:
                 raise IdNotFound('id not found:{}'.format(id))
         output = account_transaction_details_schema.dump(mini_statement)
         logger.info('account transaction details returned successfully')
         response = ResponseGenerator(
             data=output,
             message="account transaction details returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self):
     """Provides the data of all the users in the user table"""
     try:
         all_users = User.query.filter(User.is_deleted == 0)
         output = []
         for user in all_users:
             currentuser = {}
             currentuser['id'] = user.id
             currentuser['first_name'] = user.first_name
             currentuser['last_name'] = user.last_name
             currentuser['address'] = user.address
             currentuser['mobile_number'] = user.mobile_number
             currentuser['email_id'] = user.email_id
             currentuser['user_type_id'] = user.user_type_id
             currentuser['created_on'] = user.created_on
             output.append(currentuser)
         logger.info("All Users data returned successfully")
         response = ResponseGenerator(
             data=output,
             message="All Users data returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self):
     """Provides the data of all the branch details"""
     try:
         all_branch_details = BranchDetails.query.all()
         output = []
         for branch in all_branch_details:
             currentbranch = {}
             currentbranch['id'] = branch.id
             currentbranch['branch_name'] = branch.branch_name
             currentbranch['branch_address'] = branch.branch_address
             output.append(currentbranch)
         logger.info("All branch data returned successfully")
         response = ResponseGenerator(
             data=output,
             message="All branch data returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def delete(self, id):
     """delete the branch detail of selected branch  id"""
     try:
         branch = BranchDetails.query.get(id)
         if branch:
             db.session.delete(branch)
             db.session.commit()
             logger.info("Branch details deleted successfully")
             return "Branch details deleted successfully"
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #14
0
    def get(self):
        """Provides the data of all the bank accounts"""

        try:
            all_accounts = BankAccount.query.filter(BankAccount.deleted == 0)
            output = []
            for account in all_accounts:
                currentaccount = {}
                currentaccount['id'] = account.id
                currentaccount['account_number'] = account.account_number
                currentaccount['is_active'] = account.is_active
                currentaccount['balance'] = account.balance
                currentaccount['user_id'] = account.user_id
                currentaccount['account_type_id'] = account.account_type_id
                currentaccount['branch_id'] = account.branch_id
                currentaccount['created_on'] = account.created_on
                output.append(currentaccount)
            logger.info("All account data returned successfully")
            response = ResponseGenerator(
                data=output,
                message="All account data returned successfully",
                success=True,
                status=status.HTTP_200_OK)
            return response.success_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
    def get(self):
        """Provides the details of all the transaction type"""

        try:
            all_transaction_type = TransactionType.query.all()
            output = []
            for transaction in all_transaction_type:
                currenttransaction = {}
                currenttransaction['id'] = transaction.id
                currenttransaction[
                    'transaction_type'] = transaction.transaction_type
                output.append(currenttransaction)
            logger.info("All transaction type details returned successfully")
            response = ResponseGenerator(
                data=output,
                message="All transaction type details returned successfully",
                success=True,
                status=status.HTTP_200_OK)
            return response.success_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
 def delete(self):
     try:
         jti = get_jwt()["jti"]
         now = datetime.now(timezone.utc)
         db.session.add(TokenBlocklist(jti=jti, created_at=now))
         db.session.commit()
         logger.info("You have been logged out!")
         response = ResponseGenerator(data={}, message="You have been logged out!",
                                      success=True, status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={}, message=error,
                                      success=False, status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #17
0
 def get(self):
     """get all the user types"""
     try:
         all_users = UserType.query.all()
         output = []
         for user in all_users:
             current_user = {}
             current_user['id'] = user.id
             current_user['user_type'] = user.user_type
             output.append(current_user)
         logger.info("All User types data returned successfully")
         response = ResponseGenerator(
             data=output,
             message="All Users data returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #18
0
 def get(self):
     """Provides the data of all the accountTypes"""
     try:
         all_account_types = AccountType.query.all()
         output = []
         for account in all_account_types:
             currentaccount = {}
             currentaccount['id'] = account.id
             currentaccount['account_type'] = account.account_type
             output.append(currentaccount)
         logger.info("All account_type data returned successfully")
         response = ResponseGenerator(
             data=output,
             message="All account_type data returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
 def get(self):
     """Provides the data of all the fund transfer"""
     try:
         all_fund_transfer = FundTransfer.query.all()
         fund_transfer_list = []
         for transfer in all_fund_transfer:
             currentfund = {}
             currentfund['from_account'] = transfer.from_account
             currentfund['to_account'] = transfer.to_account
             fund_transfer_list.append(currentfund)
         logger.info("All fund transfer data returned successfully")
         response = ResponseGenerator(
             data=fund_transfer_list,
             message="All fund transfer data returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def put(self, id):
     """Update the Branch Data """
     try:
         data = request.get_json()
         result = branch_detail_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         branch = BranchDetails.query.filter(BranchDetails.id == id).first()
         if branch:
             branch.branch_name = data.get('branch_name',
                                           branch.branch_name)
             branch.branch_address = data.get('branch_address',
                                              branch.branch_address)
             db.session.commit()
             output = branch_detail_schema.dump(branch)
             logger.info("Branch data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="Branch data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def put(self, id):
     """Update the user data """
     try:
         data = request.get_json()
         result = user_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         user = User.query.filter(User.id == id,
                                  User.is_deleted == 0).first()
         hashed = bcrypt.hashpw(
             data.get('password', user.password).encode('utf-8'),
             bcrypt.gensalt())
         if user:
             user.first_name = data.get('first_name', user.first_name)
             user.last_name = data.get('last_name', user.last_name)
             user.address = data.get('address', user.address)
             user.mobile_number = data.get('mobile_number',
                                           user.mobile_number)
             user.email_id = data.get('email_id', user.email_id)
             user.password = hashed
             user.user_type_id = data.get('user_type_id', user.user_type_id)
             db.session.commit()
             output = user_schema.dump(user)
             logger.info("User data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="User data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #22
0
 def put(self, id):
     """Update the bank account data """
     try:
         data = request.get_json()
         result = bank_account_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         account = BankAccount.query.filter(
             BankAccount.id == id, BankAccount.is_active == True,
             BankAccount.deleted == False).first()
         if account:
             account.user_id = data.get('user_id', account.user_id)
             account.account_type_id = data.get('account_type_id',
                                                account.account_type_id)
             account.branch_id = data.get('branch_id', account.branch_id)
             account.balance = data.get('balance', account.balance)
             db.session.commit()
             output = bank_account_schema.dump(account)
             logger.info("bank account data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="bank account data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
    def put(self, id):
        """Update the Transaction type """

        try:
            data = request.get_json()
            result = transaction_type_schema.validate(data, partial=True)
            if result:
                logger.exception(result)
                response = ResponseGenerator(
                    data={},
                    message=result,
                    success=False,
                    status=status.HTTP_400_BAD_REQUEST)
                return response.error_response()
            transaction = TransactionType.query.filter(
                TransactionType.id == id).first()
            if transaction:
                transaction.transaction_type = data.get(
                    'transaction_type', transaction.transaction_type)
                db.session.commit()
                output = transaction_type_schema.dump(transaction)
                logger.info("transaction_type updated successfully")
                response = ResponseGenerator(
                    data=output,
                    message="transaction_type updated successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
    def put(self, id):
        """Update the fund transfer """

        try:
            data = request.get_json()
            result = fund_transfer_schema.validate(data, partial=True)
            if result:
                logger.exception(result)
                response = ResponseGenerator(
                    data={},
                    message=result,
                    success=False,
                    status=status.HTTP_400_BAD_REQUEST)
                return response.error_response()
            fund = FundTransfer.query.filter(FundTransfer.id == id).first()
            if fund:
                fund.source = data.get('from_account', fund.from_account)
                fund.destination = data.get('to_account', fund.to_account)
                db.session.commit()
                output = fund_transfer_schema.dump(fund)
                logger.info("fund transfer updated successfully")
                response = ResponseGenerator(
                    data=output,
                    message="fund transfer updated successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
 def post(self):
     """Add fund transfer in the FundTransfer table"""
     try:
         fund_data = request.get_json()
         result = fund_transfer_schema.validate(fund_data)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         fund = FundTransfer(from_account=fund_data['from_account'],
                             to_account=fund_data['to_account'])
         db.session.add(fund)
         db.session.commit()
         output = fund_transfer_schema.dump(fund)
         from_account = BankAccount.query.filter(
             BankAccount.account_number ==
             fund_data['from_account']).first()
         if not from_account:
             response = ResponseGenerator(
                 data={},
                 message="Invalid Account number, from_account",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         to_account = BankAccount.query.filter(
             BankAccount.account_number == fund_data['to_account']).first()
         if not to_account:
             response = ResponseGenerator(
                 data={},
                 message="Invalid Account number, to_account",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         transaction_type = TransactionType.query.filter(
             TransactionType.transaction_type ==
             transaction_type_1).first()
         if from_account.balance - fund_data['transaction_amount'] > 1000:
             from_account.balance -= fund_data['transaction_amount']
             db.session.add(from_account)
             to_account.balance += fund_data['transaction_amount']
             db.session.add(to_account)
             transaction_status = "transaction successful"
         else:
             transaction_status = "transaction failed"
             response = ResponseGenerator(
                 data={},
                 message=transaction_status,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         account = AccountTransactionDetails(
             transaction_amount=fund_data['transaction_amount'],
             bank_account_id=from_account.id,
             transaction_type_id=transaction_type.id,
             fund_id=output.get('id'),
             transaction_status=transaction_status)
         db.session.add(account)
         db.session.commit()
         account_transaction_detail_schema.dump(account)
         logger.info("fund transfer data successfully created")
         response = ResponseGenerator(
             data=output,
             message="fund transfer data successfully created",
             success=True,
             status=status.HTTP_201_CREATED)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
예제 #26
0
 def post(self):
     """Create bank account in the BankAccount table"""
     try:
         account_data = request.get_json()
         result = bank_account_schema.validate(account_data)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         branch_id = account_data['branch_id']
         random_number = generate_random_number(7)
         account_number = str(branch_id).zfill(3) + str(random_number)
         logger.debug(account_number)
         user_id = User.query.filter(
             User.id == account_data['user_id']).first()
         if not user_id:
             response = ResponseGenerator(
                 data={},
                 message="Invalid user id given",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         account_type_id = AccountType.query.filter(
             AccountType.id == account_data['account_type_id']).first()
         if not account_type_id:
             response = ResponseGenerator(
                 data={},
                 message="Invalid account type id given",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         branch_id = BranchDetails.query.filter(
             BranchDetails.id == account_data['branch_id']).first()
         if not branch_id:
             response = ResponseGenerator(
                 data={},
                 message="Invalid branch id given",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         account = BankAccount(
             account_number=account_number,
             is_active=1,
             deleted=0,
             balance=account_data['balance'],
             user_id=account_data['user_id'],
             account_type_id=account_data['account_type_id'],
             branch_id=account_data['branch_id'])
         db.session.add(account)
         db.session.commit()
         fund = FundTransfer(from_account=account.account_number,
                             to_account=None)
         db.session.add(fund)
         db.session.commit()
         output = fund_transfer_schema.dump(fund)
         account = AccountTransactionDetails(
             transaction_amount=account.balance,
             bank_account_id=account.id,
             transaction_type_id=2,
             fund_id=output.get('id'),
             transaction_status="Success")
         db.session.add(account)
         db.session.commit()
         account_transaction_detail_schema.dump(account)
         output = bank_account_schema.dump(account)
         logger.info("Account data successfully created")
         response = ResponseGenerator(
             data=output,
             message="Account data successfully created",
             success=True,
             status=status.HTTP_201_CREATED)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def post(self):
     """Create user in the User table"""
     try:
         userdata = request.get_json()
         result = user_schema.validate(userdata)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         if if_email_id_exist(userdata['email_id']):
             logger.warning("Email_id is already taken")
             response = ResponseGenerator(
                 data={},
                 message="Email_id is already taken",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         if if_mobile_no_exist(userdata['mobile_number']):
             logger.warning("Mobile number is already taken")
             response = ResponseGenerator(
                 data={},
                 message="Mobile number is already taken",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         usertype = UserType.query.filter(
             UserType.id == userdata['user_type_id']).first()
         if not usertype:
             response = ResponseGenerator(
                 data={},
                 message="Invalid usertype",
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         hashed = bcrypt.hashpw(userdata['password'].encode('utf-8'),
                                bcrypt.gensalt())
         user = User(first_name=userdata['first_name'],
                     last_name=userdata['last_name'],
                     address=userdata['address'],
                     mobile_number=userdata['mobile_number'],
                     email_id=userdata['email_id'],
                     is_deleted=0,
                     password=hashed,
                     user_type_id=userdata['user_type_id'])
         db.session.add(user)
         db.session.commit()
         output = user_schema.dump(user)
         logger.info("User data successfully created")
         response = ResponseGenerator(
             data=output,
             message="User data successfully created",
             success=True,
             status=status.HTTP_201_CREATED)
         return response.success_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def post(self):
     try:
         user_email_id = request.json.get('email_id')
         password = request.json.get('password')
         if not user_email_id:
             logger.warning("Missing user email id")
             response = ResponseGenerator(data={}, message="Email Missing",
                                          success=False, status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         if not password:
             logger.warning("Missing Password")
             response = ResponseGenerator(data={}, message="Missing Password",
                                          success=False, status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         user = User.query.filter_by(email_id=user_email_id).first()
         if not user:
             logger.warning("Invalid user email entered")
             response = ResponseGenerator(data={}, message="Invalid user email entered",
                                          success=False, status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         if bcrypt.checkpw(password.encode('utf-8'), user.password.encode('utf-8')):
             access_token = create_access_token(identity={'email_id': user_email_id, 'password': password})
             logger.info("Successfully Logged in")
             response = ResponseGenerator(data={"access_token": access_token},
                                          message="You are successfully Logged in!", success=True,
                                          status=status.HTTP_201_CREATED)
             return response.success_response()
         else:
             logger.warning("Invalid password entered")
             response = ResponseGenerator(data={}, message="Invalid password entered",
                                          success=False, status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={}, message=error,
                                      success=False, status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def my_revoked_token_callback(jwt_header, jwt_payload):
     response = ResponseGenerator(data={}, message="Token has been Revoked, Logged Out!",
                                  success=False, status=status.HTTP_401_UNAUTHORIZED)
     return response.error_response()
 def my_invalid_token_callback(error_string):
     response = ResponseGenerator(data={}, message="Entered Token is Invalid, Enter Correct Token",
                                  success=False, status=status.HTTP_401_UNAUTHORIZED)
     return response.error_response()